1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..0095943 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
33 @@ -70,6 +74,7 @@ Kerntypes
41 @@ -93,19 +98,24 @@ bounds.h
66 @@ -119,6 +129,7 @@ dslm
70 +exception_policy.conf
74 @@ -126,12 +137,15 @@ fore200e_pca_fw.c*
90 @@ -146,7 +160,7 @@ int32.c
99 @@ -154,7 +168,6 @@ kxgettext
107 @@ -166,14 +179,15 @@ machtypes.h
124 @@ -209,6 +223,7 @@ r300_reg_safe.h
132 @@ -219,6 +234,7 @@ setup
140 @@ -229,6 +245,7 @@ tftpboot.img
148 @@ -246,7 +263,9 @@ vmlinux
158 @@ -254,9 +273,11 @@ vsyscall_32.lds
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.
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.
183 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
188 diff --git a/Makefile b/Makefile
189 index 5f1739b..1831396 100644
192 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
196 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
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
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
207 # Basic helpers built in scripts/
208 -PHONY += 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
215 @@ -564,6 +565,48 @@ else
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_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
224 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
225 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
226 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
228 +ifdef CONFIG_KALLOCSTAT_PLUGIN
229 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
231 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
232 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
233 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
234 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
236 +ifdef CONFIG_CHECKER_PLUGIN
237 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
238 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
241 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS) $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS)
242 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
243 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
244 +ifeq ($(KBUILD_EXTMOD),)
246 + $(Q)$(MAKE) $(build)=tools/gcc
252 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
253 + $(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.))
255 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
257 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
261 include $(srctree)/arch/$(SRCARCH)/Makefile
263 ifneq ($(CONFIG_FRAME_WARN),0)
264 @@ -708,7 +751,7 @@ export mod_strip_cmd
267 ifeq ($(KBUILD_EXTMOD),)
268 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
269 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
271 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
272 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
273 @@ -932,6 +975,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
275 # The actual objects are generated when descending,
276 # make sure no implicit rule kicks in
277 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
278 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
279 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
281 # Handle descending into subdirectories listed in $(vmlinux-dirs)
282 @@ -941,7 +986,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
283 # Error messages still appears in the original language
285 PHONY += $(vmlinux-dirs)
286 -$(vmlinux-dirs): prepare scripts
287 +$(vmlinux-dirs): gcc-plugins prepare scripts
288 $(Q)$(MAKE) $(build)=$@
290 # Store (new) KERNELRELASE string in include/config/kernel.release
291 @@ -985,6 +1030,7 @@ prepare0: archprepare FORCE
292 $(Q)$(MAKE) $(build)=.
294 # All the preparing..
295 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
298 # Generate some files
299 @@ -1086,6 +1132,8 @@ all: modules
300 # using awk while concatenating to the final file.
303 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
304 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
305 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
306 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
307 @$(kecho) ' Building modules, stage 2.';
308 @@ -1101,7 +1149,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
310 # Target to prepare building external modules
311 PHONY += modules_prepare
312 -modules_prepare: prepare scripts
313 +modules_prepare: gcc-plugins prepare scripts
315 # Target to install modules
316 PHONY += modules_install
317 @@ -1198,6 +1246,7 @@ distclean: mrproper
318 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
319 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
321 + -o -name '.*.rej' -o -name '*.so' \
322 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
323 -type f -print | xargs rm -f
325 @@ -1358,6 +1407,8 @@ PHONY += $(module-dirs) modules
326 $(module-dirs): crmodverdir $(objtree)/Module.symvers
327 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
329 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
330 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
331 modules: $(module-dirs)
332 @$(kecho) ' Building modules, stage 2.';
333 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
334 @@ -1484,17 +1535,21 @@ else
335 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
338 -%.s: %.c prepare scripts FORCE
339 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
340 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
341 +%.s: %.c gcc-plugins prepare scripts FORCE
342 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
343 %.i: %.c prepare scripts FORCE
344 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
345 -%.o: %.c prepare scripts FORCE
346 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
347 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
348 +%.o: %.c gcc-plugins prepare scripts FORCE
349 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
350 %.lst: %.c prepare scripts FORCE
351 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
352 -%.s: %.S prepare scripts FORCE
353 +%.s: %.S gcc-plugins prepare scripts FORCE
354 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
355 -%.o: %.S prepare scripts FORCE
356 +%.o: %.S gcc-plugins prepare scripts FORCE
357 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
358 %.symtypes: %.c prepare scripts FORCE
359 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
360 @@ -1504,11 +1559,15 @@ endif
362 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
363 $(build)=$(build-dir)
364 -%/: prepare scripts FORCE
365 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
366 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
367 +%/: gcc-plugins prepare scripts FORCE
369 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
370 $(build)=$(build-dir)
371 -%.ko: prepare scripts FORCE
372 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
373 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
374 +%.ko: gcc-plugins prepare scripts FORCE
376 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
377 $(build)=$(build-dir) $(@:.ko=.o)
378 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
379 index 640f909..48b6597 100644
380 --- a/arch/alpha/include/asm/atomic.h
381 +++ b/arch/alpha/include/asm/atomic.h
382 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
383 #define atomic_dec(v) atomic_sub(1,(v))
384 #define atomic64_dec(v) atomic64_sub(1,(v))
386 +#define atomic64_read_unchecked(v) atomic64_read(v)
387 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
388 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
389 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
390 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
391 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
392 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
393 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
394 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
396 #define smp_mb__before_atomic_dec() smp_mb()
397 #define smp_mb__after_atomic_dec() smp_mb()
398 #define smp_mb__before_atomic_inc() smp_mb()
399 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
400 index da5449e..7418343 100644
401 --- a/arch/alpha/include/asm/elf.h
402 +++ b/arch/alpha/include/asm/elf.h
403 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
405 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
407 +#ifdef CONFIG_PAX_ASLR
408 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
410 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
411 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
414 /* $0 is set by ld.so to a pointer to a function which might be
415 registered using atexit. This provides a mean for the dynamic
416 linker to call DT_FINI functions for shared libraries that have
417 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
418 index de98a73..bd4f1f8 100644
419 --- a/arch/alpha/include/asm/pgtable.h
420 +++ b/arch/alpha/include/asm/pgtable.h
421 @@ -101,6 +101,17 @@ struct vm_area_struct;
422 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
423 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
424 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
426 +#ifdef CONFIG_PAX_PAGEEXEC
427 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
428 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
429 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
431 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
432 +# define PAGE_COPY_NOEXEC PAGE_COPY
433 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
436 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
438 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
439 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
440 index 2fd00b7..cfd5069 100644
441 --- a/arch/alpha/kernel/module.c
442 +++ b/arch/alpha/kernel/module.c
443 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
445 /* The small sections were sorted to the end of the segment.
446 The following should definitely cover them. */
447 - gp = (u64)me->module_core + me->core_size - 0x8000;
448 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
449 got = sechdrs[me->arch.gotsecindex].sh_addr;
451 for (i = 0; i < n; i++) {
452 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
453 index 01e8715..be0e80f 100644
454 --- a/arch/alpha/kernel/osf_sys.c
455 +++ b/arch/alpha/kernel/osf_sys.c
456 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
457 /* At this point: (!vma || addr < vma->vm_end). */
458 if (limit - len < addr)
460 - if (!vma || addr + len <= vma->vm_start)
461 + if (check_heap_stack_gap(vma, addr, len))
465 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
466 merely specific addresses, but regions of memory -- perhaps
467 this feature should be incorporated into all ports? */
469 +#ifdef CONFIG_PAX_RANDMMAP
470 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
474 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
475 if (addr != (unsigned long) -ENOMEM)
476 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
479 /* Next, try allocating at TASK_UNMAPPED_BASE. */
480 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
482 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
484 if (addr != (unsigned long) -ENOMEM)
487 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
488 index fadd5f8..904e73a 100644
489 --- a/arch/alpha/mm/fault.c
490 +++ b/arch/alpha/mm/fault.c
491 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
492 __reload_thread(pcb);
495 +#ifdef CONFIG_PAX_PAGEEXEC
497 + * PaX: decide what to do with offenders (regs->pc = fault address)
499 + * returns 1 when task should be killed
500 + * 2 when patched PLT trampoline was detected
501 + * 3 when unpatched PLT trampoline was detected
503 +static int pax_handle_fetch_fault(struct pt_regs *regs)
506 +#ifdef CONFIG_PAX_EMUPLT
509 + do { /* PaX: patched PLT emulation #1 */
510 + unsigned int ldah, ldq, jmp;
512 + err = get_user(ldah, (unsigned int *)regs->pc);
513 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
514 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
519 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
520 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
521 + jmp == 0x6BFB0000U)
523 + unsigned long r27, addr;
524 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
525 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
527 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
528 + err = get_user(r27, (unsigned long *)addr);
538 + do { /* PaX: patched PLT emulation #2 */
539 + unsigned int ldah, lda, br;
541 + err = get_user(ldah, (unsigned int *)regs->pc);
542 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
543 + err |= get_user(br, (unsigned int *)(regs->pc+8));
548 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
549 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
550 + (br & 0xFFE00000U) == 0xC3E00000U)
552 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
553 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
554 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
556 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
557 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
562 + do { /* PaX: unpatched PLT emulation */
565 + err = get_user(br, (unsigned int *)regs->pc);
567 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
568 + unsigned int br2, ldq, nop, jmp;
569 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
571 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
572 + err = get_user(br2, (unsigned int *)addr);
573 + err |= get_user(ldq, (unsigned int *)(addr+4));
574 + err |= get_user(nop, (unsigned int *)(addr+8));
575 + err |= get_user(jmp, (unsigned int *)(addr+12));
576 + err |= get_user(resolver, (unsigned long *)(addr+16));
581 + if (br2 == 0xC3600000U &&
582 + ldq == 0xA77B000CU &&
583 + nop == 0x47FF041FU &&
584 + jmp == 0x6B7B0000U)
586 + regs->r28 = regs->pc+4;
587 + regs->r27 = addr+16;
588 + regs->pc = resolver;
598 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
602 + printk(KERN_ERR "PAX: bytes at PC: ");
603 + for (i = 0; i < 5; i++) {
605 + if (get_user(c, (unsigned int *)pc+i))
606 + printk(KERN_CONT "???????? ");
608 + printk(KERN_CONT "%08x ", c);
615 * This routine handles page faults. It determines the address,
616 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
618 si_code = SEGV_ACCERR;
620 - if (!(vma->vm_flags & VM_EXEC))
621 + if (!(vma->vm_flags & VM_EXEC)) {
623 +#ifdef CONFIG_PAX_PAGEEXEC
624 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
627 + up_read(&mm->mmap_sem);
628 + switch (pax_handle_fetch_fault(regs)) {
630 +#ifdef CONFIG_PAX_EMUPLT
637 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
638 + do_group_exit(SIGKILL);
645 /* Allow reads even for write-only mappings */
646 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
647 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
648 index 86976d0..6610950 100644
649 --- a/arch/arm/include/asm/atomic.h
650 +++ b/arch/arm/include/asm/atomic.h
652 #include <linux/types.h>
653 #include <asm/system.h>
655 +#ifdef CONFIG_GENERIC_ATOMIC64
656 +#include <asm-generic/atomic64.h>
659 #define ATOMIC_INIT(i) { (i) }
662 @@ -239,6 +243,14 @@ typedef struct {
663 u64 __aligned(8) counter;
666 +#ifdef CONFIG_PAX_REFCOUNT
668 + u64 __aligned(8) counter;
669 +} atomic64_unchecked_t;
671 +typedef atomic64_t atomic64_unchecked_t;
674 #define ATOMIC64_INIT(i) { (i) }
676 static inline u64 atomic64_read(atomic64_t *v)
677 @@ -459,6 +471,16 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
678 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
679 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
681 +#define atomic64_read_unchecked(v) atomic64_read(v)
682 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
683 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
684 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
685 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
686 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
687 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
688 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
689 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
691 #endif /* !CONFIG_GENERIC_ATOMIC64 */
694 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
695 index 0e9ce8d..6ef1e03 100644
696 --- a/arch/arm/include/asm/elf.h
697 +++ b/arch/arm/include/asm/elf.h
698 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
699 the loader. We need to make sure that it is out of the way of the program
700 that it will "exec", and that there is sufficient room for the brk. */
702 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
703 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
705 +#ifdef CONFIG_PAX_ASLR
706 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
708 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
709 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
712 /* When the program starts, a1 contains a pointer to a function to be
713 registered with atexit, as per the SVR4 ABI. A value of 0 means we
714 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
715 extern void elf_set_personality(const struct elf32_hdr *);
716 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
719 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
720 -#define arch_randomize_brk arch_randomize_brk
722 extern int vectors_user_mapping(void);
723 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
724 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
725 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
726 index e51b1e8..32a3113 100644
727 --- a/arch/arm/include/asm/kmap_types.h
728 +++ b/arch/arm/include/asm/kmap_types.h
729 @@ -21,6 +21,7 @@ enum km_type {
737 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
738 index b293616..96310e5 100644
739 --- a/arch/arm/include/asm/uaccess.h
740 +++ b/arch/arm/include/asm/uaccess.h
742 #define VERIFY_READ 0
743 #define VERIFY_WRITE 1
745 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
748 * The exception table consists of pairs of addresses: the first is the
749 * address of an instruction that is allowed to fault, and the second is
750 @@ -387,8 +389,23 @@ do { \
754 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
755 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
756 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
757 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
759 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
761 + if (!__builtin_constant_p(n))
762 + check_object_size(to, n, false);
763 + return ___copy_from_user(to, from, n);
766 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
768 + if (!__builtin_constant_p(n))
769 + check_object_size(from, n, true);
770 + return ___copy_to_user(to, from, n);
773 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
774 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
775 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
776 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
778 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
783 if (access_ok(VERIFY_READ, from, n))
784 n = __copy_from_user(to, from, n);
785 else /* security hole - plug it */
786 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
788 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
793 if (access_ok(VERIFY_WRITE, to, n))
794 n = __copy_to_user(to, from, n);
796 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
797 index 5b0bce6..becd81c 100644
798 --- a/arch/arm/kernel/armksyms.c
799 +++ b/arch/arm/kernel/armksyms.c
800 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
802 EXPORT_SYMBOL(copy_page);
804 -EXPORT_SYMBOL(__copy_from_user);
805 -EXPORT_SYMBOL(__copy_to_user);
806 +EXPORT_SYMBOL(___copy_from_user);
807 +EXPORT_SYMBOL(___copy_to_user);
808 EXPORT_SYMBOL(__clear_user);
810 EXPORT_SYMBOL(__get_user_1);
811 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
812 index 3d0c6fb..3dcae52 100644
813 --- a/arch/arm/kernel/process.c
814 +++ b/arch/arm/kernel/process.c
816 #include <linux/tick.h>
817 #include <linux/utsname.h>
818 #include <linux/uaccess.h>
819 -#include <linux/random.h>
820 #include <linux/hw_breakpoint.h>
821 #include <linux/cpuidle.h>
823 @@ -484,12 +483,6 @@ unsigned long get_wchan(struct task_struct *p)
827 -unsigned long arch_randomize_brk(struct mm_struct *mm)
829 - unsigned long range_end = mm->brk + 0x02000000;
830 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
835 * The vectors page is always readable from user space for the
836 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
837 index 99a5727..a3d5bb1 100644
838 --- a/arch/arm/kernel/traps.c
839 +++ b/arch/arm/kernel/traps.c
840 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
842 static DEFINE_RAW_SPINLOCK(die_lock);
844 +extern void gr_handle_kernel_exploit(void);
847 * This function is protected against re-entrancy.
849 @@ -288,6 +290,9 @@ void die(const char *str, struct pt_regs *regs, int err)
850 panic("Fatal exception in interrupt");
852 panic("Fatal exception");
854 + gr_handle_kernel_exploit();
856 if (ret != NOTIFY_STOP)
859 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
860 index 66a477a..bee61d3 100644
861 --- a/arch/arm/lib/copy_from_user.S
862 +++ b/arch/arm/lib/copy_from_user.S
867 - * size_t __copy_from_user(void *to, const void *from, size_t n)
868 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
876 -ENTRY(__copy_from_user)
877 +ENTRY(___copy_from_user)
879 #include "copy_template.S"
881 -ENDPROC(__copy_from_user)
882 +ENDPROC(___copy_from_user)
884 .pushsection .fixup,"ax"
886 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
887 index d066df6..df28194 100644
888 --- a/arch/arm/lib/copy_to_user.S
889 +++ b/arch/arm/lib/copy_to_user.S
894 - * size_t __copy_to_user(void *to, const void *from, size_t n)
895 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
902 ENTRY(__copy_to_user_std)
903 -WEAK(__copy_to_user)
904 +WEAK(___copy_to_user)
906 #include "copy_template.S"
908 -ENDPROC(__copy_to_user)
909 +ENDPROC(___copy_to_user)
910 ENDPROC(__copy_to_user_std)
912 .pushsection .fixup,"ax"
913 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
914 index d0ece2a..5ae2f39 100644
915 --- a/arch/arm/lib/uaccess.S
916 +++ b/arch/arm/lib/uaccess.S
919 #define PAGE_SHIFT 12
921 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
922 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
923 * Purpose : copy a block to user memory from kernel memory
924 * Params : to - user memory
925 * : from - kernel memory
926 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
930 -ENTRY(__copy_to_user)
931 +ENTRY(___copy_to_user)
932 stmfd sp!, {r2, r4 - r7, lr}
935 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
937 USER( T(strgtb) r3, [r0], #1) @ May fault
939 -ENDPROC(__copy_to_user)
940 +ENDPROC(___copy_to_user)
942 .pushsection .fixup,"ax"
944 9001: ldmfd sp!, {r0, r4 - r7, pc}
947 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
948 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
949 * Purpose : copy a block from user memory to kernel memory
950 * Params : to - kernel memory
951 * : from - user memory
952 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
956 -ENTRY(__copy_from_user)
957 +ENTRY(___copy_from_user)
958 stmfd sp!, {r0, r2, r4 - r7, lr}
961 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
962 USER( T(ldrgtb) r3, [r1], #1) @ May fault
965 -ENDPROC(__copy_from_user)
966 +ENDPROC(___copy_from_user)
968 .pushsection .fixup,"ax"
970 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
971 index 025f742..8432b08 100644
972 --- a/arch/arm/lib/uaccess_with_memcpy.c
973 +++ b/arch/arm/lib/uaccess_with_memcpy.c
974 @@ -104,7 +104,7 @@ out:
978 -__copy_to_user(void __user *to, const void *from, unsigned long n)
979 +___copy_to_user(void __user *to, const void *from, unsigned long n)
982 * This test is stubbed out of the main function above to keep
983 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
984 index 2b2d51c..0127490 100644
985 --- a/arch/arm/mach-ux500/mbox-db5500.c
986 +++ b/arch/arm/mach-ux500/mbox-db5500.c
987 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
988 return sprintf(buf, "0x%X\n", mbox_value);
991 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
992 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
994 static int mbox_show(struct seq_file *s, void *data)
996 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
997 index aa33949..b242a2f 100644
998 --- a/arch/arm/mm/fault.c
999 +++ b/arch/arm/mm/fault.c
1000 @@ -183,6 +183,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1004 +#ifdef CONFIG_PAX_PAGEEXEC
1005 + if (fsr & FSR_LNX_PF) {
1006 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1007 + do_group_exit(SIGKILL);
1011 tsk->thread.address = addr;
1012 tsk->thread.error_code = fsr;
1013 tsk->thread.trap_no = 14;
1014 @@ -384,6 +391,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1016 #endif /* CONFIG_MMU */
1018 +#ifdef CONFIG_PAX_PAGEEXEC
1019 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1023 + printk(KERN_ERR "PAX: bytes at PC: ");
1024 + for (i = 0; i < 20; i++) {
1026 + if (get_user(c, (__force unsigned char __user *)pc+i))
1027 + printk(KERN_CONT "?? ");
1029 + printk(KERN_CONT "%02x ", c);
1033 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1034 + for (i = -1; i < 20; i++) {
1036 + if (get_user(c, (__force unsigned long __user *)sp+i))
1037 + printk(KERN_CONT "???????? ");
1039 + printk(KERN_CONT "%08lx ", c);
1046 * First Level Translation Fault Handler
1048 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1049 index 44b628e..623ee2a 100644
1050 --- a/arch/arm/mm/mmap.c
1051 +++ b/arch/arm/mm/mmap.c
1052 @@ -54,6 +54,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1053 if (len > TASK_SIZE)
1056 +#ifdef CONFIG_PAX_RANDMMAP
1057 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1062 addr = COLOUR_ALIGN(addr, pgoff);
1063 @@ -61,15 +65,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1064 addr = PAGE_ALIGN(addr);
1066 vma = find_vma(mm, addr);
1067 - if (TASK_SIZE - len >= addr &&
1068 - (!vma || addr + len <= vma->vm_start))
1069 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1072 if (len > mm->cached_hole_size) {
1073 - start_addr = addr = mm->free_area_cache;
1074 + start_addr = addr = mm->free_area_cache;
1076 - start_addr = addr = TASK_UNMAPPED_BASE;
1077 - mm->cached_hole_size = 0;
1078 + start_addr = addr = mm->mmap_base;
1079 + mm->cached_hole_size = 0;
1081 /* 8 bits of randomness in 20 address space bits */
1082 if ((current->flags & PF_RANDOMIZE) &&
1083 @@ -89,14 +92,14 @@ full_search:
1084 * Start a new search - just in case we missed
1087 - if (start_addr != TASK_UNMAPPED_BASE) {
1088 - start_addr = addr = TASK_UNMAPPED_BASE;
1089 + if (start_addr != mm->mmap_base) {
1090 + start_addr = addr = mm->mmap_base;
1091 mm->cached_hole_size = 0;
1096 - if (!vma || addr + len <= vma->vm_start) {
1097 + if (check_heap_stack_gap(vma, addr, len)) {
1099 * Remember the place where we stopped the search:
1101 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1102 index 3b3159b..425ea94 100644
1103 --- a/arch/avr32/include/asm/elf.h
1104 +++ b/arch/avr32/include/asm/elf.h
1105 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1106 the loader. We need to make sure that it is out of the way of the program
1107 that it will "exec", and that there is sufficient room for the brk. */
1109 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1110 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1112 +#ifdef CONFIG_PAX_ASLR
1113 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1115 +#define PAX_DELTA_MMAP_LEN 15
1116 +#define PAX_DELTA_STACK_LEN 15
1119 /* This yields a mask that user programs can use to figure out what
1120 instruction set this CPU supports. This could be done in user space,
1121 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1122 index b7f5c68..556135c 100644
1123 --- a/arch/avr32/include/asm/kmap_types.h
1124 +++ b/arch/avr32/include/asm/kmap_types.h
1125 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1130 +D(14) KM_CLEARPAGE,
1135 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1136 index f7040a1..db9f300 100644
1137 --- a/arch/avr32/mm/fault.c
1138 +++ b/arch/avr32/mm/fault.c
1139 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1141 int exception_trace = 1;
1143 +#ifdef CONFIG_PAX_PAGEEXEC
1144 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1148 + printk(KERN_ERR "PAX: bytes at PC: ");
1149 + for (i = 0; i < 20; i++) {
1151 + if (get_user(c, (unsigned char *)pc+i))
1152 + printk(KERN_CONT "???????? ");
1154 + printk(KERN_CONT "%02x ", c);
1161 * This routine handles page faults. It determines the address and the
1162 * problem, and then passes it off to one of the appropriate routines.
1163 @@ -156,6 +173,16 @@ bad_area:
1164 up_read(&mm->mmap_sem);
1166 if (user_mode(regs)) {
1168 +#ifdef CONFIG_PAX_PAGEEXEC
1169 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1170 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1171 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1172 + do_group_exit(SIGKILL);
1177 if (exception_trace && printk_ratelimit())
1178 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1179 "sp %08lx ecr %lu\n",
1180 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
1181 index 0d8a7d6..d0c9ff5 100644
1182 --- a/arch/frv/include/asm/atomic.h
1183 +++ b/arch/frv/include/asm/atomic.h
1184 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
1185 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
1186 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
1188 +#define atomic64_read_unchecked(v) atomic64_read(v)
1189 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1190 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1191 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1192 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1193 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1194 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1195 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1196 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1198 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
1201 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1202 index f8e16b2..c73ff79 100644
1203 --- a/arch/frv/include/asm/kmap_types.h
1204 +++ b/arch/frv/include/asm/kmap_types.h
1205 @@ -23,6 +23,7 @@ enum km_type {
1213 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1214 index 385fd30..6c3d97e 100644
1215 --- a/arch/frv/mm/elf-fdpic.c
1216 +++ b/arch/frv/mm/elf-fdpic.c
1217 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1219 addr = PAGE_ALIGN(addr);
1220 vma = find_vma(current->mm, addr);
1221 - if (TASK_SIZE - len >= addr &&
1222 - (!vma || addr + len <= vma->vm_start))
1223 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1227 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1228 for (; vma; vma = vma->vm_next) {
1231 - if (addr + len <= vma->vm_start)
1232 + if (check_heap_stack_gap(vma, addr, len))
1236 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1237 for (; vma; vma = vma->vm_next) {
1240 - if (addr + len <= vma->vm_start)
1241 + if (check_heap_stack_gap(vma, addr, len))
1245 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
1246 index 3fad89e..3047da5 100644
1247 --- a/arch/ia64/include/asm/atomic.h
1248 +++ b/arch/ia64/include/asm/atomic.h
1249 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
1250 #define atomic64_inc(v) atomic64_add(1, (v))
1251 #define atomic64_dec(v) atomic64_sub(1, (v))
1253 +#define atomic64_read_unchecked(v) atomic64_read(v)
1254 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1255 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1256 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1257 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1258 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1259 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1260 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1261 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1263 /* Atomic operations are already serializing */
1264 #define smp_mb__before_atomic_dec() barrier()
1265 #define smp_mb__after_atomic_dec() barrier()
1266 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1267 index b5298eb..67c6e62 100644
1268 --- a/arch/ia64/include/asm/elf.h
1269 +++ b/arch/ia64/include/asm/elf.h
1272 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1274 +#ifdef CONFIG_PAX_ASLR
1275 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1277 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1278 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1281 #define PT_IA_64_UNWIND 0x70000001
1283 /* IA-64 relocations: */
1284 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1285 index 1a97af3..7529d31 100644
1286 --- a/arch/ia64/include/asm/pgtable.h
1287 +++ b/arch/ia64/include/asm/pgtable.h
1289 * David Mosberger-Tang <davidm@hpl.hp.com>
1293 +#include <linux/const.h>
1294 #include <asm/mman.h>
1295 #include <asm/page.h>
1296 #include <asm/processor.h>
1297 @@ -143,6 +143,17 @@
1298 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1299 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1300 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1302 +#ifdef CONFIG_PAX_PAGEEXEC
1303 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1304 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1305 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1307 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1308 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1309 +# define PAGE_COPY_NOEXEC PAGE_COPY
1312 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1313 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1314 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1315 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1316 index b77768d..e0795eb 100644
1317 --- a/arch/ia64/include/asm/spinlock.h
1318 +++ b/arch/ia64/include/asm/spinlock.h
1319 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
1320 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1322 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1323 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1324 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1327 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1328 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1329 index 449c8c0..432a3d2 100644
1330 --- a/arch/ia64/include/asm/uaccess.h
1331 +++ b/arch/ia64/include/asm/uaccess.h
1332 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1333 const void *__cu_from = (from); \
1334 long __cu_len = (n); \
1336 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1337 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1338 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1341 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1342 long __cu_len = (n); \
1344 __chk_user_ptr(__cu_from); \
1345 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1346 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1347 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1350 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1351 index 24603be..948052d 100644
1352 --- a/arch/ia64/kernel/module.c
1353 +++ b/arch/ia64/kernel/module.c
1354 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
1356 module_free (struct module *mod, void *module_region)
1358 - if (mod && mod->arch.init_unw_table &&
1359 - module_region == mod->module_init) {
1360 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1361 unw_remove_unwind_table(mod->arch.init_unw_table);
1362 mod->arch.init_unw_table = NULL;
1364 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
1368 +in_init_rx (const struct module *mod, uint64_t addr)
1370 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1374 +in_init_rw (const struct module *mod, uint64_t addr)
1376 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1380 in_init (const struct module *mod, uint64_t addr)
1382 - return addr - (uint64_t) mod->module_init < mod->init_size;
1383 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1387 +in_core_rx (const struct module *mod, uint64_t addr)
1389 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1393 +in_core_rw (const struct module *mod, uint64_t addr)
1395 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1399 in_core (const struct module *mod, uint64_t addr)
1401 - return addr - (uint64_t) mod->module_core < mod->core_size;
1402 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1406 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
1410 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1411 + if (in_init_rx(mod, val))
1412 + val -= (uint64_t) mod->module_init_rx;
1413 + else if (in_init_rw(mod, val))
1414 + val -= (uint64_t) mod->module_init_rw;
1415 + else if (in_core_rx(mod, val))
1416 + val -= (uint64_t) mod->module_core_rx;
1417 + else if (in_core_rw(mod, val))
1418 + val -= (uint64_t) mod->module_core_rw;
1422 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
1423 * addresses have been selected...
1426 - if (mod->core_size > MAX_LTOFF)
1427 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1429 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1430 * at the end of the module.
1432 - gp = mod->core_size - MAX_LTOFF / 2;
1433 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1435 - gp = mod->core_size / 2;
1436 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1437 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1438 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1440 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1442 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1443 index 609d500..7dde2a8 100644
1444 --- a/arch/ia64/kernel/sys_ia64.c
1445 +++ b/arch/ia64/kernel/sys_ia64.c
1446 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1447 if (REGION_NUMBER(addr) == RGN_HPAGE)
1451 +#ifdef CONFIG_PAX_RANDMMAP
1452 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1453 + addr = mm->free_area_cache;
1458 addr = mm->free_area_cache;
1460 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1461 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1462 /* At this point: (!vma || addr < vma->vm_end). */
1463 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1464 - if (start_addr != TASK_UNMAPPED_BASE) {
1465 + if (start_addr != mm->mmap_base) {
1466 /* Start a new search --- just in case we missed some holes. */
1467 - addr = TASK_UNMAPPED_BASE;
1468 + addr = mm->mmap_base;
1473 - if (!vma || addr + len <= vma->vm_start) {
1474 + if (check_heap_stack_gap(vma, addr, len)) {
1475 /* Remember the address where we stopped this search: */
1476 mm->free_area_cache = addr + len;
1478 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1479 index 53c0ba0..2accdde 100644
1480 --- a/arch/ia64/kernel/vmlinux.lds.S
1481 +++ b/arch/ia64/kernel/vmlinux.lds.S
1482 @@ -199,7 +199,7 @@ SECTIONS {
1484 . = ALIGN(PERCPU_PAGE_SIZE);
1485 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1486 - __phys_per_cpu_start = __per_cpu_load;
1487 + __phys_per_cpu_start = per_cpu_load;
1489 * ensure percpu data fits
1490 * into percpu page size
1491 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1492 index 20b3593..1ce77f0 100644
1493 --- a/arch/ia64/mm/fault.c
1494 +++ b/arch/ia64/mm/fault.c
1495 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
1496 return pte_present(pte);
1499 +#ifdef CONFIG_PAX_PAGEEXEC
1500 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1504 + printk(KERN_ERR "PAX: bytes at PC: ");
1505 + for (i = 0; i < 8; i++) {
1507 + if (get_user(c, (unsigned int *)pc+i))
1508 + printk(KERN_CONT "???????? ");
1510 + printk(KERN_CONT "%08x ", c);
1517 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1519 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
1520 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1521 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1523 - if ((vma->vm_flags & mask) != mask)
1524 + if ((vma->vm_flags & mask) != mask) {
1526 +#ifdef CONFIG_PAX_PAGEEXEC
1527 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1528 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1531 + up_read(&mm->mmap_sem);
1532 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1533 + do_group_exit(SIGKILL);
1542 * If for any reason at all we couldn't handle the fault, make
1543 * sure we exit gracefully rather than endlessly redo the
1544 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1545 index 5ca674b..e0e1b70 100644
1546 --- a/arch/ia64/mm/hugetlbpage.c
1547 +++ b/arch/ia64/mm/hugetlbpage.c
1548 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
1549 /* At this point: (!vmm || addr < vmm->vm_end). */
1550 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1552 - if (!vmm || (addr + len) <= vmm->vm_start)
1553 + if (check_heap_stack_gap(vmm, addr, len))
1555 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1557 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1558 index 00cb0e2..2ad8024 100644
1559 --- a/arch/ia64/mm/init.c
1560 +++ b/arch/ia64/mm/init.c
1561 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
1562 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1563 vma->vm_end = vma->vm_start + PAGE_SIZE;
1564 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1566 +#ifdef CONFIG_PAX_PAGEEXEC
1567 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1568 + vma->vm_flags &= ~VM_EXEC;
1570 +#ifdef CONFIG_PAX_MPROTECT
1571 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1572 + vma->vm_flags &= ~VM_MAYEXEC;
1578 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1579 down_write(¤t->mm->mmap_sem);
1580 if (insert_vm_struct(current->mm, vma)) {
1581 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1582 index 82abd15..d95ae5d 100644
1583 --- a/arch/m32r/lib/usercopy.c
1584 +++ b/arch/m32r/lib/usercopy.c
1587 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1593 if (access_ok(VERIFY_WRITE, to, n))
1594 __copy_user(to,from,n);
1595 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1597 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1603 if (access_ok(VERIFY_READ, from, n))
1604 __copy_user_zeroing(to,from,n);
1605 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
1606 index 1d93f81..67794d0 100644
1607 --- a/arch/mips/include/asm/atomic.h
1608 +++ b/arch/mips/include/asm/atomic.h
1610 #include <asm/war.h>
1611 #include <asm/system.h>
1613 +#ifdef CONFIG_GENERIC_ATOMIC64
1614 +#include <asm-generic/atomic64.h>
1617 #define ATOMIC_INIT(i) { (i) }
1620 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
1622 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
1624 +#define atomic64_read_unchecked(v) atomic64_read(v)
1625 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1626 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1627 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1628 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1629 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1630 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1631 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1632 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1634 #endif /* CONFIG_64BIT */
1637 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1638 index 455c0ac..ad65fbe 100644
1639 --- a/arch/mips/include/asm/elf.h
1640 +++ b/arch/mips/include/asm/elf.h
1641 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
1642 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1645 +#ifdef CONFIG_PAX_ASLR
1646 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1648 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1649 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1652 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1653 struct linux_binprm;
1654 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1658 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1659 -#define arch_randomize_brk arch_randomize_brk
1661 #endif /* _ASM_ELF_H */
1662 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1663 index e59cd1a..8e329d6 100644
1664 --- a/arch/mips/include/asm/page.h
1665 +++ b/arch/mips/include/asm/page.h
1666 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
1667 #ifdef CONFIG_CPU_MIPS32
1668 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1669 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1670 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1671 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1673 typedef struct { unsigned long long pte; } pte_t;
1674 #define pte_val(x) ((x).pte)
1675 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1676 index 6018c80..7c37203 100644
1677 --- a/arch/mips/include/asm/system.h
1678 +++ b/arch/mips/include/asm/system.h
1679 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1681 #define __ARCH_WANT_UNLOCKED_CTXSW
1683 -extern unsigned long arch_align_stack(unsigned long sp);
1684 +#define arch_align_stack(x) ((x) & ~0xfUL)
1686 #endif /* _ASM_SYSTEM_H */
1687 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1688 index 9fdd8bc..4bd7f1a 100644
1689 --- a/arch/mips/kernel/binfmt_elfn32.c
1690 +++ b/arch/mips/kernel/binfmt_elfn32.c
1691 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1692 #undef ELF_ET_DYN_BASE
1693 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1695 +#ifdef CONFIG_PAX_ASLR
1696 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1698 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1699 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1702 #include <asm/processor.h>
1703 #include <linux/module.h>
1704 #include <linux/elfcore.h>
1705 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
1706 index ff44823..97f8906 100644
1707 --- a/arch/mips/kernel/binfmt_elfo32.c
1708 +++ b/arch/mips/kernel/binfmt_elfo32.c
1709 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1710 #undef ELF_ET_DYN_BASE
1711 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1713 +#ifdef CONFIG_PAX_ASLR
1714 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1716 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1717 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1720 #include <asm/processor.h>
1723 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
1724 index c47f96e..661d418 100644
1725 --- a/arch/mips/kernel/process.c
1726 +++ b/arch/mips/kernel/process.c
1727 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
1733 - * Don't forget that the stack pointer must be aligned on a 8 bytes
1734 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1736 -unsigned long arch_align_stack(unsigned long sp)
1738 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1739 - sp -= get_random_int() & ~PAGE_MASK;
1741 - return sp & ALMASK;
1743 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
1744 index 937cf33..adb39bb 100644
1745 --- a/arch/mips/mm/fault.c
1746 +++ b/arch/mips/mm/fault.c
1748 #include <asm/highmem.h> /* For VMALLOC_END */
1749 #include <linux/kdebug.h>
1751 +#ifdef CONFIG_PAX_PAGEEXEC
1752 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1756 + printk(KERN_ERR "PAX: bytes at PC: ");
1757 + for (i = 0; i < 5; i++) {
1759 + if (get_user(c, (unsigned int *)pc+i))
1760 + printk(KERN_CONT "???????? ");
1762 + printk(KERN_CONT "%08x ", c);
1769 * This routine handles page faults. It determines the address,
1770 * and the problem, and then passes it off to one of the appropriate
1771 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
1772 index 302d779..7d35bf8 100644
1773 --- a/arch/mips/mm/mmap.c
1774 +++ b/arch/mips/mm/mmap.c
1775 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1778 /* requesting a specific address */
1780 +#ifdef CONFIG_PAX_RANDMMAP
1781 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1786 addr = COLOUR_ALIGN(addr, pgoff);
1787 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1788 addr = PAGE_ALIGN(addr);
1790 vma = find_vma(mm, addr);
1791 - if (TASK_SIZE - len >= addr &&
1792 - (!vma || addr + len <= vma->vm_start))
1793 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
1797 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1798 /* At this point: (!vma || addr < vma->vm_end). */
1799 if (TASK_SIZE - len < addr)
1801 - if (!vma || addr + len <= vma->vm_start)
1802 + if (check_heap_stack_gap(vmm, addr, len))
1806 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1807 /* make sure it can fit in the remaining address space */
1808 if (likely(addr > len)) {
1809 vma = find_vma(mm, addr - len);
1810 - if (!vma || addr <= vma->vm_start) {
1811 + if (check_heap_stack_gap(vmm, addr - len, len))
1812 /* cache the address as a hint for next time */
1813 return mm->free_area_cache = addr - len;
1815 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1816 * return with success:
1818 vma = find_vma(mm, addr);
1819 - if (likely(!vma || addr + len <= vma->vm_start)) {
1820 + if (check_heap_stack_gap(vmm, addr, len)) {
1821 /* cache the address as a hint for next time */
1822 return mm->free_area_cache = addr;
1824 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1825 mm->unmap_area = arch_unmap_area_topdown;
1829 -static inline unsigned long brk_rnd(void)
1831 - unsigned long rnd = get_random_int();
1833 - rnd = rnd << PAGE_SHIFT;
1834 - /* 8MB for 32bit, 256MB for 64bit */
1835 - if (TASK_IS_32BIT_ADDR)
1836 - rnd = rnd & 0x7ffffful;
1838 - rnd = rnd & 0xffffffful;
1843 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1845 - unsigned long base = mm->brk;
1846 - unsigned long ret;
1848 - ret = PAGE_ALIGN(base + brk_rnd());
1850 - if (ret < mm->brk)
1855 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
1856 index 4054b31..a10c105 100644
1857 --- a/arch/parisc/include/asm/atomic.h
1858 +++ b/arch/parisc/include/asm/atomic.h
1859 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
1861 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
1863 +#define atomic64_read_unchecked(v) atomic64_read(v)
1864 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1865 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1866 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1867 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1868 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1869 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1870 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1871 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1873 #endif /* !CONFIG_64BIT */
1876 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
1877 index 19f6cb1..6c78cf2 100644
1878 --- a/arch/parisc/include/asm/elf.h
1879 +++ b/arch/parisc/include/asm/elf.h
1880 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
1882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1884 +#ifdef CONFIG_PAX_ASLR
1885 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
1887 +#define PAX_DELTA_MMAP_LEN 16
1888 +#define PAX_DELTA_STACK_LEN 16
1891 /* This yields a mask that user programs can use to figure out what
1892 instruction set this CPU supports. This could be done in user space,
1893 but it's not easy, and we've already done it here. */
1894 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
1895 index 22dadeb..f6c2be4 100644
1896 --- a/arch/parisc/include/asm/pgtable.h
1897 +++ b/arch/parisc/include/asm/pgtable.h
1898 @@ -210,6 +210,17 @@ struct vm_area_struct;
1899 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1900 #define PAGE_COPY PAGE_EXECREAD
1901 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1903 +#ifdef CONFIG_PAX_PAGEEXEC
1904 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1905 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1906 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1908 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1909 +# define PAGE_COPY_NOEXEC PAGE_COPY
1910 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1913 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1914 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
1915 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
1916 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
1917 index 5e34ccf..672bc9c 100644
1918 --- a/arch/parisc/kernel/module.c
1919 +++ b/arch/parisc/kernel/module.c
1922 /* three functions to determine where in the module core
1923 * or init pieces the location is */
1924 +static inline int in_init_rx(struct module *me, void *loc)
1926 + return (loc >= me->module_init_rx &&
1927 + loc < (me->module_init_rx + me->init_size_rx));
1930 +static inline int in_init_rw(struct module *me, void *loc)
1932 + return (loc >= me->module_init_rw &&
1933 + loc < (me->module_init_rw + me->init_size_rw));
1936 static inline int in_init(struct module *me, void *loc)
1938 - return (loc >= me->module_init &&
1939 - loc <= (me->module_init + me->init_size));
1940 + return in_init_rx(me, loc) || in_init_rw(me, loc);
1943 +static inline int in_core_rx(struct module *me, void *loc)
1945 + return (loc >= me->module_core_rx &&
1946 + loc < (me->module_core_rx + me->core_size_rx));
1949 +static inline int in_core_rw(struct module *me, void *loc)
1951 + return (loc >= me->module_core_rw &&
1952 + loc < (me->module_core_rw + me->core_size_rw));
1955 static inline int in_core(struct module *me, void *loc)
1957 - return (loc >= me->module_core &&
1958 - loc <= (me->module_core + me->core_size));
1959 + return in_core_rx(me, loc) || in_core_rw(me, loc);
1962 static inline int in_local(struct module *me, void *loc)
1963 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
1966 /* align things a bit */
1967 - me->core_size = ALIGN(me->core_size, 16);
1968 - me->arch.got_offset = me->core_size;
1969 - me->core_size += gots * sizeof(struct got_entry);
1970 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1971 + me->arch.got_offset = me->core_size_rw;
1972 + me->core_size_rw += gots * sizeof(struct got_entry);
1974 - me->core_size = ALIGN(me->core_size, 16);
1975 - me->arch.fdesc_offset = me->core_size;
1976 - me->core_size += fdescs * sizeof(Elf_Fdesc);
1977 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1978 + me->arch.fdesc_offset = me->core_size_rw;
1979 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1981 me->arch.got_max = gots;
1982 me->arch.fdesc_max = fdescs;
1983 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1987 - got = me->module_core + me->arch.got_offset;
1988 + got = me->module_core_rw + me->arch.got_offset;
1989 for (i = 0; got[i].addr; i++)
1990 if (got[i].addr == value)
1992 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1994 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1996 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1997 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2000 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2001 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2003 /* Create new one */
2004 fdesc->addr = value;
2005 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2006 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2007 return (Elf_Addr)fdesc;
2009 #endif /* CONFIG_64BIT */
2010 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
2012 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2013 end = table + sechdrs[me->arch.unwind_section].sh_size;
2014 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2015 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2017 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2018 me->arch.unwind_section, table, end, gp);
2019 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
2020 index c9b9322..02d8940 100644
2021 --- a/arch/parisc/kernel/sys_parisc.c
2022 +++ b/arch/parisc/kernel/sys_parisc.c
2023 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
2024 /* At this point: (!vma || addr < vma->vm_end). */
2025 if (TASK_SIZE - len < addr)
2027 - if (!vma || addr + len <= vma->vm_start)
2028 + if (check_heap_stack_gap(vma, addr, len))
2032 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
2033 /* At this point: (!vma || addr < vma->vm_end). */
2034 if (TASK_SIZE - len < addr)
2036 - if (!vma || addr + len <= vma->vm_start)
2037 + if (check_heap_stack_gap(vma, addr, len))
2039 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2040 if (addr < vma->vm_end) /* handle wraparound */
2041 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2042 if (flags & MAP_FIXED)
2045 - addr = TASK_UNMAPPED_BASE;
2046 + addr = current->mm->mmap_base;
2049 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2050 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
2051 index f19e660..414fe24 100644
2052 --- a/arch/parisc/kernel/traps.c
2053 +++ b/arch/parisc/kernel/traps.c
2054 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
2056 down_read(¤t->mm->mmap_sem);
2057 vma = find_vma(current->mm,regs->iaoq[0]);
2058 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2059 - && (vma->vm_flags & VM_EXEC)) {
2061 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2062 fault_address = regs->iaoq[0];
2063 fault_space = regs->iasq[0];
2065 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
2066 index 18162ce..94de376 100644
2067 --- a/arch/parisc/mm/fault.c
2068 +++ b/arch/parisc/mm/fault.c
2070 #include <linux/sched.h>
2071 #include <linux/interrupt.h>
2072 #include <linux/module.h>
2073 +#include <linux/unistd.h>
2075 #include <asm/uaccess.h>
2076 #include <asm/traps.h>
2077 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
2078 static unsigned long
2079 parisc_acctyp(unsigned long code, unsigned int inst)
2081 - if (code == 6 || code == 16)
2082 + if (code == 6 || code == 7 || code == 16)
2085 switch (inst & 0xf0000000) {
2086 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
2090 +#ifdef CONFIG_PAX_PAGEEXEC
2092 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2094 + * returns 1 when task should be killed
2095 + * 2 when rt_sigreturn trampoline was detected
2096 + * 3 when unpatched PLT trampoline was detected
2098 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2101 +#ifdef CONFIG_PAX_EMUPLT
2104 + do { /* PaX: unpatched PLT emulation */
2105 + unsigned int bl, depwi;
2107 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2108 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2113 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2114 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2116 + err = get_user(ldw, (unsigned int *)addr);
2117 + err |= get_user(bv, (unsigned int *)(addr+4));
2118 + err |= get_user(ldw2, (unsigned int *)(addr+8));
2123 + if (ldw == 0x0E801096U &&
2124 + bv == 0xEAC0C000U &&
2125 + ldw2 == 0x0E881095U)
2127 + unsigned int resolver, map;
2129 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2130 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2134 + regs->gr[20] = instruction_pointer(regs)+8;
2135 + regs->gr[21] = map;
2136 + regs->gr[22] = resolver;
2137 + regs->iaoq[0] = resolver | 3UL;
2138 + regs->iaoq[1] = regs->iaoq[0] + 4;
2145 +#ifdef CONFIG_PAX_EMUTRAMP
2147 +#ifndef CONFIG_PAX_EMUSIGRT
2148 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2152 + do { /* PaX: rt_sigreturn emulation */
2153 + unsigned int ldi1, ldi2, bel, nop;
2155 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2156 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2157 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2158 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2163 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2164 + ldi2 == 0x3414015AU &&
2165 + bel == 0xE4008200U &&
2166 + nop == 0x08000240U)
2168 + regs->gr[25] = (ldi1 & 2) >> 1;
2169 + regs->gr[20] = __NR_rt_sigreturn;
2170 + regs->gr[31] = regs->iaoq[1] + 16;
2171 + regs->sr[0] = regs->iasq[1];
2172 + regs->iaoq[0] = 0x100UL;
2173 + regs->iaoq[1] = regs->iaoq[0] + 4;
2174 + regs->iasq[0] = regs->sr[2];
2175 + regs->iasq[1] = regs->sr[2];
2184 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2188 + printk(KERN_ERR "PAX: bytes at PC: ");
2189 + for (i = 0; i < 5; i++) {
2191 + if (get_user(c, (unsigned int *)pc+i))
2192 + printk(KERN_CONT "???????? ");
2194 + printk(KERN_CONT "%08x ", c);
2200 int fixup_exception(struct pt_regs *regs)
2202 const struct exception_table_entry *fix;
2203 @@ -192,8 +303,33 @@ good_area:
2205 acc_type = parisc_acctyp(code,regs->iir);
2207 - if ((vma->vm_flags & acc_type) != acc_type)
2208 + if ((vma->vm_flags & acc_type) != acc_type) {
2210 +#ifdef CONFIG_PAX_PAGEEXEC
2211 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2212 + (address & ~3UL) == instruction_pointer(regs))
2214 + up_read(&mm->mmap_sem);
2215 + switch (pax_handle_fetch_fault(regs)) {
2217 +#ifdef CONFIG_PAX_EMUPLT
2222 +#ifdef CONFIG_PAX_EMUTRAMP
2228 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2229 + do_group_exit(SIGKILL);
2237 * If for any reason at all we couldn't handle the fault, make
2238 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
2239 index 02e41b5..ec6e26c 100644
2240 --- a/arch/powerpc/include/asm/atomic.h
2241 +++ b/arch/powerpc/include/asm/atomic.h
2242 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2244 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2246 +#define atomic64_read_unchecked(v) atomic64_read(v)
2247 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2248 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2249 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2250 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2251 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2252 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2253 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2254 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2256 #endif /* __powerpc64__ */
2258 #endif /* __KERNEL__ */
2259 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2260 index 3bf9cca..e7457d0 100644
2261 --- a/arch/powerpc/include/asm/elf.h
2262 +++ b/arch/powerpc/include/asm/elf.h
2263 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
2264 the loader. We need to make sure that it is out of the way of the program
2265 that it will "exec", and that there is sufficient room for the brk. */
2267 -extern unsigned long randomize_et_dyn(unsigned long base);
2268 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2269 +#define ELF_ET_DYN_BASE (0x20000000)
2271 +#ifdef CONFIG_PAX_ASLR
2272 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2274 +#ifdef __powerpc64__
2275 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
2276 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
2278 +#define PAX_DELTA_MMAP_LEN 15
2279 +#define PAX_DELTA_STACK_LEN 15
2284 * Our registers are always unsigned longs, whether we're a 32 bit
2285 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2286 (0x7ff >> (PAGE_SHIFT - 12)) : \
2287 (0x3ffff >> (PAGE_SHIFT - 12)))
2289 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2290 -#define arch_randomize_brk arch_randomize_brk
2292 #endif /* __KERNEL__ */
2295 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2296 index bca8fdc..61e9580 100644
2297 --- a/arch/powerpc/include/asm/kmap_types.h
2298 +++ b/arch/powerpc/include/asm/kmap_types.h
2299 @@ -27,6 +27,7 @@ enum km_type {
2307 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
2308 index d4a7f64..451de1c 100644
2309 --- a/arch/powerpc/include/asm/mman.h
2310 +++ b/arch/powerpc/include/asm/mman.h
2311 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
2313 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
2315 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
2316 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
2318 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
2320 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2321 index dd9c4fd..a2ced87 100644
2322 --- a/arch/powerpc/include/asm/page.h
2323 +++ b/arch/powerpc/include/asm/page.h
2324 @@ -141,8 +141,9 @@ extern phys_addr_t kernstart_addr;
2325 * and needs to be executable. This means the whole heap ends
2326 * up being executable.
2328 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2329 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2330 +#define VM_DATA_DEFAULT_FLAGS32 \
2331 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2332 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2334 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2335 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2336 @@ -170,6 +171,9 @@ extern phys_addr_t kernstart_addr;
2337 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2340 +#define ktla_ktva(addr) (addr)
2341 +#define ktva_ktla(addr) (addr)
2344 * Use the top bit of the higher-level page table entries to indicate whether
2345 * the entries we point to contain hugepages. This works because we know that
2346 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2347 index fb40ede..d3ce956 100644
2348 --- a/arch/powerpc/include/asm/page_64.h
2349 +++ b/arch/powerpc/include/asm/page_64.h
2350 @@ -144,15 +144,18 @@ do { \
2351 * stack by default, so in the absence of a PT_GNU_STACK program header
2352 * we turn execute permission off.
2354 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2355 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2356 +#define VM_STACK_DEFAULT_FLAGS32 \
2357 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2358 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2360 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2361 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2363 +#ifndef CONFIG_PAX_PAGEEXEC
2364 #define VM_STACK_DEFAULT_FLAGS \
2365 (is_32bit_task() ? \
2366 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2369 #include <asm-generic/getorder.h>
2371 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2372 index 88b0bd9..e32bc67 100644
2373 --- a/arch/powerpc/include/asm/pgtable.h
2374 +++ b/arch/powerpc/include/asm/pgtable.h
2376 #define _ASM_POWERPC_PGTABLE_H
2379 +#include <linux/const.h>
2380 #ifndef __ASSEMBLY__
2381 #include <asm/processor.h> /* For TASK_SIZE */
2382 #include <asm/mmu.h>
2383 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2384 index 4aad413..85d86bf 100644
2385 --- a/arch/powerpc/include/asm/pte-hash32.h
2386 +++ b/arch/powerpc/include/asm/pte-hash32.h
2388 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2389 #define _PAGE_USER 0x004 /* usermode access allowed */
2390 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2391 +#define _PAGE_EXEC _PAGE_GUARDED
2392 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2393 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2394 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2395 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2396 index 559da19..7e5835c 100644
2397 --- a/arch/powerpc/include/asm/reg.h
2398 +++ b/arch/powerpc/include/asm/reg.h
2400 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2401 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2402 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2403 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2404 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2405 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2406 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2407 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2408 index e30a13d..2b7d994 100644
2409 --- a/arch/powerpc/include/asm/system.h
2410 +++ b/arch/powerpc/include/asm/system.h
2411 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
2412 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2415 -extern unsigned long arch_align_stack(unsigned long sp);
2416 +#define arch_align_stack(x) ((x) & ~0xfUL)
2418 /* Used in very early kernel initialization. */
2419 extern unsigned long reloc_offset(void);
2420 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2421 index bd0fb84..a42a14b 100644
2422 --- a/arch/powerpc/include/asm/uaccess.h
2423 +++ b/arch/powerpc/include/asm/uaccess.h
2425 #define VERIFY_READ 0
2426 #define VERIFY_WRITE 1
2428 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2431 * The fs value determines whether argument validity checking should be
2432 * performed or not. If get_fs() == USER_DS, checking is performed, with
2433 @@ -327,52 +329,6 @@ do { \
2434 extern unsigned long __copy_tofrom_user(void __user *to,
2435 const void __user *from, unsigned long size);
2437 -#ifndef __powerpc64__
2439 -static inline unsigned long copy_from_user(void *to,
2440 - const void __user *from, unsigned long n)
2442 - unsigned long over;
2444 - if (access_ok(VERIFY_READ, from, n))
2445 - return __copy_tofrom_user((__force void __user *)to, from, n);
2446 - if ((unsigned long)from < TASK_SIZE) {
2447 - over = (unsigned long)from + n - TASK_SIZE;
2448 - return __copy_tofrom_user((__force void __user *)to, from,
2454 -static inline unsigned long copy_to_user(void __user *to,
2455 - const void *from, unsigned long n)
2457 - unsigned long over;
2459 - if (access_ok(VERIFY_WRITE, to, n))
2460 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2461 - if ((unsigned long)to < TASK_SIZE) {
2462 - over = (unsigned long)to + n - TASK_SIZE;
2463 - return __copy_tofrom_user(to, (__force void __user *)from,
2469 -#else /* __powerpc64__ */
2471 -#define __copy_in_user(to, from, size) \
2472 - __copy_tofrom_user((to), (from), (size))
2474 -extern unsigned long copy_from_user(void *to, const void __user *from,
2476 -extern unsigned long copy_to_user(void __user *to, const void *from,
2478 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2481 -#endif /* __powerpc64__ */
2483 static inline unsigned long __copy_from_user_inatomic(void *to,
2484 const void __user *from, unsigned long n)
2486 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
2491 + if (!__builtin_constant_p(n))
2492 + check_object_size(to, n, false);
2494 return __copy_tofrom_user((__force void __user *)to, from, n);
2497 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
2502 + if (!__builtin_constant_p(n))
2503 + check_object_size(from, n, true);
2505 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2508 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
2509 return __copy_to_user_inatomic(to, from, size);
2512 +#ifndef __powerpc64__
2514 +static inline unsigned long __must_check copy_from_user(void *to,
2515 + const void __user *from, unsigned long n)
2517 + unsigned long over;
2522 + if (access_ok(VERIFY_READ, from, n)) {
2523 + if (!__builtin_constant_p(n))
2524 + check_object_size(to, n, false);
2525 + return __copy_tofrom_user((__force void __user *)to, from, n);
2527 + if ((unsigned long)from < TASK_SIZE) {
2528 + over = (unsigned long)from + n - TASK_SIZE;
2529 + if (!__builtin_constant_p(n - over))
2530 + check_object_size(to, n - over, false);
2531 + return __copy_tofrom_user((__force void __user *)to, from,
2537 +static inline unsigned long __must_check copy_to_user(void __user *to,
2538 + const void *from, unsigned long n)
2540 + unsigned long over;
2545 + if (access_ok(VERIFY_WRITE, to, n)) {
2546 + if (!__builtin_constant_p(n))
2547 + check_object_size(from, n, true);
2548 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2550 + if ((unsigned long)to < TASK_SIZE) {
2551 + over = (unsigned long)to + n - TASK_SIZE;
2552 + if (!__builtin_constant_p(n))
2553 + check_object_size(from, n - over, true);
2554 + return __copy_tofrom_user(to, (__force void __user *)from,
2560 +#else /* __powerpc64__ */
2562 +#define __copy_in_user(to, from, size) \
2563 + __copy_tofrom_user((to), (from), (size))
2565 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2567 + if ((long)n < 0 || n > INT_MAX)
2570 + if (!__builtin_constant_p(n))
2571 + check_object_size(to, n, false);
2573 + if (likely(access_ok(VERIFY_READ, from, n)))
2574 + n = __copy_from_user(to, from, n);
2580 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2582 + if ((long)n < 0 || n > INT_MAX)
2585 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2586 + if (!__builtin_constant_p(n))
2587 + check_object_size(from, n, true);
2588 + n = __copy_to_user(to, from, n);
2593 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2596 +#endif /* __powerpc64__ */
2598 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2600 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2601 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
2602 index 429983c..7af363b 100644
2603 --- a/arch/powerpc/kernel/exceptions-64e.S
2604 +++ b/arch/powerpc/kernel/exceptions-64e.S
2605 @@ -587,6 +587,7 @@ storage_fault_common:
2608 addi r3,r1,STACK_FRAME_OVERHEAD
2612 ld r14,PACA_EXGEN+EX_R14(r13)
2613 @@ -596,8 +597,7 @@ storage_fault_common:
2616 b .ret_from_except_lite
2620 addi r3,r1,STACK_FRAME_OVERHEAD
2623 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
2624 index cf9c69b..ebc9640 100644
2625 --- a/arch/powerpc/kernel/exceptions-64s.S
2626 +++ b/arch/powerpc/kernel/exceptions-64s.S
2627 @@ -1004,10 +1004,10 @@ handle_page_fault:
2630 addi r3,r1,STACK_FRAME_OVERHEAD
2637 addi r3,r1,STACK_FRAME_OVERHEAD
2639 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
2640 index 0b6d796..d760ddb 100644
2641 --- a/arch/powerpc/kernel/module_32.c
2642 +++ b/arch/powerpc/kernel/module_32.c
2643 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
2644 me->arch.core_plt_section = i;
2646 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2647 - printk("Module doesn't contain .plt or .init.plt sections.\n");
2648 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2652 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
2654 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2655 /* Init, or core PLT? */
2656 - if (location >= mod->module_core
2657 - && location < mod->module_core + mod->core_size)
2658 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2659 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2660 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2662 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2663 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2664 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2666 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2670 /* Find this entry, or if that fails, the next avail. entry */
2671 while (entry->jump[0]) {
2672 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
2673 index 6457574..08b28d3 100644
2674 --- a/arch/powerpc/kernel/process.c
2675 +++ b/arch/powerpc/kernel/process.c
2676 @@ -660,8 +660,8 @@ void show_regs(struct pt_regs * regs)
2677 * Lookup NIP late so we have the best change of getting the
2678 * above info out without failing
2680 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2681 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2682 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2683 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2685 show_stack(current, (unsigned long *) regs->gpr[1]);
2686 if (!user_mode(regs))
2687 @@ -1165,10 +1165,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2689 ip = stack[STACK_FRAME_LR_SAVE];
2690 if (!firstframe || ip != lr) {
2691 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2692 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2693 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2694 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2697 (void *)current->ret_stack[curr_frame].ret);
2700 @@ -1188,7 +1188,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2701 struct pt_regs *regs = (struct pt_regs *)
2702 (sp + STACK_FRAME_OVERHEAD);
2704 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
2705 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
2706 regs->trap, (void *)regs->nip, (void *)lr);
2709 @@ -1263,58 +1263,3 @@ void thread_info_cache_init(void)
2712 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2714 -unsigned long arch_align_stack(unsigned long sp)
2716 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2717 - sp -= get_random_int() & ~PAGE_MASK;
2721 -static inline unsigned long brk_rnd(void)
2723 - unsigned long rnd = 0;
2725 - /* 8MB for 32bit, 1GB for 64bit */
2726 - if (is_32bit_task())
2727 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2729 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2731 - return rnd << PAGE_SHIFT;
2734 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2736 - unsigned long base = mm->brk;
2737 - unsigned long ret;
2739 -#ifdef CONFIG_PPC_STD_MMU_64
2741 - * If we are using 1TB segments and we are allowed to randomise
2742 - * the heap, we can put it above 1TB so it is backed by a 1TB
2743 - * segment. Otherwise the heap will be in the bottom 1TB
2744 - * which always uses 256MB segments and this may result in a
2745 - * performance penalty.
2747 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2748 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2751 - ret = PAGE_ALIGN(base + brk_rnd());
2753 - if (ret < mm->brk)
2759 -unsigned long randomize_et_dyn(unsigned long base)
2761 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2768 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
2769 index 836a5a1..27289a3 100644
2770 --- a/arch/powerpc/kernel/signal_32.c
2771 +++ b/arch/powerpc/kernel/signal_32.c
2772 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
2773 /* Save user registers on the stack */
2774 frame = &rt_sf->uc.uc_mcontext;
2776 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2777 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2778 if (save_user_regs(regs, frame, 0, 1))
2780 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2781 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
2782 index a50b5ec..547078a 100644
2783 --- a/arch/powerpc/kernel/signal_64.c
2784 +++ b/arch/powerpc/kernel/signal_64.c
2785 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
2786 current->thread.fpscr.val = 0;
2788 /* Set up to return from userspace. */
2789 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2790 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2791 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2793 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2794 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
2795 index 5459d14..10f8070 100644
2796 --- a/arch/powerpc/kernel/traps.c
2797 +++ b/arch/powerpc/kernel/traps.c
2798 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
2799 static inline void pmac_backlight_unblank(void) { }
2802 +extern void gr_handle_kernel_exploit(void);
2804 int die(const char *str, struct pt_regs *regs, long err)
2807 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
2809 panic("Fatal exception");
2811 + gr_handle_kernel_exploit();
2816 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
2817 index 7d14bb6..1305601 100644
2818 --- a/arch/powerpc/kernel/vdso.c
2819 +++ b/arch/powerpc/kernel/vdso.c
2821 #include <asm/firmware.h>
2822 #include <asm/vdso.h>
2823 #include <asm/vdso_datapage.h>
2824 +#include <asm/mman.h>
2828 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2829 vdso_base = VDSO32_MBASE;
2832 - current->mm->context.vdso_base = 0;
2833 + current->mm->context.vdso_base = ~0UL;
2835 /* vDSO has a problem and was disabled, just don't "enable" it for the
2837 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2838 vdso_base = get_unmapped_area(NULL, vdso_base,
2839 (vdso_pages << PAGE_SHIFT) +
2840 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2842 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
2843 if (IS_ERR_VALUE(vdso_base)) {
2846 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
2847 index 5eea6f3..5d10396 100644
2848 --- a/arch/powerpc/lib/usercopy_64.c
2849 +++ b/arch/powerpc/lib/usercopy_64.c
2851 #include <linux/module.h>
2852 #include <asm/uaccess.h>
2854 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2856 - if (likely(access_ok(VERIFY_READ, from, n)))
2857 - n = __copy_from_user(to, from, n);
2863 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2865 - if (likely(access_ok(VERIFY_WRITE, to, n)))
2866 - n = __copy_to_user(to, from, n);
2870 unsigned long copy_in_user(void __user *to, const void __user *from,
2873 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
2877 -EXPORT_SYMBOL(copy_from_user);
2878 -EXPORT_SYMBOL(copy_to_user);
2879 EXPORT_SYMBOL(copy_in_user);
2881 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
2882 index 5efe8c9..db9ceef 100644
2883 --- a/arch/powerpc/mm/fault.c
2884 +++ b/arch/powerpc/mm/fault.c
2886 #include <linux/perf_event.h>
2887 #include <linux/magic.h>
2888 #include <linux/ratelimit.h>
2889 +#include <linux/slab.h>
2890 +#include <linux/pagemap.h>
2891 +#include <linux/compiler.h>
2892 +#include <linux/unistd.h>
2894 #include <asm/firmware.h>
2895 #include <asm/page.h>
2897 #include <asm/tlbflush.h>
2898 #include <asm/siginfo.h>
2899 #include <mm/mmu_decl.h>
2900 +#include <asm/ptrace.h>
2902 #ifdef CONFIG_KPROBES
2903 static inline int notify_page_fault(struct pt_regs *regs)
2904 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
2908 +#ifdef CONFIG_PAX_PAGEEXEC
2910 + * PaX: decide what to do with offenders (regs->nip = fault address)
2912 + * returns 1 when task should be killed
2914 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2919 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2923 + printk(KERN_ERR "PAX: bytes at PC: ");
2924 + for (i = 0; i < 5; i++) {
2926 + if (get_user(c, (unsigned int __user *)pc+i))
2927 + printk(KERN_CONT "???????? ");
2929 + printk(KERN_CONT "%08x ", c);
2936 * Check whether the instruction at regs->nip is a store using
2937 * an update addressing form which will update r1.
2938 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
2939 * indicate errors in DSISR but can validly be set in SRR1.
2942 - error_code &= 0x48200000;
2943 + error_code &= 0x58200000;
2945 is_write = error_code & DSISR_ISSTORE;
2947 @@ -259,7 +291,7 @@ good_area:
2948 * "undefined". Of those that can be set, this is the only
2949 * one which seems bad.
2951 - if (error_code & 0x10000000)
2952 + if (error_code & DSISR_GUARDED)
2953 /* Guarded storage error. */
2955 #endif /* CONFIG_8xx */
2956 @@ -274,7 +306,7 @@ good_area:
2957 * processors use the same I/D cache coherency mechanism
2960 - if (error_code & DSISR_PROTFAULT)
2961 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2963 #endif /* CONFIG_PPC_STD_MMU */
2965 @@ -343,6 +375,23 @@ bad_area:
2966 bad_area_nosemaphore:
2967 /* User mode accesses cause a SIGSEGV */
2968 if (user_mode(regs)) {
2970 +#ifdef CONFIG_PAX_PAGEEXEC
2971 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2972 +#ifdef CONFIG_PPC_STD_MMU
2973 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2975 + if (is_exec && regs->nip == address) {
2977 + switch (pax_handle_fetch_fault(regs)) {
2980 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2981 + do_group_exit(SIGKILL);
2986 _exception(SIGSEGV, regs, code, address);
2989 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
2990 index 5a783d8..c23e14b 100644
2991 --- a/arch/powerpc/mm/mmap_64.c
2992 +++ b/arch/powerpc/mm/mmap_64.c
2993 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2995 if (mmap_is_legacy()) {
2996 mm->mmap_base = TASK_UNMAPPED_BASE;
2998 +#ifdef CONFIG_PAX_RANDMMAP
2999 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3000 + mm->mmap_base += mm->delta_mmap;
3003 mm->get_unmapped_area = arch_get_unmapped_area;
3004 mm->unmap_area = arch_unmap_area;
3006 mm->mmap_base = mmap_base();
3008 +#ifdef CONFIG_PAX_RANDMMAP
3009 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3010 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3013 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3014 mm->unmap_area = arch_unmap_area_topdown;
3016 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
3017 index 73709f7..6b90313 100644
3018 --- a/arch/powerpc/mm/slice.c
3019 +++ b/arch/powerpc/mm/slice.c
3020 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
3021 if ((mm->task_size - len) < addr)
3023 vma = find_vma(mm, addr);
3024 - return (!vma || (addr + len) <= vma->vm_start);
3025 + return check_heap_stack_gap(vma, addr, len);
3028 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3029 @@ -256,7 +256,7 @@ full_search:
3030 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3033 - if (!vma || addr + len <= vma->vm_start) {
3034 + if (check_heap_stack_gap(vma, addr, len)) {
3036 * Remember the place where we stopped the search:
3038 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3042 - addr = mm->mmap_base;
3043 - while (addr > len) {
3044 + if (mm->mmap_base < len)
3047 + addr = mm->mmap_base - len;
3049 + while (!IS_ERR_VALUE(addr)) {
3050 /* Go down by chunk size */
3051 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3052 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
3054 /* Check for hit with different page size */
3055 mask = slice_range_to_mask(addr, len);
3056 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3057 * return with success:
3059 vma = find_vma(mm, addr);
3060 - if (!vma || (addr + len) <= vma->vm_start) {
3061 + if (check_heap_stack_gap(vma, addr, len)) {
3062 /* remember the address as a hint for next time */
3064 mm->free_area_cache = addr;
3065 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3066 mm->cached_hole_size = vma->vm_start - addr;
3068 /* try just below the current vma->vm_start */
3069 - addr = vma->vm_start;
3070 + addr = skip_heap_stack_gap(vma, len);
3074 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
3075 if (fixed && addr > (mm->task_size - len))
3078 +#ifdef CONFIG_PAX_RANDMMAP
3079 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3083 /* If hint, make sure it matches our alignment restrictions */
3084 if (!fixed && addr) {
3085 addr = _ALIGN_UP(addr, 1ul << pshift);
3086 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
3087 index 8517d2a..d2738d4 100644
3088 --- a/arch/s390/include/asm/atomic.h
3089 +++ b/arch/s390/include/asm/atomic.h
3090 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
3091 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
3092 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3094 +#define atomic64_read_unchecked(v) atomic64_read(v)
3095 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3096 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3097 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3098 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3099 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3100 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3101 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3102 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3104 #define smp_mb__before_atomic_dec() smp_mb()
3105 #define smp_mb__after_atomic_dec() smp_mb()
3106 #define smp_mb__before_atomic_inc() smp_mb()
3107 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
3108 index 547f1a6..0b22b53 100644
3109 --- a/arch/s390/include/asm/elf.h
3110 +++ b/arch/s390/include/asm/elf.h
3111 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
3112 the loader. We need to make sure that it is out of the way of the program
3113 that it will "exec", and that there is sufficient room for the brk. */
3115 -extern unsigned long randomize_et_dyn(unsigned long base);
3116 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
3117 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3119 +#ifdef CONFIG_PAX_ASLR
3120 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3122 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
3123 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
3126 /* This yields a mask that user programs can use to figure out what
3127 instruction set this CPU supports. */
3128 @@ -211,7 +217,4 @@ struct linux_binprm;
3129 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3130 int arch_setup_additional_pages(struct linux_binprm *, int);
3132 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3133 -#define arch_randomize_brk arch_randomize_brk
3136 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
3137 index ef573c1..75a1ce6 100644
3138 --- a/arch/s390/include/asm/system.h
3139 +++ b/arch/s390/include/asm/system.h
3140 @@ -262,7 +262,7 @@ extern void (*_machine_restart)(char *command);
3141 extern void (*_machine_halt)(void);
3142 extern void (*_machine_power_off)(void);
3144 -extern unsigned long arch_align_stack(unsigned long sp);
3145 +#define arch_align_stack(x) ((x) & ~0xfUL)
3147 static inline int tprot(unsigned long addr)
3149 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
3150 index 2b23885..e136e31 100644
3151 --- a/arch/s390/include/asm/uaccess.h
3152 +++ b/arch/s390/include/asm/uaccess.h
3153 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
3154 copy_to_user(void __user *to, const void *from, unsigned long n)
3161 if (access_ok(VERIFY_WRITE, to, n))
3162 n = __copy_to_user(to, from, n);
3164 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
3165 static inline unsigned long __must_check
3166 __copy_from_user(void *to, const void __user *from, unsigned long n)
3171 if (__builtin_constant_p(n) && (n <= 256))
3172 return uaccess.copy_from_user_small(n, from, to);
3174 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
3175 unsigned int sz = __compiletime_object_size(to);
3182 if (unlikely(sz != -1 && sz < n)) {
3183 copy_from_user_overflow();
3185 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
3186 index dfcb343..eda788a 100644
3187 --- a/arch/s390/kernel/module.c
3188 +++ b/arch/s390/kernel/module.c
3189 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
3191 /* Increase core size by size of got & plt and set start
3192 offsets for got and plt. */
3193 - me->core_size = ALIGN(me->core_size, 4);
3194 - me->arch.got_offset = me->core_size;
3195 - me->core_size += me->arch.got_size;
3196 - me->arch.plt_offset = me->core_size;
3197 - me->core_size += me->arch.plt_size;
3198 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3199 + me->arch.got_offset = me->core_size_rw;
3200 + me->core_size_rw += me->arch.got_size;
3201 + me->arch.plt_offset = me->core_size_rx;
3202 + me->core_size_rx += me->arch.plt_size;
3206 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3207 if (info->got_initialized == 0) {
3210 - gotent = me->module_core + me->arch.got_offset +
3211 + gotent = me->module_core_rw + me->arch.got_offset +
3214 info->got_initialized = 1;
3215 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3216 else if (r_type == R_390_GOTENT ||
3217 r_type == R_390_GOTPLTENT)
3218 *(unsigned int *) loc =
3219 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3220 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3221 else if (r_type == R_390_GOT64 ||
3222 r_type == R_390_GOTPLT64)
3223 *(unsigned long *) loc = val;
3224 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3225 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3226 if (info->plt_initialized == 0) {
3228 - ip = me->module_core + me->arch.plt_offset +
3229 + ip = me->module_core_rx + me->arch.plt_offset +
3231 #ifndef CONFIG_64BIT
3232 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3233 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3234 val - loc + 0xffffUL < 0x1ffffeUL) ||
3235 (r_type == R_390_PLT32DBL &&
3236 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3237 - val = (Elf_Addr) me->module_core +
3238 + val = (Elf_Addr) me->module_core_rx +
3239 me->arch.plt_offset +
3241 val += rela->r_addend - loc;
3242 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3243 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3244 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3245 val = val + rela->r_addend -
3246 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3247 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3248 if (r_type == R_390_GOTOFF16)
3249 *(unsigned short *) loc = val;
3250 else if (r_type == R_390_GOTOFF32)
3251 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3253 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3254 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3255 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3256 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3257 rela->r_addend - loc;
3258 if (r_type == R_390_GOTPC)
3259 *(unsigned int *) loc = val;
3260 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
3261 index 9451b21..ed8956f 100644
3262 --- a/arch/s390/kernel/process.c
3263 +++ b/arch/s390/kernel/process.c
3264 @@ -321,39 +321,3 @@ unsigned long get_wchan(struct task_struct *p)
3269 -unsigned long arch_align_stack(unsigned long sp)
3271 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3272 - sp -= get_random_int() & ~PAGE_MASK;
3276 -static inline unsigned long brk_rnd(void)
3278 - /* 8MB for 32bit, 1GB for 64bit */
3279 - if (is_32bit_task())
3280 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
3282 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
3285 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3287 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
3289 - if (ret < mm->brk)
3294 -unsigned long randomize_et_dyn(unsigned long base)
3296 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3298 - if (!(current->flags & PF_RANDOMIZE))
3304 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
3305 index f09c748..cf9ec1d 100644
3306 --- a/arch/s390/mm/mmap.c
3307 +++ b/arch/s390/mm/mmap.c
3308 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3310 if (mmap_is_legacy()) {
3311 mm->mmap_base = TASK_UNMAPPED_BASE;
3313 +#ifdef CONFIG_PAX_RANDMMAP
3314 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3315 + mm->mmap_base += mm->delta_mmap;
3318 mm->get_unmapped_area = arch_get_unmapped_area;
3319 mm->unmap_area = arch_unmap_area;
3321 mm->mmap_base = mmap_base();
3323 +#ifdef CONFIG_PAX_RANDMMAP
3324 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3325 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3328 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3329 mm->unmap_area = arch_unmap_area_topdown;
3331 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3333 if (mmap_is_legacy()) {
3334 mm->mmap_base = TASK_UNMAPPED_BASE;
3336 +#ifdef CONFIG_PAX_RANDMMAP
3337 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3338 + mm->mmap_base += mm->delta_mmap;
3341 mm->get_unmapped_area = s390_get_unmapped_area;
3342 mm->unmap_area = arch_unmap_area;
3344 mm->mmap_base = mmap_base();
3346 +#ifdef CONFIG_PAX_RANDMMAP
3347 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3348 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3351 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3352 mm->unmap_area = arch_unmap_area_topdown;
3354 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
3355 index 589d5c7..669e274 100644
3356 --- a/arch/score/include/asm/system.h
3357 +++ b/arch/score/include/asm/system.h
3358 @@ -17,7 +17,7 @@ do { \
3359 #define finish_arch_switch(prev) do {} while (0)
3361 typedef void (*vi_handler_t)(void);
3362 -extern unsigned long arch_align_stack(unsigned long sp);
3363 +#define arch_align_stack(x) (x)
3365 #define mb() barrier()
3366 #define rmb() barrier()
3367 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
3368 index 25d0803..d6c8e36 100644
3369 --- a/arch/score/kernel/process.c
3370 +++ b/arch/score/kernel/process.c
3371 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
3373 return task_pt_regs(task)->cp0_epc;
3376 -unsigned long arch_align_stack(unsigned long sp)
3380 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
3381 index afeb710..d1d1289 100644
3382 --- a/arch/sh/mm/mmap.c
3383 +++ b/arch/sh/mm/mmap.c
3384 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3385 addr = PAGE_ALIGN(addr);
3387 vma = find_vma(mm, addr);
3388 - if (TASK_SIZE - len >= addr &&
3389 - (!vma || addr + len <= vma->vm_start))
3390 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3394 @@ -106,7 +105,7 @@ full_search:
3398 - if (likely(!vma || addr + len <= vma->vm_start)) {
3399 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3401 * Remember the place where we stopped the search:
3403 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3404 addr = PAGE_ALIGN(addr);
3406 vma = find_vma(mm, addr);
3407 - if (TASK_SIZE - len >= addr &&
3408 - (!vma || addr + len <= vma->vm_start))
3409 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3413 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3414 /* make sure it can fit in the remaining address space */
3415 if (likely(addr > len)) {
3416 vma = find_vma(mm, addr-len);
3417 - if (!vma || addr <= vma->vm_start) {
3418 + if (check_heap_stack_gap(vma, addr - len, len)) {
3419 /* remember the address as a hint for next time */
3420 return (mm->free_area_cache = addr-len);
3422 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3423 if (unlikely(mm->mmap_base < len))
3426 - addr = mm->mmap_base-len;
3427 - if (do_colour_align)
3428 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3429 + addr = mm->mmap_base - len;
3432 + if (do_colour_align)
3433 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3435 * Lookup failure means no vma is above this address,
3436 * else if new region fits below vma->vm_start,
3437 * return with success:
3439 vma = find_vma(mm, addr);
3440 - if (likely(!vma || addr+len <= vma->vm_start)) {
3441 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3442 /* remember the address as a hint for next time */
3443 return (mm->free_area_cache = addr);
3445 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3446 mm->cached_hole_size = vma->vm_start - addr;
3448 /* try just below the current vma->vm_start */
3449 - addr = vma->vm_start-len;
3450 - if (do_colour_align)
3451 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3452 - } while (likely(len < vma->vm_start));
3453 + addr = skip_heap_stack_gap(vma, len);
3454 + } while (!IS_ERR_VALUE(addr));
3458 diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
3459 index f92602e..27060b2 100644
3460 --- a/arch/sparc/Kconfig
3461 +++ b/arch/sparc/Kconfig
3462 @@ -31,6 +31,7 @@ config SPARC
3466 + select GENERIC_ATOMIC64
3470 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
3471 index ad1fb5d..fc5315b 100644
3472 --- a/arch/sparc/Makefile
3473 +++ b/arch/sparc/Makefile
3474 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
3475 # Export what is needed by arch/sparc/boot/Makefile
3476 export VMLINUX_INIT VMLINUX_MAIN
3477 VMLINUX_INIT := $(head-y) $(init-y)
3478 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
3479 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
3480 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
3481 VMLINUX_MAIN += $(drivers-y) $(net-y)
3483 diff --git a/arch/sparc/include/asm/atomic.h b/arch/sparc/include/asm/atomic.h
3484 index 8ff83d8..4a459c2 100644
3485 --- a/arch/sparc/include/asm/atomic.h
3486 +++ b/arch/sparc/include/asm/atomic.h
3488 #include <asm/atomic_64.h>
3490 #include <asm/atomic_32.h>
3491 +#include <asm-generic/atomic64.h>
3494 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
3495 index 9f421df..b81fc12 100644
3496 --- a/arch/sparc/include/asm/atomic_64.h
3497 +++ b/arch/sparc/include/asm/atomic_64.h
3499 #define ATOMIC64_INIT(i) { (i) }
3501 #define atomic_read(v) (*(volatile int *)&(v)->counter)
3502 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3504 + return v->counter;
3506 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
3507 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3509 + return v->counter;
3512 #define atomic_set(v, i) (((v)->counter) = i)
3513 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3517 #define atomic64_set(v, i) (((v)->counter) = i)
3518 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3523 extern void atomic_add(int, atomic_t *);
3524 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3525 extern void atomic64_add(long, atomic64_t *);
3526 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3527 extern void atomic_sub(int, atomic_t *);
3528 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3529 extern void atomic64_sub(long, atomic64_t *);
3530 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3532 extern int atomic_add_ret(int, atomic_t *);
3533 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3534 extern long atomic64_add_ret(long, atomic64_t *);
3535 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3536 extern int atomic_sub_ret(int, atomic_t *);
3537 extern long atomic64_sub_ret(long, atomic64_t *);
3539 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3540 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3542 #define atomic_inc_return(v) atomic_add_ret(1, v)
3543 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3545 + return atomic_add_ret_unchecked(1, v);
3547 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3548 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3550 + return atomic64_add_ret_unchecked(1, v);
3553 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3554 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3556 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3557 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3559 + return atomic_add_ret_unchecked(i, v);
3561 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3562 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
3564 + return atomic64_add_ret_unchecked(i, v);
3568 * atomic_inc_and_test - increment and test
3569 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3572 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3573 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
3575 + return atomic_inc_return_unchecked(v) == 0;
3577 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3579 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3580 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3581 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3583 #define atomic_inc(v) atomic_add(1, v)
3584 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3586 + atomic_add_unchecked(1, v);
3588 #define atomic64_inc(v) atomic64_add(1, v)
3589 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3591 + atomic64_add_unchecked(1, v);
3594 #define atomic_dec(v) atomic_sub(1, v)
3595 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3597 + atomic_sub_unchecked(1, v);
3599 #define atomic64_dec(v) atomic64_sub(1, v)
3600 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3602 + atomic64_sub_unchecked(1, v);
3605 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3606 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3608 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3609 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
3611 + return cmpxchg(&v->counter, old, new);
3613 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3614 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
3616 + return xchg(&v->counter, new);
3619 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3625 - if (unlikely(c == (u)))
3626 + if (unlikely(c == u))
3628 - old = atomic_cmpxchg((v), c, c + (a));
3630 + asm volatile("addcc %2, %0, %0\n"
3632 +#ifdef CONFIG_PAX_REFCOUNT
3637 + : "0" (c), "ir" (a)
3640 + old = atomic_cmpxchg(v, c, new);
3641 if (likely(old == c))
3644 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3645 #define atomic64_cmpxchg(v, o, n) \
3646 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
3647 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
3648 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
3650 + return xchg(&v->counter, new);
3653 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3657 c = atomic64_read(v);
3659 - if (unlikely(c == (u)))
3660 + if (unlikely(c == u))
3662 - old = atomic64_cmpxchg((v), c, c + (a));
3664 + asm volatile("addcc %2, %0, %0\n"
3666 +#ifdef CONFIG_PAX_REFCOUNT
3671 + : "0" (c), "ir" (a)
3674 + old = atomic64_cmpxchg(v, c, new);
3675 if (likely(old == c))
3683 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3684 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
3685 index 69358b5..17b4745 100644
3686 --- a/arch/sparc/include/asm/cache.h
3687 +++ b/arch/sparc/include/asm/cache.h
3689 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
3691 #define L1_CACHE_SHIFT 5
3692 -#define L1_CACHE_BYTES 32
3693 +#define L1_CACHE_BYTES 32UL
3695 #ifdef CONFIG_SPARC32
3696 #define SMP_CACHE_BYTES_SHIFT 5
3697 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
3698 index 4269ca6..e3da77f 100644
3699 --- a/arch/sparc/include/asm/elf_32.h
3700 +++ b/arch/sparc/include/asm/elf_32.h
3701 @@ -114,6 +114,13 @@ typedef struct {
3703 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3705 +#ifdef CONFIG_PAX_ASLR
3706 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3708 +#define PAX_DELTA_MMAP_LEN 16
3709 +#define PAX_DELTA_STACK_LEN 16
3712 /* This yields a mask that user programs can use to figure out what
3713 instruction set this cpu supports. This can NOT be done in userspace
3715 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
3716 index 7df8b7f..4946269 100644
3717 --- a/arch/sparc/include/asm/elf_64.h
3718 +++ b/arch/sparc/include/asm/elf_64.h
3719 @@ -180,6 +180,13 @@ typedef struct {
3720 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3721 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3723 +#ifdef CONFIG_PAX_ASLR
3724 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3726 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3727 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3730 extern unsigned long sparc64_elf_hwcap;
3731 #define ELF_HWCAP sparc64_elf_hwcap
3733 diff --git a/arch/sparc/include/asm/page_32.h b/arch/sparc/include/asm/page_32.h
3734 index 156707b..aefa786 100644
3735 --- a/arch/sparc/include/asm/page_32.h
3736 +++ b/arch/sparc/include/asm/page_32.h
3738 #ifndef _SPARC_PAGE_H
3739 #define _SPARC_PAGE_H
3741 +#include <linux/const.h>
3743 #define PAGE_SHIFT 12
3745 #ifndef __ASSEMBLY__
3746 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
3747 index a790cc6..091ed94 100644
3748 --- a/arch/sparc/include/asm/pgtable_32.h
3749 +++ b/arch/sparc/include/asm/pgtable_32.h
3750 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3751 BTFIXUPDEF_INT(page_none)
3752 BTFIXUPDEF_INT(page_copy)
3753 BTFIXUPDEF_INT(page_readonly)
3755 +#ifdef CONFIG_PAX_PAGEEXEC
3756 +BTFIXUPDEF_INT(page_shared_noexec)
3757 +BTFIXUPDEF_INT(page_copy_noexec)
3758 +BTFIXUPDEF_INT(page_readonly_noexec)
3761 BTFIXUPDEF_INT(page_kernel)
3763 #define PMD_SHIFT SUN4C_PMD_SHIFT
3764 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
3765 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3766 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3768 +#ifdef CONFIG_PAX_PAGEEXEC
3769 +extern pgprot_t PAGE_SHARED_NOEXEC;
3770 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3771 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3773 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3774 +# define PAGE_COPY_NOEXEC PAGE_COPY
3775 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3778 extern unsigned long page_kernel;
3781 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
3782 index f6ae2b2..b03ffc7 100644
3783 --- a/arch/sparc/include/asm/pgtsrmmu.h
3784 +++ b/arch/sparc/include/asm/pgtsrmmu.h
3785 @@ -115,6 +115,13 @@
3786 SRMMU_EXEC | SRMMU_REF)
3787 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3788 SRMMU_EXEC | SRMMU_REF)
3790 +#ifdef CONFIG_PAX_PAGEEXEC
3791 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3792 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3793 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3796 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3797 SRMMU_DIRTY | SRMMU_REF)
3799 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
3800 index 9689176..63c18ea 100644
3801 --- a/arch/sparc/include/asm/spinlock_64.h
3802 +++ b/arch/sparc/include/asm/spinlock_64.h
3803 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
3805 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3807 -static void inline arch_read_lock(arch_rwlock_t *lock)
3808 +static inline void arch_read_lock(arch_rwlock_t *lock)
3810 unsigned long tmp1, tmp2;
3812 __asm__ __volatile__ (
3813 "1: ldsw [%2], %0\n"
3815 -"4: add %0, 1, %1\n"
3816 +"4: addcc %0, 1, %1\n"
3818 +#ifdef CONFIG_PAX_REFCOUNT
3822 " cas [%2], %0, %1\n"
3824 " bne,pn %%icc, 1b\n"
3825 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
3827 : "=&r" (tmp1), "=&r" (tmp2)
3830 + : "memory", "cc");
3833 -static int inline arch_read_trylock(arch_rwlock_t *lock)
3834 +static inline int arch_read_trylock(arch_rwlock_t *lock)
3838 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3839 "1: ldsw [%2], %0\n"
3840 " brlz,a,pn %0, 2f\n"
3843 +" addcc %0, 1, %1\n"
3845 +#ifdef CONFIG_PAX_REFCOUNT
3849 " cas [%2], %0, %1\n"
3851 " bne,pn %%icc, 1b\n"
3852 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3856 -static void inline arch_read_unlock(arch_rwlock_t *lock)
3857 +static inline void arch_read_unlock(arch_rwlock_t *lock)
3859 unsigned long tmp1, tmp2;
3861 __asm__ __volatile__(
3862 "1: lduw [%2], %0\n"
3864 +" subcc %0, 1, %1\n"
3866 +#ifdef CONFIG_PAX_REFCOUNT
3870 " cas [%2], %0, %1\n"
3872 " bne,pn %%xcc, 1b\n"
3873 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
3877 -static void inline arch_write_lock(arch_rwlock_t *lock)
3878 +static inline void arch_write_lock(arch_rwlock_t *lock)
3880 unsigned long mask, tmp1, tmp2;
3882 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
3886 -static void inline arch_write_unlock(arch_rwlock_t *lock)
3887 +static inline void arch_write_unlock(arch_rwlock_t *lock)
3889 __asm__ __volatile__(
3891 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
3895 -static int inline arch_write_trylock(arch_rwlock_t *lock)
3896 +static inline int arch_write_trylock(arch_rwlock_t *lock)
3898 unsigned long mask, tmp1, tmp2, result;
3900 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
3901 index fa57532..e1a4c53 100644
3902 --- a/arch/sparc/include/asm/thread_info_32.h
3903 +++ b/arch/sparc/include/asm/thread_info_32.h
3904 @@ -50,6 +50,8 @@ struct thread_info {
3905 unsigned long w_saved;
3907 struct restart_block restart_block;
3909 + unsigned long lowest_stack;
3913 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
3914 index 60d86be..952dea1 100644
3915 --- a/arch/sparc/include/asm/thread_info_64.h
3916 +++ b/arch/sparc/include/asm/thread_info_64.h
3917 @@ -63,6 +63,8 @@ struct thread_info {
3918 struct pt_regs *kern_una_regs;
3919 unsigned int kern_una_insn;
3921 + unsigned long lowest_stack;
3923 unsigned long fpregs[0] __attribute__ ((aligned(64)));
3926 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
3927 index e88fbe5..96b0ce5 100644
3928 --- a/arch/sparc/include/asm/uaccess.h
3929 +++ b/arch/sparc/include/asm/uaccess.h
3931 #ifndef ___ASM_SPARC_UACCESS_H
3932 #define ___ASM_SPARC_UACCESS_H
3935 +#ifndef __ASSEMBLY__
3936 +#include <linux/types.h>
3937 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3941 #if defined(__sparc__) && defined(__arch64__)
3942 #include <asm/uaccess_64.h>
3944 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
3945 index 8303ac4..07f333d 100644
3946 --- a/arch/sparc/include/asm/uaccess_32.h
3947 +++ b/arch/sparc/include/asm/uaccess_32.h
3948 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
3950 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3952 - if (n && __access_ok((unsigned long) to, n))
3956 + if (n && __access_ok((unsigned long) to, n)) {
3957 + if (!__builtin_constant_p(n))
3958 + check_object_size(from, n, true);
3959 return __copy_user(to, (__force void __user *) from, n);
3965 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
3970 + if (!__builtin_constant_p(n))
3971 + check_object_size(from, n, true);
3973 return __copy_user(to, (__force void __user *) from, n);
3976 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3978 - if (n && __access_ok((unsigned long) from, n))
3982 + if (n && __access_ok((unsigned long) from, n)) {
3983 + if (!__builtin_constant_p(n))
3984 + check_object_size(to, n, false);
3985 return __copy_user((__force void __user *) to, from, n);
3991 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
3996 return __copy_user((__force void __user *) to, from, n);
3999 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
4000 index 3e1449f..5293a0e 100644
4001 --- a/arch/sparc/include/asm/uaccess_64.h
4002 +++ b/arch/sparc/include/asm/uaccess_64.h
4004 #include <linux/compiler.h>
4005 #include <linux/string.h>
4006 #include <linux/thread_info.h>
4007 +#include <linux/kernel.h>
4008 #include <asm/asi.h>
4009 #include <asm/system.h>
4010 #include <asm/spitfire.h>
4011 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
4012 static inline unsigned long __must_check
4013 copy_from_user(void *to, const void __user *from, unsigned long size)
4015 - unsigned long ret = ___copy_from_user(to, from, size);
4016 + unsigned long ret;
4018 + if ((long)size < 0 || size > INT_MAX)
4021 + if (!__builtin_constant_p(size))
4022 + check_object_size(to, size, false);
4024 + ret = ___copy_from_user(to, from, size);
4026 ret = copy_from_user_fixup(to, from, size);
4028 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
4029 static inline unsigned long __must_check
4030 copy_to_user(void __user *to, const void *from, unsigned long size)
4032 - unsigned long ret = ___copy_to_user(to, from, size);
4033 + unsigned long ret;
4035 + if ((long)size < 0 || size > INT_MAX)
4038 + if (!__builtin_constant_p(size))
4039 + check_object_size(from, size, true);
4041 + ret = ___copy_to_user(to, from, size);
4043 ret = copy_to_user_fixup(to, from, size);
4045 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
4046 index cb85458..e063f17 100644
4047 --- a/arch/sparc/kernel/Makefile
4048 +++ b/arch/sparc/kernel/Makefile
4053 -ccflags-y := -Werror
4054 +#ccflags-y := -Werror
4056 extra-y := head_$(BITS).o
4057 extra-y += init_task.o
4058 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
4059 index f793742..4d880af 100644
4060 --- a/arch/sparc/kernel/process_32.c
4061 +++ b/arch/sparc/kernel/process_32.c
4062 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
4063 rw->ins[4], rw->ins[5],
4066 - printk("%pS\n", (void *) rw->ins[7]);
4067 + printk("%pA\n", (void *) rw->ins[7]);
4068 rw = (struct reg_window32 *) rw->ins[6];
4070 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4071 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
4073 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4074 r->psr, r->pc, r->npc, r->y, print_tainted());
4075 - printk("PC: <%pS>\n", (void *) r->pc);
4076 + printk("PC: <%pA>\n", (void *) r->pc);
4077 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4078 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4079 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4080 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4081 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4082 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4083 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4084 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4086 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4087 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4088 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4089 rw = (struct reg_window32 *) fp;
4091 printk("[%08lx : ", pc);
4092 - printk("%pS ] ", (void *) pc);
4093 + printk("%pA ] ", (void *) pc);
4095 } while (++count < 16);
4097 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
4098 index 3739a06..48b2ff0 100644
4099 --- a/arch/sparc/kernel/process_64.c
4100 +++ b/arch/sparc/kernel/process_64.c
4101 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
4102 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4103 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4104 if (regs->tstate & TSTATE_PRIV)
4105 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4106 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4109 void show_regs(struct pt_regs *regs)
4111 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4112 regs->tpc, regs->tnpc, regs->y, print_tainted());
4113 - printk("TPC: <%pS>\n", (void *) regs->tpc);
4114 + printk("TPC: <%pA>\n", (void *) regs->tpc);
4115 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4116 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4118 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4119 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4120 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4122 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4123 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4124 show_regwindow(regs);
4125 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
4127 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
4128 ((tp && tp->task) ? tp->task->pid : -1));
4130 if (gp->tstate & TSTATE_PRIV) {
4131 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4132 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4136 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
4137 index 42b282f..28ce9f2 100644
4138 --- a/arch/sparc/kernel/sys_sparc_32.c
4139 +++ b/arch/sparc/kernel/sys_sparc_32.c
4140 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4141 if (ARCH_SUN4C && len > 0x20000000)
4144 - addr = TASK_UNMAPPED_BASE;
4145 + addr = current->mm->mmap_base;
4147 if (flags & MAP_SHARED)
4148 addr = COLOUR_ALIGN(addr);
4149 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4151 if (TASK_SIZE - PAGE_SIZE - len < addr)
4153 - if (!vmm || addr + len <= vmm->vm_start)
4154 + if (check_heap_stack_gap(vmm, addr, len))
4157 if (flags & MAP_SHARED)
4158 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
4159 index 441521a..b767073 100644
4160 --- a/arch/sparc/kernel/sys_sparc_64.c
4161 +++ b/arch/sparc/kernel/sys_sparc_64.c
4162 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4163 /* We do not accept a shared mapping if it would violate
4164 * cache aliasing constraints.
4166 - if ((flags & MAP_SHARED) &&
4167 + if ((filp || (flags & MAP_SHARED)) &&
4168 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4171 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4172 if (filp || (flags & MAP_SHARED))
4175 +#ifdef CONFIG_PAX_RANDMMAP
4176 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4181 addr = COLOUR_ALIGN(addr, pgoff);
4182 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4183 addr = PAGE_ALIGN(addr);
4185 vma = find_vma(mm, addr);
4186 - if (task_size - len >= addr &&
4187 - (!vma || addr + len <= vma->vm_start))
4188 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4192 if (len > mm->cached_hole_size) {
4193 - start_addr = addr = mm->free_area_cache;
4194 + start_addr = addr = mm->free_area_cache;
4196 - start_addr = addr = TASK_UNMAPPED_BASE;
4197 + start_addr = addr = mm->mmap_base;
4198 mm->cached_hole_size = 0;
4201 @@ -174,14 +177,14 @@ full_search:
4202 vma = find_vma(mm, VA_EXCLUDE_END);
4204 if (unlikely(task_size < addr)) {
4205 - if (start_addr != TASK_UNMAPPED_BASE) {
4206 - start_addr = addr = TASK_UNMAPPED_BASE;
4207 + if (start_addr != mm->mmap_base) {
4208 + start_addr = addr = mm->mmap_base;
4209 mm->cached_hole_size = 0;
4214 - if (likely(!vma || addr + len <= vma->vm_start)) {
4215 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4217 * Remember the place where we stopped the search:
4219 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4220 /* We do not accept a shared mapping if it would violate
4221 * cache aliasing constraints.
4223 - if ((flags & MAP_SHARED) &&
4224 + if ((filp || (flags & MAP_SHARED)) &&
4225 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4228 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4229 addr = PAGE_ALIGN(addr);
4231 vma = find_vma(mm, addr);
4232 - if (task_size - len >= addr &&
4233 - (!vma || addr + len <= vma->vm_start))
4234 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4238 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4239 /* make sure it can fit in the remaining address space */
4240 if (likely(addr > len)) {
4241 vma = find_vma(mm, addr-len);
4242 - if (!vma || addr <= vma->vm_start) {
4243 + if (check_heap_stack_gap(vma, addr - len, len)) {
4244 /* remember the address as a hint for next time */
4245 return (mm->free_area_cache = addr-len);
4247 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4248 if (unlikely(mm->mmap_base < len))
4251 - addr = mm->mmap_base-len;
4252 - if (do_color_align)
4253 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4254 + addr = mm->mmap_base - len;
4257 + if (do_color_align)
4258 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4260 * Lookup failure means no vma is above this address,
4261 * else if new region fits below vma->vm_start,
4262 * return with success:
4264 vma = find_vma(mm, addr);
4265 - if (likely(!vma || addr+len <= vma->vm_start)) {
4266 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4267 /* remember the address as a hint for next time */
4268 return (mm->free_area_cache = addr);
4270 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4271 mm->cached_hole_size = vma->vm_start - addr;
4273 /* try just below the current vma->vm_start */
4274 - addr = vma->vm_start-len;
4275 - if (do_color_align)
4276 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4277 - } while (likely(len < vma->vm_start));
4278 + addr = skip_heap_stack_gap(vma, len);
4279 + } while (!IS_ERR_VALUE(addr));
4283 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4284 gap == RLIM_INFINITY ||
4285 sysctl_legacy_va_layout) {
4286 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4288 +#ifdef CONFIG_PAX_RANDMMAP
4289 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4290 + mm->mmap_base += mm->delta_mmap;
4293 mm->get_unmapped_area = arch_get_unmapped_area;
4294 mm->unmap_area = arch_unmap_area;
4296 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4297 gap = (task_size / 6 * 5);
4299 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4301 +#ifdef CONFIG_PAX_RANDMMAP
4302 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4303 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4306 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4307 mm->unmap_area = arch_unmap_area_topdown;
4309 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
4310 index 591f20c..0f1b925 100644
4311 --- a/arch/sparc/kernel/traps_32.c
4312 +++ b/arch/sparc/kernel/traps_32.c
4313 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
4314 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
4315 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
4317 +extern void gr_handle_kernel_exploit(void);
4319 void die_if_kernel(char *str, struct pt_regs *regs)
4321 static int die_counter;
4322 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4324 (((unsigned long) rw) >= PAGE_OFFSET) &&
4325 !(((unsigned long) rw) & 0x7)) {
4326 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
4327 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
4328 (void *) rw->ins[7]);
4329 rw = (struct reg_window32 *)rw->ins[6];
4332 printk("Instruction DUMP:");
4333 instruction_dump ((unsigned long *) regs->pc);
4334 - if(regs->psr & PSR_PS)
4335 + if(regs->psr & PSR_PS) {
4336 + gr_handle_kernel_exploit();
4342 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
4343 index 0cbdaa4..438e4c9 100644
4344 --- a/arch/sparc/kernel/traps_64.c
4345 +++ b/arch/sparc/kernel/traps_64.c
4346 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
4348 p->trapstack[i].tstate, p->trapstack[i].tpc,
4349 p->trapstack[i].tnpc, p->trapstack[i].tt);
4350 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4351 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4355 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
4358 if (regs->tstate & TSTATE_PRIV) {
4360 +#ifdef CONFIG_PAX_REFCOUNT
4362 + pax_report_refcount_overflow(regs);
4365 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4366 die_if_kernel(buffer, regs);
4368 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
4369 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4374 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4375 0, lvl, SIGTRAP) == NOTIFY_STOP)
4378 +#ifdef CONFIG_PAX_REFCOUNT
4380 + pax_report_refcount_overflow(regs);
4383 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4385 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4386 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
4387 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4388 printk("%s" "ERROR(%d): ",
4389 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4390 - printk("TPC<%pS>\n", (void *) regs->tpc);
4391 + printk("TPC<%pA>\n", (void *) regs->tpc);
4392 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4393 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4394 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4395 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4397 (type & 0x1) ? 'I' : 'D',
4399 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4400 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4401 panic("Irrecoverable Cheetah+ parity error.");
4404 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4406 (type & 0x1) ? 'I' : 'D',
4408 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4409 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4412 struct sun4v_error_entry {
4413 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
4415 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4417 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4418 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4419 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4420 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4421 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4422 (void *) regs->u_regs[UREG_I7]);
4423 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4424 "pte[%lx] error[%lx]\n",
4425 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
4427 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4429 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4430 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4431 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4432 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4433 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4434 (void *) regs->u_regs[UREG_I7]);
4435 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4436 "pte[%lx] error[%lx]\n",
4437 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4438 fp = (unsigned long)sf->fp + STACK_BIAS;
4441 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4442 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4443 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4444 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
4445 int index = tsk->curr_ret_stack;
4446 if (tsk->ret_stack && index >= graph) {
4447 pc = tsk->ret_stack[index - graph].ret;
4448 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4449 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4453 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
4454 return (struct reg_window *) (fp + STACK_BIAS);
4457 +extern void gr_handle_kernel_exploit(void);
4459 void die_if_kernel(char *str, struct pt_regs *regs)
4461 static int die_counter;
4462 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4465 kstack_valid(tp, (unsigned long) rw)) {
4466 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
4467 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
4468 (void *) rw->ins[7]);
4470 rw = kernel_stack_up(rw);
4471 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4473 user_instruction_dump ((unsigned int __user *) regs->tpc);
4475 - if (regs->tstate & TSTATE_PRIV)
4476 + if (regs->tstate & TSTATE_PRIV) {
4477 + gr_handle_kernel_exploit();
4482 EXPORT_SYMBOL(die_if_kernel);
4483 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
4484 index 76e4ac1..78f8bb1 100644
4485 --- a/arch/sparc/kernel/unaligned_64.c
4486 +++ b/arch/sparc/kernel/unaligned_64.c
4487 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
4488 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
4490 if (__ratelimit(&ratelimit)) {
4491 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
4492 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
4493 regs->tpc, (void *) regs->tpc);
4496 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
4497 index a3fc437..fea9957 100644
4498 --- a/arch/sparc/lib/Makefile
4499 +++ b/arch/sparc/lib/Makefile
4503 asflags-y := -ansi -DST_DIV0=0x02
4504 -ccflags-y := -Werror
4505 +#ccflags-y := -Werror
4507 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4508 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4509 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
4510 index 59186e0..f747d7a 100644
4511 --- a/arch/sparc/lib/atomic_64.S
4512 +++ b/arch/sparc/lib/atomic_64.S
4514 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4518 + addcc %g1, %o0, %g7
4520 +#ifdef CONFIG_PAX_REFCOUNT
4526 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4527 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4528 2: BACKOFF_SPIN(%o2, %o3, 1b)
4529 .size atomic_add, .-atomic_add
4531 + .globl atomic_add_unchecked
4532 + .type atomic_add_unchecked,#function
4533 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4534 + BACKOFF_SETUP(%o2)
4537 + cas [%o1], %g1, %g7
4543 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4544 + .size atomic_add_unchecked, .-atomic_add_unchecked
4547 .type atomic_sub,#function
4548 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4552 + subcc %g1, %o0, %g7
4554 +#ifdef CONFIG_PAX_REFCOUNT
4560 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4561 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4562 2: BACKOFF_SPIN(%o2, %o3, 1b)
4563 .size atomic_sub, .-atomic_sub
4565 + .globl atomic_sub_unchecked
4566 + .type atomic_sub_unchecked,#function
4567 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4568 + BACKOFF_SETUP(%o2)
4571 + cas [%o1], %g1, %g7
4577 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4578 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
4580 .globl atomic_add_ret
4581 .type atomic_add_ret,#function
4582 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4586 + addcc %g1, %o0, %g7
4588 +#ifdef CONFIG_PAX_REFCOUNT
4594 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4595 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4596 2: BACKOFF_SPIN(%o2, %o3, 1b)
4597 .size atomic_add_ret, .-atomic_add_ret
4599 + .globl atomic_add_ret_unchecked
4600 + .type atomic_add_ret_unchecked,#function
4601 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4602 + BACKOFF_SETUP(%o2)
4604 + addcc %g1, %o0, %g7
4605 + cas [%o1], %g1, %g7
4612 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4613 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4615 .globl atomic_sub_ret
4616 .type atomic_sub_ret,#function
4617 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4621 + subcc %g1, %o0, %g7
4623 +#ifdef CONFIG_PAX_REFCOUNT
4629 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4630 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4631 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4635 + addcc %g1, %o0, %g7
4637 +#ifdef CONFIG_PAX_REFCOUNT
4641 casx [%o1], %g1, %g7
4643 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4644 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4645 2: BACKOFF_SPIN(%o2, %o3, 1b)
4646 .size atomic64_add, .-atomic64_add
4648 + .globl atomic64_add_unchecked
4649 + .type atomic64_add_unchecked,#function
4650 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4651 + BACKOFF_SETUP(%o2)
4653 + addcc %g1, %o0, %g7
4654 + casx [%o1], %g1, %g7
4660 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4661 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
4664 .type atomic64_sub,#function
4665 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4669 + subcc %g1, %o0, %g7
4671 +#ifdef CONFIG_PAX_REFCOUNT
4675 casx [%o1], %g1, %g7
4677 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4678 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4679 2: BACKOFF_SPIN(%o2, %o3, 1b)
4680 .size atomic64_sub, .-atomic64_sub
4682 + .globl atomic64_sub_unchecked
4683 + .type atomic64_sub_unchecked,#function
4684 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4685 + BACKOFF_SETUP(%o2)
4687 + subcc %g1, %o0, %g7
4688 + casx [%o1], %g1, %g7
4694 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4695 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4697 .globl atomic64_add_ret
4698 .type atomic64_add_ret,#function
4699 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4703 + addcc %g1, %o0, %g7
4705 +#ifdef CONFIG_PAX_REFCOUNT
4709 casx [%o1], %g1, %g7
4711 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4712 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4713 2: BACKOFF_SPIN(%o2, %o3, 1b)
4714 .size atomic64_add_ret, .-atomic64_add_ret
4716 + .globl atomic64_add_ret_unchecked
4717 + .type atomic64_add_ret_unchecked,#function
4718 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4719 + BACKOFF_SETUP(%o2)
4721 + addcc %g1, %o0, %g7
4722 + casx [%o1], %g1, %g7
4729 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4730 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4732 .globl atomic64_sub_ret
4733 .type atomic64_sub_ret,#function
4734 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4738 + subcc %g1, %o0, %g7
4740 +#ifdef CONFIG_PAX_REFCOUNT
4744 casx [%o1], %g1, %g7
4746 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4747 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
4748 index 1b30bb3..b4a16c7 100644
4749 --- a/arch/sparc/lib/ksyms.c
4750 +++ b/arch/sparc/lib/ksyms.c
4751 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
4753 /* Atomic counter implementation. */
4754 EXPORT_SYMBOL(atomic_add);
4755 +EXPORT_SYMBOL(atomic_add_unchecked);
4756 EXPORT_SYMBOL(atomic_add_ret);
4757 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
4758 EXPORT_SYMBOL(atomic_sub);
4759 +EXPORT_SYMBOL(atomic_sub_unchecked);
4760 EXPORT_SYMBOL(atomic_sub_ret);
4761 EXPORT_SYMBOL(atomic64_add);
4762 +EXPORT_SYMBOL(atomic64_add_unchecked);
4763 EXPORT_SYMBOL(atomic64_add_ret);
4764 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4765 EXPORT_SYMBOL(atomic64_sub);
4766 +EXPORT_SYMBOL(atomic64_sub_unchecked);
4767 EXPORT_SYMBOL(atomic64_sub_ret);
4769 /* Atomic bit operations. */
4770 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
4771 index 301421c..e2535d1 100644
4772 --- a/arch/sparc/mm/Makefile
4773 +++ b/arch/sparc/mm/Makefile
4778 -ccflags-y := -Werror
4779 +#ccflags-y := -Werror
4781 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
4782 obj-y += fault_$(BITS).o
4783 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
4784 index 8023fd7..c8e89e9 100644
4785 --- a/arch/sparc/mm/fault_32.c
4786 +++ b/arch/sparc/mm/fault_32.c
4788 #include <linux/perf_event.h>
4789 #include <linux/interrupt.h>
4790 #include <linux/kdebug.h>
4791 +#include <linux/slab.h>
4792 +#include <linux/pagemap.h>
4793 +#include <linux/compiler.h>
4795 #include <asm/system.h>
4796 #include <asm/page.h>
4797 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
4798 return safe_compute_effective_address(regs, insn);
4801 +#ifdef CONFIG_PAX_PAGEEXEC
4802 +#ifdef CONFIG_PAX_DLRESOLVE
4803 +static void pax_emuplt_close(struct vm_area_struct *vma)
4805 + vma->vm_mm->call_dl_resolve = 0UL;
4808 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4810 + unsigned int *kaddr;
4812 + vmf->page = alloc_page(GFP_HIGHUSER);
4814 + return VM_FAULT_OOM;
4816 + kaddr = kmap(vmf->page);
4817 + memset(kaddr, 0, PAGE_SIZE);
4818 + kaddr[0] = 0x9DE3BFA8U; /* save */
4819 + flush_dcache_page(vmf->page);
4820 + kunmap(vmf->page);
4821 + return VM_FAULT_MAJOR;
4824 +static const struct vm_operations_struct pax_vm_ops = {
4825 + .close = pax_emuplt_close,
4826 + .fault = pax_emuplt_fault
4829 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4833 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4834 + vma->vm_mm = current->mm;
4835 + vma->vm_start = addr;
4836 + vma->vm_end = addr + PAGE_SIZE;
4837 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4838 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4839 + vma->vm_ops = &pax_vm_ops;
4841 + ret = insert_vm_struct(current->mm, vma);
4845 + ++current->mm->total_vm;
4851 + * PaX: decide what to do with offenders (regs->pc = fault address)
4853 + * returns 1 when task should be killed
4854 + * 2 when patched PLT trampoline was detected
4855 + * 3 when unpatched PLT trampoline was detected
4857 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4860 +#ifdef CONFIG_PAX_EMUPLT
4863 + do { /* PaX: patched PLT emulation #1 */
4864 + unsigned int sethi1, sethi2, jmpl;
4866 + err = get_user(sethi1, (unsigned int *)regs->pc);
4867 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4868 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4873 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4874 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
4875 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
4877 + unsigned int addr;
4879 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4880 + addr = regs->u_regs[UREG_G1];
4881 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4883 + regs->npc = addr+4;
4888 + { /* PaX: patched PLT emulation #2 */
4891 + err = get_user(ba, (unsigned int *)regs->pc);
4893 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4894 + unsigned int addr;
4896 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4898 + regs->npc = addr+4;
4903 + do { /* PaX: patched PLT emulation #3 */
4904 + unsigned int sethi, jmpl, nop;
4906 + err = get_user(sethi, (unsigned int *)regs->pc);
4907 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4908 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4913 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4914 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4915 + nop == 0x01000000U)
4917 + unsigned int addr;
4919 + addr = (sethi & 0x003FFFFFU) << 10;
4920 + regs->u_regs[UREG_G1] = addr;
4921 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4923 + regs->npc = addr+4;
4928 + do { /* PaX: unpatched PLT emulation step 1 */
4929 + unsigned int sethi, ba, nop;
4931 + err = get_user(sethi, (unsigned int *)regs->pc);
4932 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
4933 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4938 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4939 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4940 + nop == 0x01000000U)
4942 + unsigned int addr, save, call;
4944 + if ((ba & 0xFFC00000U) == 0x30800000U)
4945 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4947 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4949 + err = get_user(save, (unsigned int *)addr);
4950 + err |= get_user(call, (unsigned int *)(addr+4));
4951 + err |= get_user(nop, (unsigned int *)(addr+8));
4955 +#ifdef CONFIG_PAX_DLRESOLVE
4956 + if (save == 0x9DE3BFA8U &&
4957 + (call & 0xC0000000U) == 0x40000000U &&
4958 + nop == 0x01000000U)
4960 + struct vm_area_struct *vma;
4961 + unsigned long call_dl_resolve;
4963 + down_read(¤t->mm->mmap_sem);
4964 + call_dl_resolve = current->mm->call_dl_resolve;
4965 + up_read(¤t->mm->mmap_sem);
4966 + if (likely(call_dl_resolve))
4969 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4971 + down_write(¤t->mm->mmap_sem);
4972 + if (current->mm->call_dl_resolve) {
4973 + call_dl_resolve = current->mm->call_dl_resolve;
4974 + up_write(¤t->mm->mmap_sem);
4976 + kmem_cache_free(vm_area_cachep, vma);
4980 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4981 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4982 + up_write(¤t->mm->mmap_sem);
4984 + kmem_cache_free(vm_area_cachep, vma);
4988 + if (pax_insert_vma(vma, call_dl_resolve)) {
4989 + up_write(¤t->mm->mmap_sem);
4990 + kmem_cache_free(vm_area_cachep, vma);
4994 + current->mm->call_dl_resolve = call_dl_resolve;
4995 + up_write(¤t->mm->mmap_sem);
4998 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4999 + regs->pc = call_dl_resolve;
5000 + regs->npc = addr+4;
5005 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5006 + if ((save & 0xFFC00000U) == 0x05000000U &&
5007 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5008 + nop == 0x01000000U)
5010 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5011 + regs->u_regs[UREG_G2] = addr + 4;
5012 + addr = (save & 0x003FFFFFU) << 10;
5013 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5015 + regs->npc = addr+4;
5021 + do { /* PaX: unpatched PLT emulation step 2 */
5022 + unsigned int save, call, nop;
5024 + err = get_user(save, (unsigned int *)(regs->pc-4));
5025 + err |= get_user(call, (unsigned int *)regs->pc);
5026 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
5030 + if (save == 0x9DE3BFA8U &&
5031 + (call & 0xC0000000U) == 0x40000000U &&
5032 + nop == 0x01000000U)
5034 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
5036 + regs->u_regs[UREG_RETPC] = regs->pc;
5037 + regs->pc = dl_resolve;
5038 + regs->npc = dl_resolve+4;
5047 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5051 + printk(KERN_ERR "PAX: bytes at PC: ");
5052 + for (i = 0; i < 8; i++) {
5054 + if (get_user(c, (unsigned int *)pc+i))
5055 + printk(KERN_CONT "???????? ");
5057 + printk(KERN_CONT "%08x ", c);
5063 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
5066 @@ -280,6 +545,24 @@ good_area:
5067 if(!(vma->vm_flags & VM_WRITE))
5071 +#ifdef CONFIG_PAX_PAGEEXEC
5072 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5073 + up_read(&mm->mmap_sem);
5074 + switch (pax_handle_fetch_fault(regs)) {
5076 +#ifdef CONFIG_PAX_EMUPLT
5083 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5084 + do_group_exit(SIGKILL);
5088 /* Allow reads even for write-only mappings */
5089 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5091 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
5092 index 504c062..6fcb9c6 100644
5093 --- a/arch/sparc/mm/fault_64.c
5094 +++ b/arch/sparc/mm/fault_64.c
5096 #include <linux/kprobes.h>
5097 #include <linux/kdebug.h>
5098 #include <linux/percpu.h>
5099 +#include <linux/slab.h>
5100 +#include <linux/pagemap.h>
5101 +#include <linux/compiler.h>
5103 #include <asm/page.h>
5104 #include <asm/pgtable.h>
5105 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
5106 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5108 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5109 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5110 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5111 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5113 unhandled_fault(regs->tpc, current, regs);
5114 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
5118 +#ifdef CONFIG_PAX_PAGEEXEC
5119 +#ifdef CONFIG_PAX_DLRESOLVE
5120 +static void pax_emuplt_close(struct vm_area_struct *vma)
5122 + vma->vm_mm->call_dl_resolve = 0UL;
5125 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5127 + unsigned int *kaddr;
5129 + vmf->page = alloc_page(GFP_HIGHUSER);
5131 + return VM_FAULT_OOM;
5133 + kaddr = kmap(vmf->page);
5134 + memset(kaddr, 0, PAGE_SIZE);
5135 + kaddr[0] = 0x9DE3BFA8U; /* save */
5136 + flush_dcache_page(vmf->page);
5137 + kunmap(vmf->page);
5138 + return VM_FAULT_MAJOR;
5141 +static const struct vm_operations_struct pax_vm_ops = {
5142 + .close = pax_emuplt_close,
5143 + .fault = pax_emuplt_fault
5146 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5150 + INIT_LIST_HEAD(&vma->anon_vma_chain);
5151 + vma->vm_mm = current->mm;
5152 + vma->vm_start = addr;
5153 + vma->vm_end = addr + PAGE_SIZE;
5154 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5155 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5156 + vma->vm_ops = &pax_vm_ops;
5158 + ret = insert_vm_struct(current->mm, vma);
5162 + ++current->mm->total_vm;
5168 + * PaX: decide what to do with offenders (regs->tpc = fault address)
5170 + * returns 1 when task should be killed
5171 + * 2 when patched PLT trampoline was detected
5172 + * 3 when unpatched PLT trampoline was detected
5174 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5177 +#ifdef CONFIG_PAX_EMUPLT
5180 + do { /* PaX: patched PLT emulation #1 */
5181 + unsigned int sethi1, sethi2, jmpl;
5183 + err = get_user(sethi1, (unsigned int *)regs->tpc);
5184 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5185 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5190 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5191 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5192 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5194 + unsigned long addr;
5196 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5197 + addr = regs->u_regs[UREG_G1];
5198 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5200 + if (test_thread_flag(TIF_32BIT))
5201 + addr &= 0xFFFFFFFFUL;
5204 + regs->tnpc = addr+4;
5209 + { /* PaX: patched PLT emulation #2 */
5212 + err = get_user(ba, (unsigned int *)regs->tpc);
5214 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5215 + unsigned long addr;
5217 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5219 + if (test_thread_flag(TIF_32BIT))
5220 + addr &= 0xFFFFFFFFUL;
5223 + regs->tnpc = addr+4;
5228 + do { /* PaX: patched PLT emulation #3 */
5229 + unsigned int sethi, jmpl, nop;
5231 + err = get_user(sethi, (unsigned int *)regs->tpc);
5232 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5233 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5238 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5239 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5240 + nop == 0x01000000U)
5242 + unsigned long addr;
5244 + addr = (sethi & 0x003FFFFFU) << 10;
5245 + regs->u_regs[UREG_G1] = addr;
5246 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5248 + if (test_thread_flag(TIF_32BIT))
5249 + addr &= 0xFFFFFFFFUL;
5252 + regs->tnpc = addr+4;
5257 + do { /* PaX: patched PLT emulation #4 */
5258 + unsigned int sethi, mov1, call, mov2;
5260 + err = get_user(sethi, (unsigned int *)regs->tpc);
5261 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5262 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
5263 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5268 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5269 + mov1 == 0x8210000FU &&
5270 + (call & 0xC0000000U) == 0x40000000U &&
5271 + mov2 == 0x9E100001U)
5273 + unsigned long addr;
5275 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5276 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5278 + if (test_thread_flag(TIF_32BIT))
5279 + addr &= 0xFFFFFFFFUL;
5282 + regs->tnpc = addr+4;
5287 + do { /* PaX: patched PLT emulation #5 */
5288 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5290 + err = get_user(sethi, (unsigned int *)regs->tpc);
5291 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5292 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5293 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5294 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5295 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5296 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5297 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5302 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5303 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5304 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5305 + (or1 & 0xFFFFE000U) == 0x82106000U &&
5306 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5307 + sllx == 0x83287020U &&
5308 + jmpl == 0x81C04005U &&
5309 + nop == 0x01000000U)
5311 + unsigned long addr;
5313 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5314 + regs->u_regs[UREG_G1] <<= 32;
5315 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5316 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5318 + regs->tnpc = addr+4;
5323 + do { /* PaX: patched PLT emulation #6 */
5324 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5326 + err = get_user(sethi, (unsigned int *)regs->tpc);
5327 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5328 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5329 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5330 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
5331 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5332 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5337 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5338 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5339 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5340 + sllx == 0x83287020U &&
5341 + (or & 0xFFFFE000U) == 0x8A116000U &&
5342 + jmpl == 0x81C04005U &&
5343 + nop == 0x01000000U)
5345 + unsigned long addr;
5347 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5348 + regs->u_regs[UREG_G1] <<= 32;
5349 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5350 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5352 + regs->tnpc = addr+4;
5357 + do { /* PaX: unpatched PLT emulation step 1 */
5358 + unsigned int sethi, ba, nop;
5360 + err = get_user(sethi, (unsigned int *)regs->tpc);
5361 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5362 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5367 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5368 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5369 + nop == 0x01000000U)
5371 + unsigned long addr;
5372 + unsigned int save, call;
5373 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5375 + if ((ba & 0xFFC00000U) == 0x30800000U)
5376 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5378 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5380 + if (test_thread_flag(TIF_32BIT))
5381 + addr &= 0xFFFFFFFFUL;
5383 + err = get_user(save, (unsigned int *)addr);
5384 + err |= get_user(call, (unsigned int *)(addr+4));
5385 + err |= get_user(nop, (unsigned int *)(addr+8));
5389 +#ifdef CONFIG_PAX_DLRESOLVE
5390 + if (save == 0x9DE3BFA8U &&
5391 + (call & 0xC0000000U) == 0x40000000U &&
5392 + nop == 0x01000000U)
5394 + struct vm_area_struct *vma;
5395 + unsigned long call_dl_resolve;
5397 + down_read(¤t->mm->mmap_sem);
5398 + call_dl_resolve = current->mm->call_dl_resolve;
5399 + up_read(¤t->mm->mmap_sem);
5400 + if (likely(call_dl_resolve))
5403 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5405 + down_write(¤t->mm->mmap_sem);
5406 + if (current->mm->call_dl_resolve) {
5407 + call_dl_resolve = current->mm->call_dl_resolve;
5408 + up_write(¤t->mm->mmap_sem);
5410 + kmem_cache_free(vm_area_cachep, vma);
5414 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5415 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5416 + up_write(¤t->mm->mmap_sem);
5418 + kmem_cache_free(vm_area_cachep, vma);
5422 + if (pax_insert_vma(vma, call_dl_resolve)) {
5423 + up_write(¤t->mm->mmap_sem);
5424 + kmem_cache_free(vm_area_cachep, vma);
5428 + current->mm->call_dl_resolve = call_dl_resolve;
5429 + up_write(¤t->mm->mmap_sem);
5432 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5433 + regs->tpc = call_dl_resolve;
5434 + regs->tnpc = addr+4;
5439 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5440 + if ((save & 0xFFC00000U) == 0x05000000U &&
5441 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5442 + nop == 0x01000000U)
5444 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5445 + regs->u_regs[UREG_G2] = addr + 4;
5446 + addr = (save & 0x003FFFFFU) << 10;
5447 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5449 + if (test_thread_flag(TIF_32BIT))
5450 + addr &= 0xFFFFFFFFUL;
5453 + regs->tnpc = addr+4;
5457 + /* PaX: 64-bit PLT stub */
5458 + err = get_user(sethi1, (unsigned int *)addr);
5459 + err |= get_user(sethi2, (unsigned int *)(addr+4));
5460 + err |= get_user(or1, (unsigned int *)(addr+8));
5461 + err |= get_user(or2, (unsigned int *)(addr+12));
5462 + err |= get_user(sllx, (unsigned int *)(addr+16));
5463 + err |= get_user(add, (unsigned int *)(addr+20));
5464 + err |= get_user(jmpl, (unsigned int *)(addr+24));
5465 + err |= get_user(nop, (unsigned int *)(addr+28));
5469 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5470 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5471 + (or1 & 0xFFFFE000U) == 0x88112000U &&
5472 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5473 + sllx == 0x89293020U &&
5474 + add == 0x8A010005U &&
5475 + jmpl == 0x89C14000U &&
5476 + nop == 0x01000000U)
5478 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5479 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5480 + regs->u_regs[UREG_G4] <<= 32;
5481 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5482 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5483 + regs->u_regs[UREG_G4] = addr + 24;
5484 + addr = regs->u_regs[UREG_G5];
5486 + regs->tnpc = addr+4;
5492 +#ifdef CONFIG_PAX_DLRESOLVE
5493 + do { /* PaX: unpatched PLT emulation step 2 */
5494 + unsigned int save, call, nop;
5496 + err = get_user(save, (unsigned int *)(regs->tpc-4));
5497 + err |= get_user(call, (unsigned int *)regs->tpc);
5498 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5502 + if (save == 0x9DE3BFA8U &&
5503 + (call & 0xC0000000U) == 0x40000000U &&
5504 + nop == 0x01000000U)
5506 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5508 + if (test_thread_flag(TIF_32BIT))
5509 + dl_resolve &= 0xFFFFFFFFUL;
5511 + regs->u_regs[UREG_RETPC] = regs->tpc;
5512 + regs->tpc = dl_resolve;
5513 + regs->tnpc = dl_resolve+4;
5519 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5520 + unsigned int sethi, ba, nop;
5522 + err = get_user(sethi, (unsigned int *)regs->tpc);
5523 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5524 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5529 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5530 + (ba & 0xFFF00000U) == 0x30600000U &&
5531 + nop == 0x01000000U)
5533 + unsigned long addr;
5535 + addr = (sethi & 0x003FFFFFU) << 10;
5536 + regs->u_regs[UREG_G1] = addr;
5537 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5539 + if (test_thread_flag(TIF_32BIT))
5540 + addr &= 0xFFFFFFFFUL;
5543 + regs->tnpc = addr+4;
5553 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5557 + printk(KERN_ERR "PAX: bytes at PC: ");
5558 + for (i = 0; i < 8; i++) {
5560 + if (get_user(c, (unsigned int *)pc+i))
5561 + printk(KERN_CONT "???????? ");
5563 + printk(KERN_CONT "%08x ", c);
5569 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5571 struct mm_struct *mm = current->mm;
5572 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5576 +#ifdef CONFIG_PAX_PAGEEXEC
5577 + /* PaX: detect ITLB misses on non-exec pages */
5578 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5579 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5581 + if (address != regs->tpc)
5584 + up_read(&mm->mmap_sem);
5585 + switch (pax_handle_fetch_fault(regs)) {
5587 +#ifdef CONFIG_PAX_EMUPLT
5594 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5595 + do_group_exit(SIGKILL);
5599 /* Pure DTLB misses do not tell us whether the fault causing
5600 * load/store/atomic was a write or not, it only says that there
5601 * was no match. So in such a case we (carefully) read the
5602 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
5603 index 07e1453..0a7d9e9 100644
5604 --- a/arch/sparc/mm/hugetlbpage.c
5605 +++ b/arch/sparc/mm/hugetlbpage.c
5606 @@ -67,7 +67,7 @@ full_search:
5610 - if (likely(!vma || addr + len <= vma->vm_start)) {
5611 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5613 * Remember the place where we stopped the search:
5615 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5616 /* make sure it can fit in the remaining address space */
5617 if (likely(addr > len)) {
5618 vma = find_vma(mm, addr-len);
5619 - if (!vma || addr <= vma->vm_start) {
5620 + if (check_heap_stack_gap(vma, addr - len, len)) {
5621 /* remember the address as a hint for next time */
5622 return (mm->free_area_cache = addr-len);
5624 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5625 if (unlikely(mm->mmap_base < len))
5628 - addr = (mm->mmap_base-len) & HPAGE_MASK;
5629 + addr = mm->mmap_base - len;
5632 + addr &= HPAGE_MASK;
5634 * Lookup failure means no vma is above this address,
5635 * else if new region fits below vma->vm_start,
5636 * return with success:
5638 vma = find_vma(mm, addr);
5639 - if (likely(!vma || addr+len <= vma->vm_start)) {
5640 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5641 /* remember the address as a hint for next time */
5642 return (mm->free_area_cache = addr);
5644 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5645 mm->cached_hole_size = vma->vm_start - addr;
5647 /* try just below the current vma->vm_start */
5648 - addr = (vma->vm_start-len) & HPAGE_MASK;
5649 - } while (likely(len < vma->vm_start));
5650 + addr = skip_heap_stack_gap(vma, len);
5651 + } while (!IS_ERR_VALUE(addr));
5655 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
5657 addr = ALIGN(addr, HPAGE_SIZE);
5658 vma = find_vma(mm, addr);
5659 - if (task_size - len >= addr &&
5660 - (!vma || addr + len <= vma->vm_start))
5661 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5664 if (mm->get_unmapped_area == arch_get_unmapped_area)
5665 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
5666 index 7b00de6..78239f4 100644
5667 --- a/arch/sparc/mm/init_32.c
5668 +++ b/arch/sparc/mm/init_32.c
5669 @@ -316,6 +316,9 @@ extern void device_scan(void);
5670 pgprot_t PAGE_SHARED __read_mostly;
5671 EXPORT_SYMBOL(PAGE_SHARED);
5673 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5674 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5676 void __init paging_init(void)
5678 switch(sparc_cpu_model) {
5679 @@ -344,17 +347,17 @@ void __init paging_init(void)
5681 /* Initialize the protection map with non-constant, MMU dependent values. */
5682 protection_map[0] = PAGE_NONE;
5683 - protection_map[1] = PAGE_READONLY;
5684 - protection_map[2] = PAGE_COPY;
5685 - protection_map[3] = PAGE_COPY;
5686 + protection_map[1] = PAGE_READONLY_NOEXEC;
5687 + protection_map[2] = PAGE_COPY_NOEXEC;
5688 + protection_map[3] = PAGE_COPY_NOEXEC;
5689 protection_map[4] = PAGE_READONLY;
5690 protection_map[5] = PAGE_READONLY;
5691 protection_map[6] = PAGE_COPY;
5692 protection_map[7] = PAGE_COPY;
5693 protection_map[8] = PAGE_NONE;
5694 - protection_map[9] = PAGE_READONLY;
5695 - protection_map[10] = PAGE_SHARED;
5696 - protection_map[11] = PAGE_SHARED;
5697 + protection_map[9] = PAGE_READONLY_NOEXEC;
5698 + protection_map[10] = PAGE_SHARED_NOEXEC;
5699 + protection_map[11] = PAGE_SHARED_NOEXEC;
5700 protection_map[12] = PAGE_READONLY;
5701 protection_map[13] = PAGE_READONLY;
5702 protection_map[14] = PAGE_SHARED;
5703 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
5704 index cbef74e..c38fead 100644
5705 --- a/arch/sparc/mm/srmmu.c
5706 +++ b/arch/sparc/mm/srmmu.c
5707 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5708 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5709 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5710 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5712 +#ifdef CONFIG_PAX_PAGEEXEC
5713 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5714 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5715 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5718 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5719 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5721 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
5722 index 27fe667..36d474c 100644
5723 --- a/arch/tile/include/asm/atomic_64.h
5724 +++ b/arch/tile/include/asm/atomic_64.h
5725 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5727 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5729 +#define atomic64_read_unchecked(v) atomic64_read(v)
5730 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5731 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5732 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5733 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5734 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5735 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5736 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5737 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5739 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
5740 #define smp_mb__before_atomic_dec() smp_mb()
5741 #define smp_mb__after_atomic_dec() smp_mb()
5742 diff --git a/arch/um/Makefile b/arch/um/Makefile
5743 index 7730af6..cce5b19 100644
5744 --- a/arch/um/Makefile
5745 +++ b/arch/um/Makefile
5746 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
5747 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
5748 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
5750 +ifdef CONSTIFY_PLUGIN
5751 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5754 #This will adjust *FLAGS accordingly to the platform.
5755 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
5757 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
5758 index 6c03acd..a5e0215 100644
5759 --- a/arch/um/include/asm/kmap_types.h
5760 +++ b/arch/um/include/asm/kmap_types.h
5761 @@ -23,6 +23,7 @@ enum km_type {
5769 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
5770 index 7cfc3ce..cbd1a58 100644
5771 --- a/arch/um/include/asm/page.h
5772 +++ b/arch/um/include/asm/page.h
5774 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5775 #define PAGE_MASK (~(PAGE_SIZE-1))
5777 +#define ktla_ktva(addr) (addr)
5778 +#define ktva_ktla(addr) (addr)
5780 #ifndef __ASSEMBLY__
5783 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
5784 index c533835..84db18e 100644
5785 --- a/arch/um/kernel/process.c
5786 +++ b/arch/um/kernel/process.c
5787 @@ -406,22 +406,6 @@ int singlestepping(void * t)
5792 - * Only x86 and x86_64 have an arch_align_stack().
5793 - * All other arches have "#define arch_align_stack(x) (x)"
5794 - * in their asm/system.h
5795 - * As this is included in UML from asm-um/system-generic.h,
5796 - * we can use it to behave as the subarch does.
5798 -#ifndef arch_align_stack
5799 -unsigned long arch_align_stack(unsigned long sp)
5801 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5802 - sp -= get_random_int() % 8192;
5807 unsigned long get_wchan(struct task_struct *p)
5809 unsigned long stack_page, sp, ip;
5810 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
5811 index efb4294..61bc18c 100644
5812 --- a/arch/x86/Kconfig
5813 +++ b/arch/x86/Kconfig
5814 @@ -235,7 +235,7 @@ config X86_HT
5816 config X86_32_LAZY_GS
5818 - depends on X86_32 && !CC_STACKPROTECTOR
5819 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
5821 config ARCH_HWEIGHT_CFLAGS
5823 @@ -1022,7 +1022,7 @@ choice
5827 - depends on !X86_NUMAQ
5828 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5830 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
5831 However, the address space of 32-bit x86 processors is only 4
5832 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
5836 - depends on !X86_NUMAQ
5837 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5839 Select this if you have a 32-bit processor and between 1 and 4
5840 gigabytes of physical RAM.
5841 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
5843 default 0xB0000000 if VMSPLIT_3G_OPT
5844 default 0x80000000 if VMSPLIT_2G
5845 - default 0x78000000 if VMSPLIT_2G_OPT
5846 + default 0x70000000 if VMSPLIT_2G_OPT
5847 default 0x40000000 if VMSPLIT_1G
5850 @@ -1496,6 +1496,7 @@ config SECCOMP
5852 config CC_STACKPROTECTOR
5853 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
5854 + depends on X86_64 || !PAX_MEMORY_UDEREF
5856 This option turns on the -fstack-protector GCC feature. This
5857 feature puts, at the beginning of functions, a canary value on
5858 @@ -1553,6 +1554,7 @@ config KEXEC_JUMP
5859 config PHYSICAL_START
5860 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
5862 + range 0x400000 0x40000000
5864 This gives the physical address where the kernel is loaded.
5866 @@ -1616,6 +1618,7 @@ config X86_NEED_RELOCS
5867 config PHYSICAL_ALIGN
5868 hex "Alignment value to which kernel should be aligned" if X86_32
5870 + range 0x400000 0x1000000 if PAX_KERNEXEC
5871 range 0x2000 0x1000000
5873 This value puts the alignment restrictions on physical address
5874 @@ -1647,9 +1650,10 @@ config HOTPLUG_CPU
5875 Say N if you want to disable CPU hotplug.
5880 prompt "Compat VDSO support"
5881 depends on X86_32 || IA32_EMULATION
5882 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
5884 Map the 32-bit VDSO to the predictable old-style address too.
5886 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
5887 index e3ca7e0..b30b28a 100644
5888 --- a/arch/x86/Kconfig.cpu
5889 +++ b/arch/x86/Kconfig.cpu
5890 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
5894 - depends on M586MMX || M586TSC || M586 || M486 || M386
5895 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
5899 @@ -365,7 +365,7 @@ config X86_POPAD_OK
5901 config X86_ALIGNMENT_16
5903 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5904 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5906 config X86_INTEL_USERCOPY
5908 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
5912 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5913 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5915 config X86_MINIMUM_CPU_FAMILY
5917 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
5918 index bf56e17..05f9891 100644
5919 --- a/arch/x86/Kconfig.debug
5920 +++ b/arch/x86/Kconfig.debug
5921 @@ -81,7 +81,7 @@ config X86_PTDUMP
5923 bool "Write protect kernel read-only data structures"
5925 - depends on DEBUG_KERNEL
5926 + depends on DEBUG_KERNEL && BROKEN
5928 Mark the kernel read-only data as write-protected in the pagetables,
5929 in order to catch accidental (and incorrect) writes to such const
5930 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
5932 config DEBUG_SET_MODULE_RONX
5933 bool "Set loadable kernel module data as NX and text as RO"
5934 - depends on MODULES
5935 + depends on MODULES && BROKEN
5937 This option helps catch unintended modifications to loadable
5938 kernel module's text and read-only data. It also prevents execution
5939 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
5940 index b02e509..2631e48 100644
5941 --- a/arch/x86/Makefile
5942 +++ b/arch/x86/Makefile
5943 @@ -46,6 +46,7 @@ else
5944 UTS_MACHINE := x86_64
5945 CHECKFLAGS += -D__x86_64__ -m64
5947 + biarch := $(call cc-option,-m64)
5948 KBUILD_AFLAGS += -m64
5949 KBUILD_CFLAGS += -m64
5951 @@ -195,3 +196,12 @@ define archhelp
5952 echo ' FDARGS="..." arguments for the booted kernel'
5953 echo ' FDINITRD=file initrd for the booted kernel'
5958 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
5959 +*** Please upgrade your binutils to 2.18 or newer
5963 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
5964 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
5965 index 95365a8..52f857b 100644
5966 --- a/arch/x86/boot/Makefile
5967 +++ b/arch/x86/boot/Makefile
5968 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
5969 $(call cc-option, -fno-stack-protector) \
5970 $(call cc-option, -mpreferred-stack-boundary=2)
5971 KBUILD_CFLAGS += $(call cc-option, -m32)
5972 +ifdef CONSTIFY_PLUGIN
5973 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5975 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5978 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
5979 index 878e4b9..20537ab 100644
5980 --- a/arch/x86/boot/bitops.h
5981 +++ b/arch/x86/boot/bitops.h
5982 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5984 const u32 *p = (const u32 *)addr;
5986 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5987 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5991 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5993 static inline void set_bit(int nr, void *addr)
5995 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5996 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5999 #endif /* BOOT_BITOPS_H */
6000 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
6001 index c7093bd..d4247ffe0 100644
6002 --- a/arch/x86/boot/boot.h
6003 +++ b/arch/x86/boot/boot.h
6004 @@ -85,7 +85,7 @@ static inline void io_delay(void)
6005 static inline u16 ds(void)
6008 - asm("movw %%ds,%0" : "=rm" (seg));
6009 + asm volatile("movw %%ds,%0" : "=rm" (seg));
6013 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
6014 static inline int memcmp(const void *s1, const void *s2, size_t len)
6017 - asm("repe; cmpsb; setnz %0"
6018 + asm volatile("repe; cmpsb; setnz %0"
6019 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
6022 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
6023 index 09664ef..edc5d03 100644
6024 --- a/arch/x86/boot/compressed/Makefile
6025 +++ b/arch/x86/boot/compressed/Makefile
6026 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
6027 KBUILD_CFLAGS += $(cflags-y)
6028 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
6029 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
6030 +ifdef CONSTIFY_PLUGIN
6031 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6034 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
6036 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
6037 index 67a655a..b924059 100644
6038 --- a/arch/x86/boot/compressed/head_32.S
6039 +++ b/arch/x86/boot/compressed/head_32.S
6040 @@ -76,7 +76,7 @@ ENTRY(startup_32)
6044 - movl $LOAD_PHYSICAL_ADDR, %ebx
6045 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6048 /* Target address to relocate to for decompression */
6049 @@ -162,7 +162,7 @@ relocated:
6050 * and where it was actually loaded.
6053 - subl $LOAD_PHYSICAL_ADDR, %ebx
6054 + subl $____LOAD_PHYSICAL_ADDR, %ebx
6055 jz 2f /* Nothing to be done if loaded at compiled addr. */
6057 * Process relocations.
6058 @@ -170,8 +170,7 @@ relocated:
6065 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
6068 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
6069 index 35af09d..99c9676 100644
6070 --- a/arch/x86/boot/compressed/head_64.S
6071 +++ b/arch/x86/boot/compressed/head_64.S
6072 @@ -91,7 +91,7 @@ ENTRY(startup_32)
6076 - movl $LOAD_PHYSICAL_ADDR, %ebx
6077 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6080 /* Target address to relocate to for decompression */
6081 @@ -233,7 +233,7 @@ ENTRY(startup_64)
6085 - movq $LOAD_PHYSICAL_ADDR, %rbp
6086 + movq $____LOAD_PHYSICAL_ADDR, %rbp
6089 /* Target address to relocate to for decompression */
6090 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
6091 index 3a19d04..7c1d55a 100644
6092 --- a/arch/x86/boot/compressed/misc.c
6093 +++ b/arch/x86/boot/compressed/misc.c
6094 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
6096 #ifdef CONFIG_RELOCATABLE
6098 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6099 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6101 dest = (void *)(phdr->p_paddr);
6103 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
6104 error("Destination address too large");
6106 #ifndef CONFIG_RELOCATABLE
6107 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
6108 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
6109 error("Wrong destination address");
6112 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
6113 index 89bbf4e..869908e 100644
6114 --- a/arch/x86/boot/compressed/relocs.c
6115 +++ b/arch/x86/boot/compressed/relocs.c
6118 static void die(char *fmt, ...);
6120 +#include "../../../../include/generated/autoconf.h"
6122 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
6123 static Elf32_Ehdr ehdr;
6124 +static Elf32_Phdr *phdr;
6125 static unsigned long reloc_count, reloc_idx;
6126 static unsigned long *relocs;
6128 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
6132 +static void read_phdrs(FILE *fp)
6136 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6138 + die("Unable to allocate %d program headers\n",
6141 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6142 + die("Seek to %d failed: %s\n",
6143 + ehdr.e_phoff, strerror(errno));
6145 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6146 + die("Cannot read ELF program headers: %s\n",
6149 + for(i = 0; i < ehdr.e_phnum; i++) {
6150 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
6151 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
6152 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
6153 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
6154 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
6155 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
6156 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
6157 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
6162 static void read_shdrs(FILE *fp)
6168 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6169 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
6171 static void read_strtabs(FILE *fp)
6175 for (i = 0; i < ehdr.e_shnum; i++) {
6176 struct section *sec = &secs[i];
6177 if (sec->shdr.sh_type != SHT_STRTAB) {
6178 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
6180 static void read_symtabs(FILE *fp)
6184 for (i = 0; i < ehdr.e_shnum; i++) {
6185 struct section *sec = &secs[i];
6186 if (sec->shdr.sh_type != SHT_SYMTAB) {
6187 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
6189 static void read_relocs(FILE *fp)
6195 for (i = 0; i < ehdr.e_shnum; i++) {
6196 struct section *sec = &secs[i];
6197 if (sec->shdr.sh_type != SHT_REL) {
6198 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
6199 die("Cannot read symbol table: %s\n",
6203 + for (j = 0; j < ehdr.e_phnum; j++) {
6204 + if (phdr[j].p_type != PT_LOAD )
6206 + 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)
6208 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6211 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6212 Elf32_Rel *rel = &sec->reltab[j];
6213 - rel->r_offset = elf32_to_cpu(rel->r_offset);
6214 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6215 rel->r_info = elf32_to_cpu(rel->r_info);
6218 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
6220 static void print_absolute_symbols(void)
6224 printf("Absolute symbols\n");
6225 printf(" Num: Value Size Type Bind Visibility Name\n");
6226 for (i = 0; i < ehdr.e_shnum; i++) {
6227 struct section *sec = &secs[i];
6229 Elf32_Sym *sh_symtab;
6233 if (sec->shdr.sh_type != SHT_SYMTAB) {
6235 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
6237 static void print_absolute_relocs(void)
6239 - int i, printed = 0;
6240 + unsigned int i, printed = 0;
6242 for (i = 0; i < ehdr.e_shnum; i++) {
6243 struct section *sec = &secs[i];
6244 struct section *sec_applies, *sec_symtab;
6246 Elf32_Sym *sh_symtab;
6249 if (sec->shdr.sh_type != SHT_REL) {
6252 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
6254 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6258 /* Walk through the relocations */
6259 for (i = 0; i < ehdr.e_shnum; i++) {
6261 Elf32_Sym *sh_symtab;
6262 struct section *sec_applies, *sec_symtab;
6265 struct section *sec = &secs[i];
6267 if (sec->shdr.sh_type != SHT_REL) {
6268 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6269 !is_rel_reloc(sym_name(sym_strtab, sym))) {
6272 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6273 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6276 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6277 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6278 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6280 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6282 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6284 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6291 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
6293 static void emit_relocs(int as_text)
6297 /* Count how many relocations I have and allocate space for them. */
6299 walk_relocs(count_reloc);
6300 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
6301 fname, strerror(errno));
6308 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
6309 index 4d3ff03..e4972ff 100644
6310 --- a/arch/x86/boot/cpucheck.c
6311 +++ b/arch/x86/boot/cpucheck.c
6312 @@ -74,7 +74,7 @@ static int has_fpu(void)
6313 u16 fcw = -1, fsw = -1;
6316 - asm("movl %%cr0,%0" : "=r" (cr0));
6317 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
6318 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6319 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6320 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6321 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6326 + asm volatile("pushfl ; "
6330 @@ -115,7 +115,7 @@ static void get_flags(void)
6331 set_bit(X86_FEATURE_FPU, cpu.flags);
6333 if (has_eflag(X86_EFLAGS_ID)) {
6335 + asm volatile("cpuid"
6336 : "=a" (max_intel_level),
6337 "=b" (cpu_vendor[0]),
6338 "=d" (cpu_vendor[1]),
6339 @@ -124,7 +124,7 @@ static void get_flags(void)
6341 if (max_intel_level >= 0x00000001 &&
6342 max_intel_level <= 0x0000ffff) {
6344 + asm volatile("cpuid"
6346 "=c" (cpu.flags[4]),
6348 @@ -136,7 +136,7 @@ static void get_flags(void)
6349 cpu.model += ((tfms >> 16) & 0xf) << 4;
6353 + asm volatile("cpuid"
6354 : "=a" (max_amd_level)
6356 : "ebx", "ecx", "edx");
6357 @@ -144,7 +144,7 @@ static void get_flags(void)
6358 if (max_amd_level >= 0x80000001 &&
6359 max_amd_level <= 0x8000ffff) {
6360 u32 eax = 0x80000001;
6362 + asm volatile("cpuid"
6364 "=c" (cpu.flags[6]),
6366 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6367 u32 ecx = MSR_K7_HWCR;
6370 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6371 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6373 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6374 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6376 get_flags(); /* Make sure it really did something */
6377 err = check_flags();
6378 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6379 u32 ecx = MSR_VIA_FCR;
6382 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6383 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6384 eax |= (1<<1)|(1<<7);
6385 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6386 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6388 set_bit(X86_FEATURE_CX8, cpu.flags);
6389 err = check_flags();
6390 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6394 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6395 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6397 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6398 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6399 + asm volatile("cpuid"
6400 : "+a" (level), "=d" (cpu.flags[0])
6402 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6403 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6405 err = check_flags();
6407 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
6408 index bdb4d45..0476680 100644
6409 --- a/arch/x86/boot/header.S
6410 +++ b/arch/x86/boot/header.S
6411 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
6412 # single linked list of
6415 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6416 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6418 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6419 #define VO_INIT_SIZE (VO__end - VO__text)
6420 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
6421 index db75d07..8e6d0af 100644
6422 --- a/arch/x86/boot/memory.c
6423 +++ b/arch/x86/boot/memory.c
6426 static int detect_memory_e820(void)
6429 + unsigned int count = 0;
6430 struct biosregs ireg, oreg;
6431 struct e820entry *desc = boot_params.e820_map;
6432 static struct e820entry buf; /* static so it is zeroed */
6433 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
6434 index 11e8c6e..fdbb1ed 100644
6435 --- a/arch/x86/boot/video-vesa.c
6436 +++ b/arch/x86/boot/video-vesa.c
6437 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6439 boot_params.screen_info.vesapm_seg = oreg.es;
6440 boot_params.screen_info.vesapm_off = oreg.di;
6441 + boot_params.screen_info.vesapm_size = oreg.cx;
6445 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
6446 index 43eda28..5ab5fdb 100644
6447 --- a/arch/x86/boot/video.c
6448 +++ b/arch/x86/boot/video.c
6449 @@ -96,7 +96,7 @@ static void store_mode_params(void)
6450 static unsigned int get_entry(void)
6454 + unsigned int i, len = 0;
6458 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
6459 index 5b577d5..3c1fed4 100644
6460 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
6461 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
6463 * including this sentence is retained in full.
6466 +#include <asm/alternative-asm.h>
6468 .extern crypto_ft_tab
6469 .extern crypto_it_tab
6470 .extern crypto_fl_tab
6471 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
6475 +#define ret pax_force_retaddr 0, 1; ret
6477 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
6480 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
6481 index be6d9e3..21fbbca 100644
6482 --- a/arch/x86/crypto/aesni-intel_asm.S
6483 +++ b/arch/x86/crypto/aesni-intel_asm.S
6486 #include <linux/linkage.h>
6487 #include <asm/inst.h>
6488 +#include <asm/alternative-asm.h>
6492 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
6496 + pax_force_retaddr 0, 1
6498 +ENDPROC(aesni_gcm_dec)
6501 /*****************************************************************************
6502 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
6506 + pax_force_retaddr 0, 1
6508 +ENDPROC(aesni_gcm_enc)
6512 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
6514 movaps %xmm0, (TKEYP)
6516 + pax_force_retaddr_bts
6520 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
6521 shufps $0b01001110, %xmm2, %xmm1
6522 movaps %xmm1, 0x10(TKEYP)
6524 + pax_force_retaddr_bts
6528 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
6530 movaps %xmm0, (TKEYP)
6532 + pax_force_retaddr_bts
6536 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
6538 movaps %xmm2, (TKEYP)
6540 + pax_force_retaddr_bts
6544 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
6548 + pax_force_retaddr 0, 1
6550 +ENDPROC(aesni_set_key)
6553 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
6554 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
6558 + pax_force_retaddr 0, 1
6563 * _aesni_enc1: internal ABI
6564 @@ -1959,6 +1972,7 @@ _aesni_enc1:
6566 movaps 0x70(TKEYP), KEY
6567 AESENCLAST KEY STATE
6568 + pax_force_retaddr_bts
6572 @@ -2067,6 +2081,7 @@ _aesni_enc4:
6573 AESENCLAST KEY STATE2
6574 AESENCLAST KEY STATE3
6575 AESENCLAST KEY STATE4
6576 + pax_force_retaddr_bts
6580 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
6584 + pax_force_retaddr 0, 1
6589 * _aesni_dec1: internal ABI
6590 @@ -2146,6 +2163,7 @@ _aesni_dec1:
6592 movaps 0x70(TKEYP), KEY
6593 AESDECLAST KEY STATE
6594 + pax_force_retaddr_bts
6598 @@ -2254,6 +2272,7 @@ _aesni_dec4:
6599 AESDECLAST KEY STATE2
6600 AESDECLAST KEY STATE3
6601 AESDECLAST KEY STATE4
6602 + pax_force_retaddr_bts
6606 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
6610 + pax_force_retaddr 0, 1
6612 +ENDPROC(aesni_ecb_enc)
6615 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6616 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
6620 + pax_force_retaddr 0, 1
6622 +ENDPROC(aesni_ecb_dec)
6625 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6626 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
6630 + pax_force_retaddr 0, 1
6632 +ENDPROC(aesni_cbc_enc)
6635 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6636 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
6640 + pax_force_retaddr 0, 1
6642 +ENDPROC(aesni_cbc_dec)
6646 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
6648 MOVQ_R64_XMM TCTR_LOW INC
6649 MOVQ_R64_XMM CTR TCTR_LOW
6650 + pax_force_retaddr_bts
6654 @@ -2552,6 +2580,7 @@ _aesni_inc:
6657 PSHUFB_XMM BSWAP_MASK IV
6658 + pax_force_retaddr_bts
6662 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
6666 + pax_force_retaddr 0, 1
6668 +ENDPROC(aesni_ctr_enc)
6670 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
6671 index 391d245..67f35c2 100644
6672 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
6673 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
6678 +#include <asm/alternative-asm.h>
6680 .file "blowfish-x86_64-asm.S"
6683 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
6687 + pax_force_retaddr 0, 1
6691 + pax_force_retaddr 0, 1
6695 @@ -188,6 +192,7 @@ blowfish_dec_blk:
6699 + pax_force_retaddr 0, 1
6702 /**********************************************************************
6703 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
6707 + pax_force_retaddr 0, 1
6711 @@ -349,6 +355,7 @@ __enc_xor4:
6715 + pax_force_retaddr 0, 1
6719 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
6723 + pax_force_retaddr 0, 1
6726 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6727 index 6214a9b..1f4fc9a 100644
6728 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
6729 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6731 +#include <asm/alternative-asm.h>
6733 # enter ECRYPT_encrypt_bytes
6736 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
6740 + pax_force_retaddr 0, 1
6744 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
6750 # enter ECRYPT_ivsetup
6752 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
6758 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
6759 index b2c2f57..8470cab 100644
6760 --- a/arch/x86/crypto/sha1_ssse3_asm.S
6761 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
6763 * (at your option) any later version.
6766 +#include <asm/alternative-asm.h>
6768 #define CTX %rdi // arg1
6769 #define BUF %rsi // arg2
6770 #define CNT %rdx // arg3
6775 + pax_force_retaddr 0, 1
6778 .size \name, .-\name
6779 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6780 index 5b012a2..36d5364 100644
6781 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6782 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6787 +#include <asm/alternative-asm.h>
6789 .file "twofish-x86_64-asm-3way.S"
6792 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
6796 + pax_force_retaddr 0, 1
6800 @@ -271,6 +274,7 @@ __enc_xor3:
6804 + pax_force_retaddr 0, 1
6807 .global twofish_dec_blk_3way
6808 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
6812 + pax_force_retaddr 0, 1
6815 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
6816 index 7bcf3fc..f53832f 100644
6817 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
6818 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
6822 #include <asm/asm-offsets.h>
6823 +#include <asm/alternative-asm.h>
6827 @@ -268,6 +269,7 @@ twofish_enc_blk:
6831 + pax_force_retaddr 0, 1
6835 @@ -319,4 +321,5 @@ twofish_dec_blk:
6839 + pax_force_retaddr 0, 1
6841 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
6842 index fd84387..887aa7e 100644
6843 --- a/arch/x86/ia32/ia32_aout.c
6844 +++ b/arch/x86/ia32/ia32_aout.c
6845 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
6846 unsigned long dump_start, dump_size;
6849 + memset(&dump, 0, sizeof(dump));
6854 @@ -315,6 +317,13 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)
6855 current->mm->free_area_cache = TASK_UNMAPPED_BASE;
6856 current->mm->cached_hole_size = 0;
6858 + retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
6860 + /* Someone check-me: is this error path enough? */
6861 + send_sig(SIGKILL, current, 0);
6865 install_exec_creds(bprm);
6866 current->flags &= ~PF_FORKNOEXEC;
6868 @@ -410,13 +419,6 @@ beyond_if:
6870 set_brk(current->mm->start_brk, current->mm->brk);
6872 - retval = setup_arg_pages(bprm, IA32_STACK_TOP, EXSTACK_DEFAULT);
6874 - /* Someone check-me: is this error path enough? */
6875 - send_sig(SIGKILL, current, 0);
6879 current->mm->start_stack =
6880 (unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
6882 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
6883 index 6557769..ef6ae89 100644
6884 --- a/arch/x86/ia32/ia32_signal.c
6885 +++ b/arch/x86/ia32/ia32_signal.c
6886 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
6890 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
6891 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
6893 if (ret >= 0 && uoss_ptr) {
6894 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
6895 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
6897 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6900 + void __user **fpstate)
6904 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6907 sp = sp - sig_xstate_ia32_size;
6908 - *fpstate = (struct _fpstate_ia32 *) sp;
6909 + *fpstate = (struct _fpstate_ia32 __user *) sp;
6910 if (save_i387_xstate_ia32(*fpstate) < 0)
6911 return (void __user *) -1L;
6913 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6915 /* Align the stack pointer according to the i386 ABI,
6916 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6917 - sp = ((sp + 4) & -16ul) - 4;
6918 + sp = ((sp - 12) & -16ul) - 4;
6919 return (void __user *) sp;
6922 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
6923 * These are actually not used anymore, but left because some
6924 * gdb versions depend on them as a marker.
6926 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6927 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6928 } put_user_catch(err);
6931 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6933 __NR_ia32_rt_sigreturn,
6939 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6940 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6942 if (ka->sa.sa_flags & SA_RESTORER)
6943 restorer = ka->sa.sa_restorer;
6944 + else if (current->mm->context.vdso)
6945 + /* Return stub is in 32bit vsyscall page */
6946 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6948 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6950 + restorer = &frame->retcode;
6951 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6954 * Not actually used anymore, but left because some gdb
6957 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6958 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6959 } put_user_catch(err);
6962 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
6963 index a6253ec..4ad2120 100644
6964 --- a/arch/x86/ia32/ia32entry.S
6965 +++ b/arch/x86/ia32/ia32entry.S
6967 #include <asm/thread_info.h>
6968 #include <asm/segment.h>
6969 #include <asm/irqflags.h>
6970 +#include <asm/pgtable.h>
6971 #include <linux/linkage.h>
6972 +#include <asm/alternative-asm.h>
6974 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6975 #include <linux/elf-em.h>
6976 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
6977 ENDPROC(native_irq_enable_sysexit)
6980 + .macro pax_enter_kernel_user
6982 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6983 + call pax_enter_kernel_user
6987 + .macro pax_exit_kernel_user
6988 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6989 + call pax_exit_kernel_user
6991 +#ifdef CONFIG_PAX_RANDKSTACK
6994 + call pax_randomize_kstack
7000 +.macro pax_erase_kstack
7001 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7002 + call pax_erase_kstack
7007 * 32bit SYSENTER instruction entry.
7009 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
7010 CFI_REGISTER rsp,rbp
7012 movq PER_CPU_VAR(kernel_stack), %rsp
7013 - addq $(KERNEL_STACK_OFFSET),%rsp
7015 - * No need to follow this irqs on/off section: the syscall
7016 - * disabled irqs, here we enable it straight after entry:
7018 - ENABLE_INTERRUPTS(CLBR_NONE)
7019 movl %ebp,%ebp /* zero extension */
7020 pushq_cfi $__USER32_DS
7021 /*CFI_REL_OFFSET ss,0*/
7022 @@ -134,25 +156,39 @@ ENTRY(ia32_sysenter_target)
7023 CFI_REL_OFFSET rsp,0
7025 /*CFI_REL_OFFSET rflags,0*/
7026 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
7027 - CFI_REGISTER rip,r10
7028 + orl $X86_EFLAGS_IF,(%rsp)
7029 + GET_THREAD_INFO(%r11)
7030 + movl TI_sysenter_return(%r11), %r11d
7031 + CFI_REGISTER rip,r11
7032 pushq_cfi $__USER32_CS
7033 /*CFI_REL_OFFSET cs,0*/
7037 CFI_REL_OFFSET rip,0
7041 + pax_enter_kernel_user
7043 + * No need to follow this irqs on/off section: the syscall
7044 + * disabled irqs, here we enable it straight after entry:
7046 + ENABLE_INTERRUPTS(CLBR_NONE)
7047 /* no need to do an access_ok check here because rbp has been
7048 32bit zero extended */
7050 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7051 + mov $PAX_USER_SHADOW_BASE,%r11
7056 .section __ex_table,"a"
7057 .quad 1b,ia32_badarg
7059 - GET_THREAD_INFO(%r10)
7060 - orl $TS_COMPAT,TI_status(%r10)
7061 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7062 + GET_THREAD_INFO(%r11)
7063 + orl $TS_COMPAT,TI_status(%r11)
7064 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7066 jnz sysenter_tracesys
7067 cmpq $(IA32_NR_syscalls-1),%rax
7068 @@ -162,13 +198,15 @@ sysenter_do_call:
7070 call *ia32_sys_call_table(,%rax,8)
7071 movq %rax,RAX-ARGOFFSET(%rsp)
7072 - GET_THREAD_INFO(%r10)
7073 + GET_THREAD_INFO(%r11)
7074 DISABLE_INTERRUPTS(CLBR_NONE)
7076 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7077 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
7079 sysexit_from_sys_call:
7080 - andl $~TS_COMPAT,TI_status(%r10)
7081 + pax_exit_kernel_user
7083 + andl $~TS_COMPAT,TI_status(%r11)
7084 /* clear IF, that popfq doesn't enable interrupts early */
7085 andl $~0x200,EFLAGS-R11(%rsp)
7086 movl RIP-R11(%rsp),%edx /* User %eip */
7087 @@ -194,6 +232,9 @@ sysexit_from_sys_call:
7088 movl %eax,%esi /* 2nd arg: syscall number */
7089 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
7090 call audit_syscall_entry
7094 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
7095 cmpq $(IA32_NR_syscalls-1),%rax
7097 @@ -205,7 +246,7 @@ sysexit_from_sys_call:
7100 .macro auditsys_exit exit
7101 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7102 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7103 jnz ia32_ret_from_sys_call
7106 @@ -215,12 +256,12 @@ sysexit_from_sys_call:
7107 movzbl %al,%edi /* zero-extend that into %edi */
7108 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
7109 call audit_syscall_exit
7110 - GET_THREAD_INFO(%r10)
7111 + GET_THREAD_INFO(%r11)
7112 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
7113 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
7116 - testl %edi,TI_flags(%r10)
7117 + testl %edi,TI_flags(%r11)
7119 CLEAR_RREGS -ARGOFFSET
7121 @@ -238,7 +279,7 @@ sysexit_audit:
7124 #ifdef CONFIG_AUDITSYSCALL
7125 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7126 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7127 jz sysenter_auditsys
7130 @@ -246,6 +287,9 @@ sysenter_tracesys:
7131 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
7132 movq %rsp,%rdi /* &pt_regs -> arg1 */
7133 call syscall_trace_enter
7137 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
7139 cmpq $(IA32_NR_syscalls-1),%rax
7140 @@ -277,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
7141 ENTRY(ia32_cstar_target)
7142 CFI_STARTPROC32 simple
7144 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
7146 CFI_REGISTER rip,rcx
7147 /*CFI_REGISTER rflags,r11*/
7151 movq PER_CPU_VAR(kernel_stack),%rsp
7153 + pax_enter_kernel_user
7155 * No need to follow this irqs on/off section: the syscall
7156 * disabled irqs and here we enable it straight after entry:
7158 ENABLE_INTERRUPTS(CLBR_NONE)
7160 movl %eax,%eax /* zero extension */
7161 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
7162 movq %rcx,RIP-ARGOFFSET(%rsp)
7163 @@ -305,13 +350,19 @@ ENTRY(ia32_cstar_target)
7164 /* no need to do an access_ok check here because r8 has been
7165 32bit zero extended */
7166 /* hardware stack frame is complete now */
7168 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7169 + mov $PAX_USER_SHADOW_BASE,%r11
7174 .section __ex_table,"a"
7175 .quad 1b,ia32_badarg
7177 - GET_THREAD_INFO(%r10)
7178 - orl $TS_COMPAT,TI_status(%r10)
7179 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7180 + GET_THREAD_INFO(%r11)
7181 + orl $TS_COMPAT,TI_status(%r11)
7182 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7185 cmpq $IA32_NR_syscalls-1,%rax
7186 @@ -321,13 +372,15 @@ cstar_do_call:
7188 call *ia32_sys_call_table(,%rax,8)
7189 movq %rax,RAX-ARGOFFSET(%rsp)
7190 - GET_THREAD_INFO(%r10)
7191 + GET_THREAD_INFO(%r11)
7192 DISABLE_INTERRUPTS(CLBR_NONE)
7194 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7195 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
7197 sysretl_from_sys_call:
7198 - andl $~TS_COMPAT,TI_status(%r10)
7199 + pax_exit_kernel_user
7201 + andl $~TS_COMPAT,TI_status(%r11)
7202 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
7203 movl RIP-ARGOFFSET(%rsp),%ecx
7204 CFI_REGISTER rip,rcx
7205 @@ -355,7 +408,7 @@ sysretl_audit:
7208 #ifdef CONFIG_AUDITSYSCALL
7209 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7210 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7214 @@ -364,6 +417,9 @@ cstar_tracesys:
7215 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
7216 movq %rsp,%rdi /* &pt_regs -> arg1 */
7217 call syscall_trace_enter
7221 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
7224 @@ -409,20 +465,21 @@ ENTRY(ia32_syscall)
7225 CFI_REL_OFFSET rip,RIP-RIP
7226 PARAVIRT_ADJUST_EXCEPTION_FRAME
7229 - * No need to follow this irqs on/off section: the syscall
7230 - * disabled irqs and here we enable it straight after entry:
7232 - ENABLE_INTERRUPTS(CLBR_NONE)
7236 /* note the registers are not zero extended to the sf.
7237 this could be a problem. */
7239 - GET_THREAD_INFO(%r10)
7240 - orl $TS_COMPAT,TI_status(%r10)
7241 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7242 + pax_enter_kernel_user
7244 + * No need to follow this irqs on/off section: the syscall
7245 + * disabled irqs and here we enable it straight after entry:
7247 + ENABLE_INTERRUPTS(CLBR_NONE)
7248 + GET_THREAD_INFO(%r11)
7249 + orl $TS_COMPAT,TI_status(%r11)
7250 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7252 cmpq $(IA32_NR_syscalls-1),%rax
7254 @@ -441,6 +498,9 @@ ia32_tracesys:
7255 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
7256 movq %rsp,%rdi /* &pt_regs -> arg1 */
7257 call syscall_trace_enter
7261 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
7263 cmpq $(IA32_NR_syscalls-1),%rax
7264 @@ -455,6 +515,7 @@ ia32_badsys:
7272 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
7273 index f6f5c53..b358b28 100644
7274 --- a/arch/x86/ia32/sys_ia32.c
7275 +++ b/arch/x86/ia32/sys_ia32.c
7276 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
7278 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
7280 - typeof(ubuf->st_uid) uid = 0;
7281 - typeof(ubuf->st_gid) gid = 0;
7282 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
7283 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
7284 SET_UID(uid, stat->uid);
7285 SET_GID(gid, stat->gid);
7286 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
7287 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
7290 ret = sys_rt_sigprocmask(how,
7291 - set ? (sigset_t __user *)&s : NULL,
7292 - oset ? (sigset_t __user *)&s : NULL,
7293 + set ? (sigset_t __force_user *)&s : NULL,
7294 + oset ? (sigset_t __force_user *)&s : NULL,
7298 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
7299 return alarm_setitimer(seconds);
7302 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
7303 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
7306 return compat_sys_wait4(pid, stat_addr, options, NULL);
7307 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
7308 mm_segment_t old_fs = get_fs();
7311 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
7312 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
7314 if (put_compat_timespec(&t, interval))
7316 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
7317 mm_segment_t old_fs = get_fs();
7320 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
7321 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
7324 switch (_NSIG_WORDS) {
7325 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
7326 if (copy_siginfo_from_user32(&info, uinfo))
7329 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
7330 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
7334 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
7338 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
7339 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
7343 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
7344 index 091508b..7692c6f 100644
7345 --- a/arch/x86/include/asm/alternative-asm.h
7346 +++ b/arch/x86/include/asm/alternative-asm.h
7353 .section .smp_locks,"a"
7364 +#ifdef KERNEXEC_PLUGIN
7365 + .macro pax_force_retaddr_bts rip=0
7366 + btsq $63,\rip(%rsp)
7368 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
7369 + .macro pax_force_retaddr rip=0, reload=0
7370 + btsq $63,\rip(%rsp)
7372 + .macro pax_force_fptr ptr
7375 + .macro pax_set_fptr_mask
7378 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
7379 + .macro pax_force_retaddr rip=0, reload=0
7383 + orq %r10,\rip(%rsp)
7385 + .macro pax_force_fptr ptr
7388 + .macro pax_set_fptr_mask
7389 + movabs $0x8000000000000000,%r10
7393 + .macro pax_force_retaddr rip=0, reload=0
7395 + .macro pax_force_fptr ptr
7397 + .macro pax_force_retaddr_bts rip=0
7399 + .macro pax_set_fptr_mask
7403 .macro altinstruction_entry orig alt feature orig_len alt_len
7406 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
7407 index 37ad100..7d47faa 100644
7408 --- a/arch/x86/include/asm/alternative.h
7409 +++ b/arch/x86/include/asm/alternative.h
7410 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
7411 ".section .discard,\"aw\",@progbits\n" \
7412 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
7414 - ".section .altinstr_replacement, \"ax\"\n" \
7415 + ".section .altinstr_replacement, \"a\"\n" \
7416 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
7419 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
7420 index 1a6c09a..fec2432 100644
7421 --- a/arch/x86/include/asm/apic.h
7422 +++ b/arch/x86/include/asm/apic.h
7423 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
7425 #ifdef CONFIG_X86_LOCAL_APIC
7427 -extern unsigned int apic_verbosity;
7428 +extern int apic_verbosity;
7429 extern int local_apic_timer_c2_ok;
7431 extern int disable_apic;
7432 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
7433 index 20370c6..a2eb9b0 100644
7434 --- a/arch/x86/include/asm/apm.h
7435 +++ b/arch/x86/include/asm/apm.h
7436 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
7437 __asm__ __volatile__(APM_DO_ZERO_SEGS
7440 - "lcall *%%cs:apm_bios_entry\n\t"
7441 + "lcall *%%ss:apm_bios_entry\n\t"
7445 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
7446 __asm__ __volatile__(APM_DO_ZERO_SEGS
7449 - "lcall *%%cs:apm_bios_entry\n\t"
7450 + "lcall *%%ss:apm_bios_entry\n\t"
7454 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
7455 index 58cb6d4..ca9010d 100644
7456 --- a/arch/x86/include/asm/atomic.h
7457 +++ b/arch/x86/include/asm/atomic.h
7460 static inline int atomic_read(const atomic_t *v)
7462 - return (*(volatile int *)&(v)->counter);
7463 + return (*(volatile const int *)&(v)->counter);
7467 + * atomic_read_unchecked - read atomic variable
7468 + * @v: pointer of type atomic_unchecked_t
7470 + * Atomically reads the value of @v.
7472 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7474 + return (*(volatile const int *)&(v)->counter);
7478 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
7482 + * atomic_set_unchecked - set atomic variable
7483 + * @v: pointer of type atomic_unchecked_t
7484 + * @i: required value
7486 + * Atomically sets the value of @v to @i.
7488 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7494 * atomic_add - add integer to atomic variable
7495 * @i: integer value to add
7496 * @v: pointer of type atomic_t
7497 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
7499 static inline void atomic_add(int i, atomic_t *v)
7501 - asm volatile(LOCK_PREFIX "addl %1,%0"
7502 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7504 +#ifdef CONFIG_PAX_REFCOUNT
7506 + LOCK_PREFIX "subl %1,%0\n"
7508 + _ASM_EXTABLE(0b, 0b)
7511 + : "+m" (v->counter)
7516 + * atomic_add_unchecked - add integer to atomic variable
7517 + * @i: integer value to add
7518 + * @v: pointer of type atomic_unchecked_t
7520 + * Atomically adds @i to @v.
7522 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7524 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7528 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
7530 static inline void atomic_sub(int i, atomic_t *v)
7532 - asm volatile(LOCK_PREFIX "subl %1,%0"
7533 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7535 +#ifdef CONFIG_PAX_REFCOUNT
7537 + LOCK_PREFIX "addl %1,%0\n"
7539 + _ASM_EXTABLE(0b, 0b)
7542 + : "+m" (v->counter)
7547 + * atomic_sub_unchecked - subtract integer from atomic variable
7548 + * @i: integer value to subtract
7549 + * @v: pointer of type atomic_unchecked_t
7551 + * Atomically subtracts @i from @v.
7553 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7555 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7559 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7563 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7564 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7566 +#ifdef CONFIG_PAX_REFCOUNT
7568 + LOCK_PREFIX "addl %2,%0\n"
7570 + _ASM_EXTABLE(0b, 0b)
7574 : "+m" (v->counter), "=qm" (c)
7575 : "ir" (i) : "memory");
7577 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7579 static inline void atomic_inc(atomic_t *v)
7581 - asm volatile(LOCK_PREFIX "incl %0"
7582 + asm volatile(LOCK_PREFIX "incl %0\n"
7584 +#ifdef CONFIG_PAX_REFCOUNT
7586 + LOCK_PREFIX "decl %0\n"
7588 + _ASM_EXTABLE(0b, 0b)
7591 + : "+m" (v->counter));
7595 + * atomic_inc_unchecked - increment atomic variable
7596 + * @v: pointer of type atomic_unchecked_t
7598 + * Atomically increments @v by 1.
7600 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7602 + asm volatile(LOCK_PREFIX "incl %0\n"
7603 : "+m" (v->counter));
7606 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
7608 static inline void atomic_dec(atomic_t *v)
7610 - asm volatile(LOCK_PREFIX "decl %0"
7611 + asm volatile(LOCK_PREFIX "decl %0\n"
7613 +#ifdef CONFIG_PAX_REFCOUNT
7615 + LOCK_PREFIX "incl %0\n"
7617 + _ASM_EXTABLE(0b, 0b)
7620 + : "+m" (v->counter));
7624 + * atomic_dec_unchecked - decrement atomic variable
7625 + * @v: pointer of type atomic_unchecked_t
7627 + * Atomically decrements @v by 1.
7629 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7631 + asm volatile(LOCK_PREFIX "decl %0\n"
7632 : "+m" (v->counter));
7635 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
7639 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7640 + asm volatile(LOCK_PREFIX "decl %0\n"
7642 +#ifdef CONFIG_PAX_REFCOUNT
7644 + LOCK_PREFIX "incl %0\n"
7646 + _ASM_EXTABLE(0b, 0b)
7650 : "+m" (v->counter), "=qm" (c)
7653 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
7657 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7658 + asm volatile(LOCK_PREFIX "incl %0\n"
7660 +#ifdef CONFIG_PAX_REFCOUNT
7662 + LOCK_PREFIX "decl %0\n"
7664 + _ASM_EXTABLE(0b, 0b)
7668 + : "+m" (v->counter), "=qm" (c)
7674 + * atomic_inc_and_test_unchecked - increment and test
7675 + * @v: pointer of type atomic_unchecked_t
7677 + * Atomically increments @v by 1
7678 + * and returns true if the result is zero, or false for all
7681 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7685 + asm volatile(LOCK_PREFIX "incl %0\n"
7687 : "+m" (v->counter), "=qm" (c)
7690 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
7694 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7695 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7697 +#ifdef CONFIG_PAX_REFCOUNT
7699 + LOCK_PREFIX "subl %2,%0\n"
7701 + _ASM_EXTABLE(0b, 0b)
7705 : "+m" (v->counter), "=qm" (c)
7706 : "ir" (i) : "memory");
7708 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
7711 /* Modern 486+ processor */
7712 - return i + xadd(&v->counter, i);
7713 + return i + xadd_check_overflow(&v->counter, i);
7716 no_xadd: /* Legacy 386 processor */
7717 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
7721 + * atomic_add_return_unchecked - add integer and return
7722 + * @i: integer value to add
7723 + * @v: pointer of type atomic_unchecked_t
7725 + * Atomically adds @i to @v and returns @i + @v
7727 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7731 + unsigned long flags;
7732 + if (unlikely(boot_cpu_data.x86 <= 3))
7735 + /* Modern 486+ processor */
7736 + return i + xadd(&v->counter, i);
7739 +no_xadd: /* Legacy 386 processor */
7740 + raw_local_irq_save(flags);
7741 + __i = atomic_read_unchecked(v);
7742 + atomic_set_unchecked(v, i + __i);
7743 + raw_local_irq_restore(flags);
7749 * atomic_sub_return - subtract integer and return
7750 * @v: pointer of type atomic_t
7751 * @i: integer value to subtract
7752 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
7755 #define atomic_inc_return(v) (atomic_add_return(1, v))
7756 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7758 + return atomic_add_return_unchecked(1, v);
7760 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7762 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7763 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7764 return cmpxchg(&v->counter, old, new);
7767 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7769 + return cmpxchg(&v->counter, old, new);
7772 static inline int atomic_xchg(atomic_t *v, int new)
7774 return xchg(&v->counter, new);
7777 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7779 + return xchg(&v->counter, new);
7783 * __atomic_add_unless - add unless the number is already a given value
7784 * @v: pointer of type atomic_t
7785 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
7787 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7793 - if (unlikely(c == (u)))
7794 + if (unlikely(c == u))
7796 - old = atomic_cmpxchg((v), c, c + (a));
7798 + asm volatile("addl %2,%0\n"
7800 +#ifdef CONFIG_PAX_REFCOUNT
7804 + _ASM_EXTABLE(0b, 0b)
7808 + : "0" (c), "ir" (a));
7810 + old = atomic_cmpxchg(v, c, new);
7811 if (likely(old == c))
7814 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7819 + * atomic_inc_not_zero_hint - increment if not null
7820 + * @v: pointer of type atomic_t
7821 + * @hint: probable value of the atomic before the increment
7823 + * This version of atomic_inc_not_zero() gives a hint of probable
7824 + * value of the atomic. This helps processor to not read the memory
7825 + * before doing the atomic read/modify/write cycle, lowering
7826 + * number of bus transactions on some arches.
7828 + * Returns: 0 if increment was not done, 1 otherwise.
7830 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
7831 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
7833 + int val, c = hint, new;
7835 + /* sanity test, should be removed by compiler if hint is a constant */
7837 + return __atomic_add_unless(v, 1, 0);
7840 + asm volatile("incl %0\n"
7842 +#ifdef CONFIG_PAX_REFCOUNT
7846 + _ASM_EXTABLE(0b, 0b)
7852 + val = atomic_cmpxchg(v, c, new);
7862 * atomic_dec_if_positive - decrement by 1 if old value positive
7863 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
7864 index 24098aa..1e37723 100644
7865 --- a/arch/x86/include/asm/atomic64_32.h
7866 +++ b/arch/x86/include/asm/atomic64_32.h
7867 @@ -12,6 +12,14 @@ typedef struct {
7868 u64 __aligned(8) counter;
7871 +#ifdef CONFIG_PAX_REFCOUNT
7873 + u64 __aligned(8) counter;
7874 +} atomic64_unchecked_t;
7876 +typedef atomic64_t atomic64_unchecked_t;
7879 #define ATOMIC64_INIT(val) { (val) }
7881 #ifdef CONFIG_X86_CMPXCHG64
7882 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
7886 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
7887 + * @p: pointer to type atomic64_unchecked_t
7888 + * @o: expected value
7891 + * Atomically sets @v to @n if it was equal to @o and returns
7895 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
7897 + return cmpxchg64(&v->counter, o, n);
7901 * atomic64_xchg - xchg atomic64 variable
7902 * @v: pointer to type atomic64_t
7903 * @n: value to assign
7904 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
7908 + * atomic64_set_unchecked - set atomic64 variable
7909 + * @v: pointer to type atomic64_unchecked_t
7910 + * @n: value to assign
7912 + * Atomically sets the value of @v to @n.
7914 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
7916 + unsigned high = (unsigned)(i >> 32);
7917 + unsigned low = (unsigned)i;
7918 + asm volatile(ATOMIC64_ALTERNATIVE(set)
7919 + : "+b" (low), "+c" (high)
7921 + : "eax", "edx", "memory"
7926 * atomic64_read - read atomic64 variable
7927 * @v: pointer to type atomic64_t
7929 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
7933 + * atomic64_read_unchecked - read atomic64 variable
7934 + * @v: pointer to type atomic64_unchecked_t
7936 + * Atomically reads the value of @v and returns it.
7938 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
7941 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
7942 + : "=A" (r), "+c" (v)
7949 * atomic64_add_return - add and return
7950 * @i: integer value to add
7951 * @v: pointer to type atomic64_t
7952 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
7957 + * atomic64_add_return_unchecked - add and return
7958 + * @i: integer value to add
7959 + * @v: pointer to type atomic64_unchecked_t
7961 + * Atomically adds @i to @v and returns @i + *@v
7963 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
7965 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
7966 + : "+A" (i), "+c" (v)
7973 * Other variants with different arithmetic operators:
7975 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
7979 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7982 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
7990 static inline long long atomic64_dec_return(atomic64_t *v)
7993 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
7997 + * atomic64_add_unchecked - add integer to atomic64 variable
7998 + * @i: integer value to add
7999 + * @v: pointer to type atomic64_unchecked_t
8001 + * Atomically adds @i to @v.
8003 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
8005 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
8006 + : "+A" (i), "+c" (v)
8013 * atomic64_sub - subtract the atomic64 variable
8014 * @i: integer value to subtract
8015 * @v: pointer to type atomic64_t
8016 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
8017 index 0e1cbfc..5623683 100644
8018 --- a/arch/x86/include/asm/atomic64_64.h
8019 +++ b/arch/x86/include/asm/atomic64_64.h
8022 static inline long atomic64_read(const atomic64_t *v)
8024 - return (*(volatile long *)&(v)->counter);
8025 + return (*(volatile const long *)&(v)->counter);
8029 + * atomic64_read_unchecked - read atomic64 variable
8030 + * @v: pointer of type atomic64_unchecked_t
8032 + * Atomically reads the value of @v.
8033 + * Doesn't imply a read memory barrier.
8035 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8037 + return (*(volatile const long *)&(v)->counter);
8041 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
8045 + * atomic64_set_unchecked - set atomic64 variable
8046 + * @v: pointer to type atomic64_unchecked_t
8047 + * @i: required value
8049 + * Atomically sets the value of @v to @i.
8051 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8057 * atomic64_add - add integer to atomic64 variable
8058 * @i: integer value to add
8059 * @v: pointer to type atomic64_t
8060 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
8062 static inline void atomic64_add(long i, atomic64_t *v)
8064 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
8066 +#ifdef CONFIG_PAX_REFCOUNT
8068 + LOCK_PREFIX "subq %1,%0\n"
8070 + _ASM_EXTABLE(0b, 0b)
8073 + : "=m" (v->counter)
8074 + : "er" (i), "m" (v->counter));
8078 + * atomic64_add_unchecked - add integer to atomic64 variable
8079 + * @i: integer value to add
8080 + * @v: pointer to type atomic64_unchecked_t
8082 + * Atomically adds @i to @v.
8084 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
8086 asm volatile(LOCK_PREFIX "addq %1,%0"
8088 : "er" (i), "m" (v->counter));
8089 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
8091 static inline void atomic64_sub(long i, atomic64_t *v)
8093 - asm volatile(LOCK_PREFIX "subq %1,%0"
8094 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8096 +#ifdef CONFIG_PAX_REFCOUNT
8098 + LOCK_PREFIX "addq %1,%0\n"
8100 + _ASM_EXTABLE(0b, 0b)
8103 + : "=m" (v->counter)
8104 + : "er" (i), "m" (v->counter));
8108 + * atomic64_sub_unchecked - subtract the atomic64 variable
8109 + * @i: integer value to subtract
8110 + * @v: pointer to type atomic64_unchecked_t
8112 + * Atomically subtracts @i from @v.
8114 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8116 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8118 : "er" (i), "m" (v->counter));
8120 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
8124 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8125 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
8127 +#ifdef CONFIG_PAX_REFCOUNT
8129 + LOCK_PREFIX "addq %2,%0\n"
8131 + _ASM_EXTABLE(0b, 0b)
8135 : "=m" (v->counter), "=qm" (c)
8136 : "er" (i), "m" (v->counter) : "memory");
8138 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
8140 static inline void atomic64_inc(atomic64_t *v)
8142 + asm volatile(LOCK_PREFIX "incq %0\n"
8144 +#ifdef CONFIG_PAX_REFCOUNT
8146 + LOCK_PREFIX "decq %0\n"
8148 + _ASM_EXTABLE(0b, 0b)
8151 + : "=m" (v->counter)
8152 + : "m" (v->counter));
8156 + * atomic64_inc_unchecked - increment atomic64 variable
8157 + * @v: pointer to type atomic64_unchecked_t
8159 + * Atomically increments @v by 1.
8161 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8163 asm volatile(LOCK_PREFIX "incq %0"
8165 : "m" (v->counter));
8166 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
8168 static inline void atomic64_dec(atomic64_t *v)
8170 - asm volatile(LOCK_PREFIX "decq %0"
8171 + asm volatile(LOCK_PREFIX "decq %0\n"
8173 +#ifdef CONFIG_PAX_REFCOUNT
8175 + LOCK_PREFIX "incq %0\n"
8177 + _ASM_EXTABLE(0b, 0b)
8180 + : "=m" (v->counter)
8181 + : "m" (v->counter));
8185 + * atomic64_dec_unchecked - decrement atomic64 variable
8186 + * @v: pointer to type atomic64_t
8188 + * Atomically decrements @v by 1.
8190 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8192 + asm volatile(LOCK_PREFIX "decq %0\n"
8194 : "m" (v->counter));
8196 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
8200 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
8201 + asm volatile(LOCK_PREFIX "decq %0\n"
8203 +#ifdef CONFIG_PAX_REFCOUNT
8205 + LOCK_PREFIX "incq %0\n"
8207 + _ASM_EXTABLE(0b, 0b)
8211 : "=m" (v->counter), "=qm" (c)
8212 : "m" (v->counter) : "memory");
8214 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
8218 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
8219 + asm volatile(LOCK_PREFIX "incq %0\n"
8221 +#ifdef CONFIG_PAX_REFCOUNT
8223 + LOCK_PREFIX "decq %0\n"
8225 + _ASM_EXTABLE(0b, 0b)
8229 : "=m" (v->counter), "=qm" (c)
8230 : "m" (v->counter) : "memory");
8232 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
8236 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8237 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
8239 +#ifdef CONFIG_PAX_REFCOUNT
8241 + LOCK_PREFIX "subq %2,%0\n"
8243 + _ASM_EXTABLE(0b, 0b)
8247 : "=m" (v->counter), "=qm" (c)
8248 : "er" (i), "m" (v->counter) : "memory");
8250 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
8252 static inline long atomic64_add_return(long i, atomic64_t *v)
8254 + return i + xadd_check_overflow(&v->counter, i);
8258 + * atomic64_add_return_unchecked - add and return
8259 + * @i: integer value to add
8260 + * @v: pointer to type atomic64_unchecked_t
8262 + * Atomically adds @i to @v and returns @i + @v
8264 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8266 return i + xadd(&v->counter, i);
8269 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
8272 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8273 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8275 + return atomic64_add_return_unchecked(1, v);
8277 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8279 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8280 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8281 return cmpxchg(&v->counter, old, new);
8284 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8286 + return cmpxchg(&v->counter, old, new);
8289 static inline long atomic64_xchg(atomic64_t *v, long new)
8291 return xchg(&v->counter, new);
8292 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
8294 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8298 c = atomic64_read(v);
8300 - if (unlikely(c == (u)))
8301 + if (unlikely(c == u))
8303 - old = atomic64_cmpxchg((v), c, c + (a));
8305 + asm volatile("add %2,%0\n"
8307 +#ifdef CONFIG_PAX_REFCOUNT
8311 + _ASM_EXTABLE(0b, 0b)
8315 + : "0" (c), "ir" (a));
8317 + old = atomic64_cmpxchg(v, c, new);
8318 if (likely(old == c))
8326 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8327 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
8328 index 1775d6e..b65017f 100644
8329 --- a/arch/x86/include/asm/bitops.h
8330 +++ b/arch/x86/include/asm/bitops.h
8332 * a mask operation on a byte.
8334 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8335 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8336 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8337 #define CONST_MASK(nr) (1 << ((nr) & 7))
8340 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
8341 index 5e1a2ee..c9f9533 100644
8342 --- a/arch/x86/include/asm/boot.h
8343 +++ b/arch/x86/include/asm/boot.h
8345 #include <asm/pgtable_types.h>
8347 /* Physical address where kernel should be loaded. */
8348 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8349 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8350 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8351 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8353 +#ifndef __ASSEMBLY__
8354 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
8355 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8358 /* Minimum kernel alignment, as a power of two */
8359 #ifdef CONFIG_X86_64
8360 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8361 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
8362 index 48f99f1..d78ebf9 100644
8363 --- a/arch/x86/include/asm/cache.h
8364 +++ b/arch/x86/include/asm/cache.h
8367 /* L1 cache line size */
8368 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8369 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8370 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8372 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8373 +#define __read_only __attribute__((__section__(".data..read_only")))
8375 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
8376 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
8377 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
8379 #ifdef CONFIG_X86_VSMP
8381 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
8382 index 4e12668..501d239 100644
8383 --- a/arch/x86/include/asm/cacheflush.h
8384 +++ b/arch/x86/include/asm/cacheflush.h
8385 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
8386 unsigned long pg_flags = pg->flags & _PGMT_MASK;
8388 if (pg_flags == _PGMT_DEFAULT)
8391 else if (pg_flags == _PGMT_WC)
8392 return _PAGE_CACHE_WC;
8393 else if (pg_flags == _PGMT_UC_MINUS)
8394 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
8395 index 46fc474..b02b0f9 100644
8396 --- a/arch/x86/include/asm/checksum_32.h
8397 +++ b/arch/x86/include/asm/checksum_32.h
8398 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
8399 int len, __wsum sum,
8400 int *src_err_ptr, int *dst_err_ptr);
8402 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
8403 + int len, __wsum sum,
8404 + int *src_err_ptr, int *dst_err_ptr);
8406 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
8407 + int len, __wsum sum,
8408 + int *src_err_ptr, int *dst_err_ptr);
8411 * Note: when you get a NULL pointer exception here this means someone
8412 * passed in an incorrect kernel address to one of these functions.
8413 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
8417 - return csum_partial_copy_generic((__force void *)src, dst,
8418 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
8419 len, sum, err_ptr, NULL);
8422 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
8425 if (access_ok(VERIFY_WRITE, dst, len))
8426 - return csum_partial_copy_generic(src, (__force void *)dst,
8427 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
8428 len, sum, NULL, err_ptr);
8431 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
8432 index 5d3acdf..6447a02 100644
8433 --- a/arch/x86/include/asm/cmpxchg.h
8434 +++ b/arch/x86/include/asm/cmpxchg.h
8435 @@ -14,6 +14,8 @@ extern void __cmpxchg_wrong_size(void)
8436 __compiletime_error("Bad argument size for cmpxchg");
8437 extern void __xadd_wrong_size(void)
8438 __compiletime_error("Bad argument size for xadd");
8439 +extern void __xadd_check_overflow_wrong_size(void)
8440 + __compiletime_error("Bad argument size for xadd_check_overflow");
8443 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
8444 @@ -195,6 +197,34 @@ extern void __xadd_wrong_size(void)
8448 +#define __xadd_check_overflow(ptr, inc, lock) \
8450 + __typeof__ (*(ptr)) __ret = (inc); \
8451 + switch (sizeof(*(ptr))) { \
8452 + case __X86_CASE_L: \
8453 + asm volatile (lock "xaddl %0, %1\n" \
8457 + _ASM_EXTABLE(0b, 0b) \
8458 + : "+r" (__ret), "+m" (*(ptr)) \
8459 + : : "memory", "cc"); \
8461 + case __X86_CASE_Q: \
8462 + asm volatile (lock "xaddq %q0, %1\n" \
8466 + _ASM_EXTABLE(0b, 0b) \
8467 + : "+r" (__ret), "+m" (*(ptr)) \
8468 + : : "memory", "cc"); \
8471 + __xadd_check_overflow_wrong_size(); \
8477 * xadd() adds "inc" to "*ptr" and atomically returns the previous
8479 @@ -207,4 +237,6 @@ extern void __xadd_wrong_size(void)
8480 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
8481 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
8483 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
8485 #endif /* ASM_X86_CMPXCHG_H */
8486 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
8487 index f3444f7..051a196 100644
8488 --- a/arch/x86/include/asm/cpufeature.h
8489 +++ b/arch/x86/include/asm/cpufeature.h
8490 @@ -363,7 +363,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
8491 ".section .discard,\"aw\",@progbits\n"
8492 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
8494 - ".section .altinstr_replacement,\"ax\"\n"
8495 + ".section .altinstr_replacement,\"a\"\n"
8499 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
8500 index 41935fa..3b40db8 100644
8501 --- a/arch/x86/include/asm/desc.h
8502 +++ b/arch/x86/include/asm/desc.h
8504 #include <asm/desc_defs.h>
8505 #include <asm/ldt.h>
8506 #include <asm/mmu.h>
8507 +#include <asm/pgtable.h>
8509 #include <linux/smp.h>
8511 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8513 desc->type = (info->read_exec_only ^ 1) << 1;
8514 desc->type |= info->contents << 2;
8515 + desc->type |= info->seg_not_present ^ 1;
8519 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8522 extern struct desc_ptr idt_descr;
8523 -extern gate_desc idt_table[];
8526 - struct desc_struct gdt[GDT_ENTRIES];
8527 -} __attribute__((aligned(PAGE_SIZE)));
8529 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
8530 +extern gate_desc idt_table[256];
8532 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
8533 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
8535 - return per_cpu(gdt_page, cpu).gdt;
8536 + return cpu_gdt_table[cpu];
8539 #ifdef CONFIG_X86_64
8540 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
8541 unsigned long base, unsigned dpl, unsigned flags,
8544 - gate->a = (seg << 16) | (base & 0xffff);
8545 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
8546 + gate->gate.offset_low = base;
8547 + gate->gate.seg = seg;
8548 + gate->gate.reserved = 0;
8549 + gate->gate.type = type;
8551 + gate->gate.dpl = dpl;
8553 + gate->gate.offset_high = base >> 16;
8557 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
8559 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
8561 + pax_open_kernel();
8562 memcpy(&idt[entry], gate, sizeof(*gate));
8563 + pax_close_kernel();
8566 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
8568 + pax_open_kernel();
8569 memcpy(&ldt[entry], desc, 8);
8570 + pax_close_kernel();
8574 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
8575 default: size = sizeof(*gdt); break;
8578 + pax_open_kernel();
8579 memcpy(&gdt[entry], desc, size);
8580 + pax_close_kernel();
8583 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
8584 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
8586 static inline void native_load_tr_desc(void)
8588 + pax_open_kernel();
8589 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
8590 + pax_close_kernel();
8593 static inline void native_load_gdt(const struct desc_ptr *dtr)
8594 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
8595 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
8598 + pax_open_kernel();
8599 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
8600 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
8601 + pax_close_kernel();
8604 #define _LDT_empty(info) \
8605 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
8606 desc->limit = (limit >> 16) & 0xf;
8609 -static inline void _set_gate(int gate, unsigned type, void *addr,
8610 +static inline void _set_gate(int gate, unsigned type, const void *addr,
8611 unsigned dpl, unsigned ist, unsigned seg)
8614 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
8615 * Pentium F0 0F bugfix can have resulted in the mapped
8616 * IDT being write-protected.
8618 -static inline void set_intr_gate(unsigned int n, void *addr)
8619 +static inline void set_intr_gate(unsigned int n, const void *addr)
8621 BUG_ON((unsigned)n > 0xFF);
8622 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
8623 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
8625 * This routine sets up an interrupt gate at directory privilege level 3.
8627 -static inline void set_system_intr_gate(unsigned int n, void *addr)
8628 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
8630 BUG_ON((unsigned)n > 0xFF);
8631 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
8634 -static inline void set_system_trap_gate(unsigned int n, void *addr)
8635 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
8637 BUG_ON((unsigned)n > 0xFF);
8638 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8641 -static inline void set_trap_gate(unsigned int n, void *addr)
8642 +static inline void set_trap_gate(unsigned int n, const void *addr)
8644 BUG_ON((unsigned)n > 0xFF);
8645 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8646 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
8647 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8649 BUG_ON((unsigned)n > 0xFF);
8650 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8651 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8654 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8655 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8657 BUG_ON((unsigned)n > 0xFF);
8658 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8661 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8662 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8664 BUG_ON((unsigned)n > 0xFF);
8665 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8668 +#ifdef CONFIG_X86_32
8669 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8671 + struct desc_struct d;
8673 + if (likely(limit))
8674 + limit = (limit - 1UL) >> PAGE_SHIFT;
8675 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
8676 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8680 #endif /* _ASM_X86_DESC_H */
8681 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
8682 index 278441f..b95a174 100644
8683 --- a/arch/x86/include/asm/desc_defs.h
8684 +++ b/arch/x86/include/asm/desc_defs.h
8685 @@ -31,6 +31,12 @@ struct desc_struct {
8686 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
8687 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
8692 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
8693 + unsigned offset_high: 16;
8696 } __attribute__((packed));
8698 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
8699 index 908b969..a1f4eb4 100644
8700 --- a/arch/x86/include/asm/e820.h
8701 +++ b/arch/x86/include/asm/e820.h
8702 @@ -69,7 +69,7 @@ struct e820map {
8703 #define ISA_START_ADDRESS 0xa0000
8704 #define ISA_END_ADDRESS 0x100000
8706 -#define BIOS_BEGIN 0x000a0000
8707 +#define BIOS_BEGIN 0x000c0000
8708 #define BIOS_END 0x00100000
8710 #define BIOS_ROM_BASE 0xffe00000
8711 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
8712 index 5f962df..7289f09 100644
8713 --- a/arch/x86/include/asm/elf.h
8714 +++ b/arch/x86/include/asm/elf.h
8715 @@ -238,7 +238,25 @@ extern int force_personality32;
8716 the loader. We need to make sure that it is out of the way of the program
8717 that it will "exec", and that there is sufficient room for the brk. */
8719 +#ifdef CONFIG_PAX_SEGMEXEC
8720 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8722 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8725 +#ifdef CONFIG_PAX_ASLR
8726 +#ifdef CONFIG_X86_32
8727 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8729 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8730 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8732 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
8734 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8735 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8739 /* This yields a mask that user programs can use to figure out what
8740 instruction set this CPU supports. This could be done in user space,
8741 @@ -291,9 +309,7 @@ do { \
8743 #define ARCH_DLINFO \
8745 - if (vdso_enabled) \
8746 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8747 - (unsigned long)current->mm->context.vdso); \
8748 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
8751 #define AT_SYSINFO 32
8752 @@ -304,7 +320,7 @@ do { \
8754 #endif /* !CONFIG_X86_32 */
8756 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8757 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8759 #define VDSO_ENTRY \
8760 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8761 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8762 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8763 #define compat_arch_setup_additional_pages syscall32_setup_pages
8765 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8766 -#define arch_randomize_brk arch_randomize_brk
8769 * True on X86_32 or when emulating IA32 on X86_64
8771 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
8772 index cc70c1c..d96d011 100644
8773 --- a/arch/x86/include/asm/emergency-restart.h
8774 +++ b/arch/x86/include/asm/emergency-restart.h
8775 @@ -15,6 +15,6 @@ enum reboot_type {
8777 extern enum reboot_type reboot_type;
8779 -extern void machine_emergency_restart(void);
8780 +extern void machine_emergency_restart(void) __noreturn;
8782 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8783 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
8784 index d09bb03..4ea4194 100644
8785 --- a/arch/x86/include/asm/futex.h
8786 +++ b/arch/x86/include/asm/futex.h
8788 #include <asm/system.h>
8790 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8791 + typecheck(u32 __user *, uaddr); \
8792 asm volatile("1:\t" insn "\n" \
8793 "2:\t.section .fixup,\"ax\"\n" \
8794 "3:\tmov\t%3, %1\n" \
8797 _ASM_EXTABLE(1b, 3b) \
8798 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8799 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
8800 : "i" (-EFAULT), "0" (oparg), "1" (0))
8802 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8803 + typecheck(u32 __user *, uaddr); \
8804 asm volatile("1:\tmovl %2, %0\n" \
8805 "\tmovl\t%0, %3\n" \
8808 _ASM_EXTABLE(1b, 4b) \
8809 _ASM_EXTABLE(2b, 4b) \
8810 : "=&a" (oldval), "=&r" (ret), \
8811 - "+m" (*uaddr), "=&r" (tem) \
8812 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
8813 : "r" (oparg), "i" (-EFAULT), "1" (0))
8815 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8816 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8820 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8821 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8824 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8825 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8829 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
8830 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8833 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
8834 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
8835 "2:\t.section .fixup, \"ax\"\n"
8839 _ASM_EXTABLE(1b, 3b)
8840 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
8841 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
8842 : "i" (-EFAULT), "r" (newval), "1" (oldval)
8845 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
8846 index eb92a6e..b98b2f4 100644
8847 --- a/arch/x86/include/asm/hw_irq.h
8848 +++ b/arch/x86/include/asm/hw_irq.h
8849 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
8850 extern void enable_IO_APIC(void);
8853 -extern atomic_t irq_err_count;
8854 -extern atomic_t irq_mis_count;
8855 +extern atomic_unchecked_t irq_err_count;
8856 +extern atomic_unchecked_t irq_mis_count;
8859 extern void eisa_set_level_irq(unsigned int irq);
8860 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
8861 index a850b4d..bae26dc 100644
8862 --- a/arch/x86/include/asm/i387.h
8863 +++ b/arch/x86/include/asm/i387.h
8864 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
8868 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8869 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8870 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
8873 /* See comment in fxsave() below. */
8874 #ifdef CONFIG_AS_FXSAVEQ
8875 asm volatile("1: fxrstorq %[fx]\n\t"
8876 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
8880 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8881 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8882 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8886 * Clear the bytes not touched by the fxsave and reserved
8888 @@ -424,7 +434,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
8889 static inline bool interrupted_user_mode(void)
8891 struct pt_regs *regs = get_irq_regs();
8892 - return regs && user_mode_vm(regs);
8893 + return regs && user_mode(regs);
8897 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
8898 index d8e8eef..99f81ae 100644
8899 --- a/arch/x86/include/asm/io.h
8900 +++ b/arch/x86/include/asm/io.h
8901 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
8903 #include <linux/vmalloc.h>
8905 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8906 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8908 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8911 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8913 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8917 * Convert a virtual cached pointer to an uncached pointer
8919 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
8920 index bba3cf8..06bc8da 100644
8921 --- a/arch/x86/include/asm/irqflags.h
8922 +++ b/arch/x86/include/asm/irqflags.h
8923 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
8927 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
8928 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8929 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
8930 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8933 #define INTERRUPT_RETURN iret
8934 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8935 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
8936 index 5478825..839e88c 100644
8937 --- a/arch/x86/include/asm/kprobes.h
8938 +++ b/arch/x86/include/asm/kprobes.h
8939 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
8940 #define RELATIVEJUMP_SIZE 5
8941 #define RELATIVECALL_OPCODE 0xe8
8942 #define RELATIVE_ADDR_SIZE 4
8943 -#define MAX_STACK_SIZE 64
8944 -#define MIN_STACK_SIZE(ADDR) \
8945 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8946 - THREAD_SIZE - (unsigned long)(ADDR))) \
8947 - ? (MAX_STACK_SIZE) \
8948 - : (((unsigned long)current_thread_info()) + \
8949 - THREAD_SIZE - (unsigned long)(ADDR)))
8950 +#define MAX_STACK_SIZE 64UL
8951 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8953 #define flush_insn_slot(p) do { } while (0)
8955 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
8956 index b4973f4..7c4d3fc 100644
8957 --- a/arch/x86/include/asm/kvm_host.h
8958 +++ b/arch/x86/include/asm/kvm_host.h
8959 @@ -459,7 +459,7 @@ struct kvm_arch {
8960 unsigned int n_requested_mmu_pages;
8961 unsigned int n_max_mmu_pages;
8962 unsigned int indirect_shadow_pages;
8963 - atomic_t invlpg_counter;
8964 + atomic_unchecked_t invlpg_counter;
8965 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
8967 * Hash table of struct kvm_mmu_page.
8968 @@ -638,7 +638,7 @@ struct kvm_x86_ops {
8969 int (*check_intercept)(struct kvm_vcpu *vcpu,
8970 struct x86_instruction_info *info,
8971 enum x86_intercept_stage stage);
8975 struct kvm_arch_async_pf {
8977 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
8978 index 9cdae5d..300d20f 100644
8979 --- a/arch/x86/include/asm/local.h
8980 +++ b/arch/x86/include/asm/local.h
8981 @@ -18,26 +18,58 @@ typedef struct {
8983 static inline void local_inc(local_t *l)
8985 - asm volatile(_ASM_INC "%0"
8986 + asm volatile(_ASM_INC "%0\n"
8988 +#ifdef CONFIG_PAX_REFCOUNT
8992 + _ASM_EXTABLE(0b, 0b)
8995 : "+m" (l->a.counter));
8998 static inline void local_dec(local_t *l)
9000 - asm volatile(_ASM_DEC "%0"
9001 + asm volatile(_ASM_DEC "%0\n"
9003 +#ifdef CONFIG_PAX_REFCOUNT
9007 + _ASM_EXTABLE(0b, 0b)
9010 : "+m" (l->a.counter));
9013 static inline void local_add(long i, local_t *l)
9015 - asm volatile(_ASM_ADD "%1,%0"
9016 + asm volatile(_ASM_ADD "%1,%0\n"
9018 +#ifdef CONFIG_PAX_REFCOUNT
9020 + _ASM_SUB "%1,%0\n"
9022 + _ASM_EXTABLE(0b, 0b)
9025 : "+m" (l->a.counter)
9029 static inline void local_sub(long i, local_t *l)
9031 - asm volatile(_ASM_SUB "%1,%0"
9032 + asm volatile(_ASM_SUB "%1,%0\n"
9034 +#ifdef CONFIG_PAX_REFCOUNT
9036 + _ASM_ADD "%1,%0\n"
9038 + _ASM_EXTABLE(0b, 0b)
9041 : "+m" (l->a.counter)
9044 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
9048 - asm volatile(_ASM_SUB "%2,%0; sete %1"
9049 + asm volatile(_ASM_SUB "%2,%0\n"
9051 +#ifdef CONFIG_PAX_REFCOUNT
9053 + _ASM_ADD "%2,%0\n"
9055 + _ASM_EXTABLE(0b, 0b)
9059 : "+m" (l->a.counter), "=qm" (c)
9060 : "ir" (i) : "memory");
9062 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
9066 - asm volatile(_ASM_DEC "%0; sete %1"
9067 + asm volatile(_ASM_DEC "%0\n"
9069 +#ifdef CONFIG_PAX_REFCOUNT
9073 + _ASM_EXTABLE(0b, 0b)
9077 : "+m" (l->a.counter), "=qm" (c)
9080 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
9084 - asm volatile(_ASM_INC "%0; sete %1"
9085 + asm volatile(_ASM_INC "%0\n"
9087 +#ifdef CONFIG_PAX_REFCOUNT
9091 + _ASM_EXTABLE(0b, 0b)
9095 : "+m" (l->a.counter), "=qm" (c)
9098 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
9102 - asm volatile(_ASM_ADD "%2,%0; sets %1"
9103 + asm volatile(_ASM_ADD "%2,%0\n"
9105 +#ifdef CONFIG_PAX_REFCOUNT
9107 + _ASM_SUB "%2,%0\n"
9109 + _ASM_EXTABLE(0b, 0b)
9113 : "+m" (l->a.counter), "=qm" (c)
9114 : "ir" (i) : "memory");
9116 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
9118 /* Modern 486+ processor */
9120 - asm volatile(_ASM_XADD "%0, %1;"
9121 + asm volatile(_ASM_XADD "%0, %1\n"
9123 +#ifdef CONFIG_PAX_REFCOUNT
9125 + _ASM_MOV "%0,%1\n"
9127 + _ASM_EXTABLE(0b, 0b)
9130 : "+r" (i), "+m" (l->a.counter)
9133 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
9134 index 593e51d..fa69c9a 100644
9135 --- a/arch/x86/include/asm/mman.h
9136 +++ b/arch/x86/include/asm/mman.h
9139 #include <asm-generic/mman.h>
9142 +#ifndef __ASSEMBLY__
9143 +#ifdef CONFIG_X86_32
9144 +#define arch_mmap_check i386_mmap_check
9145 +int i386_mmap_check(unsigned long addr, unsigned long len,
9146 + unsigned long flags);
9151 #endif /* _ASM_X86_MMAN_H */
9152 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
9153 index 5f55e69..e20bfb1 100644
9154 --- a/arch/x86/include/asm/mmu.h
9155 +++ b/arch/x86/include/asm/mmu.h
9157 * we put the segment information here.
9161 + struct desc_struct *ldt;
9164 #ifdef CONFIG_X86_64
9165 @@ -18,7 +18,19 @@ typedef struct {
9170 + unsigned long vdso;
9172 +#ifdef CONFIG_X86_32
9173 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
9174 + unsigned long user_cs_base;
9175 + unsigned long user_cs_limit;
9177 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9178 + cpumask_t cpu_user_cs_mask;
9186 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
9187 index 6902152..399f3a2 100644
9188 --- a/arch/x86/include/asm/mmu_context.h
9189 +++ b/arch/x86/include/asm/mmu_context.h
9190 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
9192 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9195 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9199 + pax_open_kernel();
9200 + pgd = get_cpu_pgd(smp_processor_id());
9201 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
9202 + set_pgd_batched(pgd+i, native_make_pgd(0));
9203 + pax_close_kernel();
9207 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
9208 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
9209 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9210 struct task_struct *tsk)
9212 unsigned cpu = smp_processor_id();
9213 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9214 + int tlbstate = TLBSTATE_OK;
9217 if (likely(prev != next)) {
9219 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9220 + tlbstate = percpu_read(cpu_tlbstate.state);
9222 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9223 percpu_write(cpu_tlbstate.active_mm, next);
9225 cpumask_set_cpu(cpu, mm_cpumask(next));
9227 /* Re-load page tables */
9228 +#ifdef CONFIG_PAX_PER_CPU_PGD
9229 + pax_open_kernel();
9230 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9231 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9232 + pax_close_kernel();
9233 + load_cr3(get_cpu_pgd(cpu));
9235 load_cr3(next->pgd);
9238 /* stop flush ipis for the previous mm */
9239 cpumask_clear_cpu(cpu, mm_cpumask(prev));
9240 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9242 if (unlikely(prev->context.ldt != next->context.ldt))
9243 load_LDT_nolock(&next->context);
9246 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9247 + if (!(__supported_pte_mask & _PAGE_NX)) {
9248 + smp_mb__before_clear_bit();
9249 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
9250 + smp_mb__after_clear_bit();
9251 + cpu_set(cpu, next->context.cpu_user_cs_mask);
9255 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9256 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
9257 + prev->context.user_cs_limit != next->context.user_cs_limit))
9258 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9260 + else if (unlikely(tlbstate != TLBSTATE_OK))
9261 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9268 +#ifdef CONFIG_PAX_PER_CPU_PGD
9269 + pax_open_kernel();
9270 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9271 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9272 + pax_close_kernel();
9273 + load_cr3(get_cpu_pgd(cpu));
9277 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9278 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
9280 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9281 * tlb flush IPI delivery. We must reload CR3
9282 * to make sure to use no freed page tables.
9285 +#ifndef CONFIG_PAX_PER_CPU_PGD
9286 load_cr3(next->pgd);
9289 load_LDT_nolock(&next->context);
9291 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9292 + if (!(__supported_pte_mask & _PAGE_NX))
9293 + cpu_set(cpu, next->context.cpu_user_cs_mask);
9296 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9297 +#ifdef CONFIG_PAX_PAGEEXEC
9298 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
9300 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9309 #define activate_mm(prev, next) \
9310 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
9311 index 9eae775..c914fea 100644
9312 --- a/arch/x86/include/asm/module.h
9313 +++ b/arch/x86/include/asm/module.h
9316 #ifdef CONFIG_X86_64
9317 /* X86_64 does not define MODULE_PROC_FAMILY */
9318 +#define MODULE_PROC_FAMILY ""
9319 #elif defined CONFIG_M386
9320 #define MODULE_PROC_FAMILY "386 "
9321 #elif defined CONFIG_M486
9323 #error unknown processor family
9326 -#ifdef CONFIG_X86_32
9327 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
9328 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9329 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
9330 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
9331 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
9333 +#define MODULE_PAX_KERNEXEC ""
9336 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9337 +#define MODULE_PAX_UDEREF "UDEREF "
9339 +#define MODULE_PAX_UDEREF ""
9342 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
9344 #endif /* _ASM_X86_MODULE_H */
9345 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
9346 index 7639dbf..e08a58c 100644
9347 --- a/arch/x86/include/asm/page_64_types.h
9348 +++ b/arch/x86/include/asm/page_64_types.h
9349 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
9351 /* duplicated to the one in bootmem.h */
9352 extern unsigned long max_pfn;
9353 -extern unsigned long phys_base;
9354 +extern const unsigned long phys_base;
9356 extern unsigned long __phys_addr(unsigned long);
9357 #define __phys_reloc_hide(x) (x)
9358 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
9359 index a7d2db9..edb023e 100644
9360 --- a/arch/x86/include/asm/paravirt.h
9361 +++ b/arch/x86/include/asm/paravirt.h
9362 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
9366 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9368 + pgdval_t val = native_pgd_val(pgd);
9370 + if (sizeof(pgdval_t) > sizeof(long))
9371 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
9372 + val, (u64)val >> 32);
9374 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
9378 static inline void pgd_clear(pgd_t *pgdp)
9380 set_pgd(pgdp, __pgd(0));
9381 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
9382 pv_mmu_ops.set_fixmap(idx, phys, flags);
9385 +#ifdef CONFIG_PAX_KERNEXEC
9386 +static inline unsigned long pax_open_kernel(void)
9388 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
9391 +static inline unsigned long pax_close_kernel(void)
9393 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
9396 +static inline unsigned long pax_open_kernel(void) { return 0; }
9397 +static inline unsigned long pax_close_kernel(void) { return 0; }
9400 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
9402 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
9403 @@ -964,7 +991,7 @@ extern void default_banner(void);
9405 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
9406 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
9407 -#define PARA_INDIRECT(addr) *%cs:addr
9408 +#define PARA_INDIRECT(addr) *%ss:addr
9411 #define INTERRUPT_RETURN \
9412 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
9413 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
9415 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
9417 +#define GET_CR0_INTO_RDI \
9418 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
9421 +#define SET_RDI_INTO_CR0 \
9422 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
9424 +#define GET_CR3_INTO_RDI \
9425 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
9428 +#define SET_RDI_INTO_CR3 \
9429 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
9431 #endif /* CONFIG_X86_32 */
9433 #endif /* __ASSEMBLY__ */
9434 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
9435 index 8e8b9a4..f07d725 100644
9436 --- a/arch/x86/include/asm/paravirt_types.h
9437 +++ b/arch/x86/include/asm/paravirt_types.h
9438 @@ -84,20 +84,20 @@ struct pv_init_ops {
9440 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
9441 unsigned long addr, unsigned len);
9446 struct pv_lazy_ops {
9447 /* Set deferred update mode, used for batching operations. */
9448 void (*enter)(void);
9449 void (*leave)(void);
9453 struct pv_time_ops {
9454 unsigned long long (*sched_clock)(void);
9455 unsigned long long (*steal_clock)(int cpu);
9456 unsigned long (*get_tsc_khz)(void);
9461 /* hooks for various privileged instructions */
9462 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
9464 void (*start_context_switch)(struct task_struct *prev);
9465 void (*end_context_switch)(struct task_struct *next);
9471 @@ -224,7 +224,7 @@ struct pv_apic_ops {
9472 unsigned long start_eip,
9473 unsigned long start_esp);
9479 unsigned long (*read_cr2)(void);
9480 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
9481 struct paravirt_callee_save make_pud;
9483 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
9484 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
9485 #endif /* PAGETABLE_LEVELS == 4 */
9486 #endif /* PAGETABLE_LEVELS >= 3 */
9488 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
9489 an mfn. We can tell which is which from the index. */
9490 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
9491 phys_addr_t phys, pgprot_t flags);
9493 +#ifdef CONFIG_PAX_KERNEXEC
9494 + unsigned long (*pax_open_kernel)(void);
9495 + unsigned long (*pax_close_kernel)(void);
9500 struct arch_spinlock;
9501 @@ -334,7 +341,7 @@ struct pv_lock_ops {
9502 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
9503 int (*spin_trylock)(struct arch_spinlock *lock);
9504 void (*spin_unlock)(struct arch_spinlock *lock);
9508 /* This contains all the paravirt structures: we get a convenient
9509 * number for each function using the offset which we use to indicate
9510 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
9511 index b4389a4..b7ff22c 100644
9512 --- a/arch/x86/include/asm/pgalloc.h
9513 +++ b/arch/x86/include/asm/pgalloc.h
9514 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
9515 pmd_t *pmd, pte_t *pte)
9517 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9518 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
9521 +static inline void pmd_populate_user(struct mm_struct *mm,
9522 + pmd_t *pmd, pte_t *pte)
9524 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9525 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
9528 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
9529 index 98391db..8f6984e 100644
9530 --- a/arch/x86/include/asm/pgtable-2level.h
9531 +++ b/arch/x86/include/asm/pgtable-2level.h
9532 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
9534 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9536 + pax_open_kernel();
9538 + pax_close_kernel();
9541 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9542 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
9543 index effff47..f9e4035 100644
9544 --- a/arch/x86/include/asm/pgtable-3level.h
9545 +++ b/arch/x86/include/asm/pgtable-3level.h
9546 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9548 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9550 + pax_open_kernel();
9551 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9552 + pax_close_kernel();
9555 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9557 + pax_open_kernel();
9558 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9559 + pax_close_kernel();
9563 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
9564 index 18601c8..3d716d1 100644
9565 --- a/arch/x86/include/asm/pgtable.h
9566 +++ b/arch/x86/include/asm/pgtable.h
9567 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9569 #ifndef __PAGETABLE_PUD_FOLDED
9570 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
9571 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
9572 #define pgd_clear(pgd) native_pgd_clear(pgd)
9575 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9577 #define arch_end_context_switch(prev) do {} while(0)
9579 +#define pax_open_kernel() native_pax_open_kernel()
9580 +#define pax_close_kernel() native_pax_close_kernel()
9581 #endif /* CONFIG_PARAVIRT */
9583 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
9584 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9586 +#ifdef CONFIG_PAX_KERNEXEC
9587 +static inline unsigned long native_pax_open_kernel(void)
9589 + unsigned long cr0;
9591 + preempt_disable();
9593 + cr0 = read_cr0() ^ X86_CR0_WP;
9594 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
9596 + return cr0 ^ X86_CR0_WP;
9599 +static inline unsigned long native_pax_close_kernel(void)
9601 + unsigned long cr0;
9603 + cr0 = read_cr0() ^ X86_CR0_WP;
9604 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9607 + preempt_enable_no_resched();
9608 + return cr0 ^ X86_CR0_WP;
9611 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
9612 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
9616 * The following only work if pte_present() is true.
9617 * Undefined behaviour if not..
9619 +static inline int pte_user(pte_t pte)
9621 + return pte_val(pte) & _PAGE_USER;
9624 static inline int pte_dirty(pte_t pte)
9626 return pte_flags(pte) & _PAGE_DIRTY;
9627 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
9628 return pte_clear_flags(pte, _PAGE_RW);
9631 +static inline pte_t pte_mkread(pte_t pte)
9633 + return __pte(pte_val(pte) | _PAGE_USER);
9636 static inline pte_t pte_mkexec(pte_t pte)
9638 - return pte_clear_flags(pte, _PAGE_NX);
9639 +#ifdef CONFIG_X86_PAE
9640 + if (__supported_pte_mask & _PAGE_NX)
9641 + return pte_clear_flags(pte, _PAGE_NX);
9644 + return pte_set_flags(pte, _PAGE_USER);
9647 +static inline pte_t pte_exprotect(pte_t pte)
9649 +#ifdef CONFIG_X86_PAE
9650 + if (__supported_pte_mask & _PAGE_NX)
9651 + return pte_set_flags(pte, _PAGE_NX);
9654 + return pte_clear_flags(pte, _PAGE_USER);
9657 static inline pte_t pte_mkdirty(pte_t pte)
9658 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
9661 #ifndef __ASSEMBLY__
9663 +#ifdef CONFIG_PAX_PER_CPU_PGD
9664 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9665 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9667 + return cpu_pgd[cpu];
9671 #include <linux/mm_types.h>
9673 static inline int pte_none(pte_t pte)
9674 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
9676 static inline int pgd_bad(pgd_t pgd)
9678 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9679 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9682 static inline int pgd_none(pgd_t pgd)
9683 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
9684 * pgd_offset() returns a (pgd_t *)
9685 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9687 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9688 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9690 +#ifdef CONFIG_PAX_PER_CPU_PGD
9691 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9695 * a shortcut which implies the use of the kernel's pgd, instead
9697 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
9698 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9699 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9701 +#ifdef CONFIG_X86_32
9702 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9704 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9705 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9708 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9710 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9715 #ifndef __ASSEMBLY__
9717 extern int direct_gbpages;
9718 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
9719 * dst and src can be on the same page, but the range must not overlap,
9720 * and must not cross a page boundary.
9722 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9723 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9725 - memcpy(dst, src, count * sizeof(pgd_t));
9726 + pax_open_kernel();
9729 + pax_close_kernel();
9732 +#ifdef CONFIG_PAX_PER_CPU_PGD
9733 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9736 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9737 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9739 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9742 #include <asm-generic/pgtable.h>
9743 #endif /* __ASSEMBLY__ */
9744 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
9745 index 0c92113..34a77c6 100644
9746 --- a/arch/x86/include/asm/pgtable_32.h
9747 +++ b/arch/x86/include/asm/pgtable_32.h
9750 struct vm_area_struct;
9752 -extern pgd_t swapper_pg_dir[1024];
9753 -extern pgd_t initial_page_table[1024];
9755 static inline void pgtable_cache_init(void) { }
9756 static inline void check_pgt_cache(void) { }
9757 void paging_init(void);
9758 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9759 # include <asm/pgtable-2level.h>
9762 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9763 +extern pgd_t initial_page_table[PTRS_PER_PGD];
9764 +#ifdef CONFIG_X86_PAE
9765 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9768 #if defined(CONFIG_HIGHPTE)
9769 #define pte_offset_map(dir, address) \
9770 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
9771 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9772 /* Clear a kernel PTE and flush it from the TLB */
9773 #define kpte_clear_flush(ptep, vaddr) \
9775 + pax_open_kernel(); \
9776 pte_clear(&init_mm, (vaddr), (ptep)); \
9777 + pax_close_kernel(); \
9778 __flush_tlb_one((vaddr)); \
9781 @@ -74,6 +79,9 @@ do { \
9783 #endif /* !__ASSEMBLY__ */
9785 +#define HAVE_ARCH_UNMAPPED_AREA
9786 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9789 * kern_addr_valid() is (1) for FLATMEM and (0) for
9790 * SPARSEMEM and DISCONTIGMEM
9791 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
9792 index ed5903b..c7fe163 100644
9793 --- a/arch/x86/include/asm/pgtable_32_types.h
9794 +++ b/arch/x86/include/asm/pgtable_32_types.h
9797 #ifdef CONFIG_X86_PAE
9798 # include <asm/pgtable-3level_types.h>
9799 -# define PMD_SIZE (1UL << PMD_SHIFT)
9800 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9801 # define PMD_MASK (~(PMD_SIZE - 1))
9803 # include <asm/pgtable-2level_types.h>
9804 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
9805 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9808 +#ifdef CONFIG_PAX_KERNEXEC
9809 +#ifndef __ASSEMBLY__
9810 +extern unsigned char MODULES_EXEC_VADDR[];
9811 +extern unsigned char MODULES_EXEC_END[];
9813 +#include <asm/boot.h>
9814 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9815 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9817 +#define ktla_ktva(addr) (addr)
9818 +#define ktva_ktla(addr) (addr)
9821 #define MODULES_VADDR VMALLOC_START
9822 #define MODULES_END VMALLOC_END
9823 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9824 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
9825 index 975f709..107976d 100644
9826 --- a/arch/x86/include/asm/pgtable_64.h
9827 +++ b/arch/x86/include/asm/pgtable_64.h
9830 extern pud_t level3_kernel_pgt[512];
9831 extern pud_t level3_ident_pgt[512];
9832 +extern pud_t level3_vmalloc_start_pgt[512];
9833 +extern pud_t level3_vmalloc_end_pgt[512];
9834 +extern pud_t level3_vmemmap_pgt[512];
9835 +extern pud_t level2_vmemmap_pgt[512];
9836 extern pmd_t level2_kernel_pgt[512];
9837 extern pmd_t level2_fixmap_pgt[512];
9838 -extern pmd_t level2_ident_pgt[512];
9839 -extern pgd_t init_level4_pgt[];
9840 +extern pmd_t level2_ident_pgt[512*2];
9841 +extern pgd_t init_level4_pgt[512];
9843 #define swapper_pg_dir init_level4_pgt
9845 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9847 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9849 + pax_open_kernel();
9851 + pax_close_kernel();
9854 static inline void native_pmd_clear(pmd_t *pmd)
9855 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
9857 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9859 + pax_open_kernel();
9861 + pax_close_kernel();
9864 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9869 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
9870 index 766ea16..5b96cb3 100644
9871 --- a/arch/x86/include/asm/pgtable_64_types.h
9872 +++ b/arch/x86/include/asm/pgtable_64_types.h
9873 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9874 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9875 #define MODULES_END _AC(0xffffffffff000000, UL)
9876 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9877 +#define MODULES_EXEC_VADDR MODULES_VADDR
9878 +#define MODULES_EXEC_END MODULES_END
9880 +#define ktla_ktva(addr) (addr)
9881 +#define ktva_ktla(addr) (addr)
9883 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9884 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
9885 index 013286a..8b42f4f 100644
9886 --- a/arch/x86/include/asm/pgtable_types.h
9887 +++ b/arch/x86/include/asm/pgtable_types.h
9889 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9890 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9891 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9892 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9893 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9894 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9895 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9896 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9897 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9898 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9899 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
9900 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9901 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
9902 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9904 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9906 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9907 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9908 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9909 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9910 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9911 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9912 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9915 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9916 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9918 +#elif defined(CONFIG_KMEMCHECK)
9919 #define _PAGE_NX (_AT(pteval_t, 0))
9921 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9924 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9926 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9929 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
9930 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
9932 #define __PAGE_KERNEL_EXEC \
9933 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9934 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9936 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9937 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9938 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9939 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9940 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9941 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
9942 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
9943 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9945 * bits are combined, this will alow user to access the high address mapped
9946 * VDSO in the presence of CONFIG_COMPAT_VDSO
9948 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9949 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9950 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9951 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9952 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9955 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
9957 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9961 +#if PAGETABLE_LEVELS == 3
9962 +#include <asm-generic/pgtable-nopud.h>
9965 +#if PAGETABLE_LEVELS == 2
9966 +#include <asm-generic/pgtable-nopmd.h>
9969 +#ifndef __ASSEMBLY__
9970 #if PAGETABLE_LEVELS > 3
9971 typedef struct { pudval_t pud; } pud_t;
9973 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
9977 -#include <asm-generic/pgtable-nopud.h>
9979 static inline pudval_t native_pud_val(pud_t pud)
9981 return native_pgd_val(pud.pgd);
9982 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
9986 -#include <asm-generic/pgtable-nopmd.h>
9988 static inline pmdval_t native_pmd_val(pmd_t pmd)
9990 return native_pgd_val(pmd.pud.pgd);
9991 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
9993 extern pteval_t __supported_pte_mask;
9994 extern void set_nx(void);
9995 -extern int nx_enabled;
9997 #define pgprot_writecombine pgprot_writecombine
9998 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9999 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
10000 index bb3ee36..781a6b8 100644
10001 --- a/arch/x86/include/asm/processor.h
10002 +++ b/arch/x86/include/asm/processor.h
10003 @@ -268,7 +268,7 @@ struct tss_struct {
10005 } ____cacheline_aligned;
10007 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
10008 +extern struct tss_struct init_tss[NR_CPUS];
10011 * Save the original ist values for checking stack pointers during debugging
10012 @@ -861,11 +861,18 @@ static inline void spin_lock_prefetch(const void *x)
10014 #define TASK_SIZE PAGE_OFFSET
10015 #define TASK_SIZE_MAX TASK_SIZE
10017 +#ifdef CONFIG_PAX_SEGMEXEC
10018 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
10019 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
10021 #define STACK_TOP TASK_SIZE
10022 -#define STACK_TOP_MAX STACK_TOP
10025 +#define STACK_TOP_MAX TASK_SIZE
10027 #define INIT_THREAD { \
10028 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10029 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10030 .vm86_info = NULL, \
10031 .sysenter_cs = __KERNEL_CS, \
10032 .io_bitmap_ptr = NULL, \
10033 @@ -879,7 +886,7 @@ static inline void spin_lock_prefetch(const void *x)
10035 #define INIT_TSS { \
10037 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
10038 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
10039 .ss0 = __KERNEL_DS, \
10040 .ss1 = __KERNEL_CS, \
10041 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
10042 @@ -890,11 +897,7 @@ static inline void spin_lock_prefetch(const void *x)
10043 extern unsigned long thread_saved_pc(struct task_struct *tsk);
10045 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
10046 -#define KSTK_TOP(info) \
10048 - unsigned long *__ptr = (unsigned long *)(info); \
10049 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
10051 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
10054 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
10055 @@ -909,7 +912,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
10056 #define task_pt_regs(task) \
10058 struct pt_regs *__regs__; \
10059 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
10060 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
10064 @@ -919,13 +922,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
10066 * User space process size. 47bits minus one guard page.
10068 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
10069 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
10071 /* This decides where the kernel will search for a free chunk of vm
10072 * space during mmap's.
10074 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
10075 - 0xc0000000 : 0xFFFFe000)
10076 + 0xc0000000 : 0xFFFFf000)
10078 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10079 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10080 @@ -936,11 +939,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
10081 #define STACK_TOP_MAX TASK_SIZE_MAX
10083 #define INIT_THREAD { \
10084 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10085 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10088 #define INIT_TSS { \
10089 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10090 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10094 @@ -962,6 +965,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
10096 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
10098 +#ifdef CONFIG_PAX_SEGMEXEC
10099 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
10102 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
10104 /* Get/set a process' ability to use the timestamp counter instruction */
10105 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
10106 index 3566454..4bdfb8c 100644
10107 --- a/arch/x86/include/asm/ptrace.h
10108 +++ b/arch/x86/include/asm/ptrace.h
10109 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
10113 - * user_mode_vm(regs) determines whether a register set came from user mode.
10114 + * user_mode(regs) determines whether a register set came from user mode.
10115 * This is true if V8086 mode was enabled OR if the register set was from
10116 * protected mode with RPL-3 CS value. This tricky test checks that with
10117 * one comparison. Many places in the kernel can bypass this full check
10118 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
10119 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
10122 -static inline int user_mode(struct pt_regs *regs)
10123 +static inline int user_mode_novm(struct pt_regs *regs)
10125 #ifdef CONFIG_X86_32
10126 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
10128 - return !!(regs->cs & 3);
10129 + return !!(regs->cs & SEGMENT_RPL_MASK);
10133 -static inline int user_mode_vm(struct pt_regs *regs)
10134 +static inline int user_mode(struct pt_regs *regs)
10136 #ifdef CONFIG_X86_32
10137 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
10140 - return user_mode(regs);
10141 + return user_mode_novm(regs);
10145 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
10146 #ifdef CONFIG_X86_64
10147 static inline bool user_64bit_mode(struct pt_regs *regs)
10149 + unsigned long cs = regs->cs & 0xffff;
10150 #ifndef CONFIG_PARAVIRT
10152 * On non-paravirt systems, this is the only long mode CPL 3
10153 * selector. We do not allow long mode selectors in the LDT.
10155 - return regs->cs == __USER_CS;
10156 + return cs == __USER_CS;
10158 /* Headers are too twisted for this to go in paravirt.h. */
10159 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
10160 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
10164 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
10165 index 92f29706..a79cbbb 100644
10166 --- a/arch/x86/include/asm/reboot.h
10167 +++ b/arch/x86/include/asm/reboot.h
10171 struct machine_ops {
10172 - void (*restart)(char *cmd);
10173 - void (*halt)(void);
10174 - void (*power_off)(void);
10175 + void (* __noreturn restart)(char *cmd);
10176 + void (* __noreturn halt)(void);
10177 + void (* __noreturn power_off)(void);
10178 void (*shutdown)(void);
10179 void (*crash_shutdown)(struct pt_regs *);
10180 - void (*emergency_restart)(void);
10182 + void (* __noreturn emergency_restart)(void);
10185 extern struct machine_ops machine_ops;
10187 void native_machine_crash_shutdown(struct pt_regs *regs);
10188 void native_machine_shutdown(void);
10189 -void machine_real_restart(unsigned int type);
10190 +void machine_real_restart(unsigned int type) __noreturn;
10191 /* These must match dispatch_table in reboot_32.S */
10194 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
10195 index 2dbe4a7..ce1db00 100644
10196 --- a/arch/x86/include/asm/rwsem.h
10197 +++ b/arch/x86/include/asm/rwsem.h
10198 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
10200 asm volatile("# beginning down_read\n\t"
10201 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10203 +#ifdef CONFIG_PAX_REFCOUNT
10205 + LOCK_PREFIX _ASM_DEC "(%1)\n"
10207 + _ASM_EXTABLE(0b, 0b)
10210 /* adds 0x00000001 */
10212 " call call_rwsem_down_read_failed\n"
10213 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
10218 +#ifdef CONFIG_PAX_REFCOUNT
10222 + _ASM_EXTABLE(0b, 0b)
10226 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10228 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
10230 asm volatile("# beginning down_write\n\t"
10231 LOCK_PREFIX " xadd %1,(%2)\n\t"
10233 +#ifdef CONFIG_PAX_REFCOUNT
10237 + _ASM_EXTABLE(0b, 0b)
10240 /* adds 0xffff0001, returns the old value */
10242 /* was the count 0 before? */
10243 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
10245 asm volatile("# beginning __up_read\n\t"
10246 LOCK_PREFIX " xadd %1,(%2)\n\t"
10248 +#ifdef CONFIG_PAX_REFCOUNT
10252 + _ASM_EXTABLE(0b, 0b)
10255 /* subtracts 1, returns the old value */
10257 " call call_rwsem_wake\n" /* expects old value in %edx */
10258 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
10260 asm volatile("# beginning __up_write\n\t"
10261 LOCK_PREFIX " xadd %1,(%2)\n\t"
10263 +#ifdef CONFIG_PAX_REFCOUNT
10267 + _ASM_EXTABLE(0b, 0b)
10270 /* subtracts 0xffff0001, returns the old value */
10272 " call call_rwsem_wake\n" /* expects old value in %edx */
10273 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
10275 asm volatile("# beginning __downgrade_write\n\t"
10276 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
10278 +#ifdef CONFIG_PAX_REFCOUNT
10280 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
10282 + _ASM_EXTABLE(0b, 0b)
10286 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
10287 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
10288 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
10290 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
10292 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
10293 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
10295 +#ifdef CONFIG_PAX_REFCOUNT
10297 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
10299 + _ASM_EXTABLE(0b, 0b)
10302 : "+m" (sem->count)
10305 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
10307 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
10309 - return delta + xadd(&sem->count, delta);
10310 + return delta + xadd_check_overflow(&sem->count, delta);
10313 #endif /* __KERNEL__ */
10314 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
10315 index 5e64171..f58957e 100644
10316 --- a/arch/x86/include/asm/segment.h
10317 +++ b/arch/x86/include/asm/segment.h
10318 @@ -64,10 +64,15 @@
10319 * 26 - ESPFIX small SS
10320 * 27 - per-cpu [ offset to per-cpu data area ]
10321 * 28 - stack_canary-20 [ for stack protector ]
10324 + * 29 - PCI BIOS CS
10325 + * 30 - PCI BIOS DS
10326 * 31 - TSS for double fault handler
10328 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
10329 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
10330 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
10331 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
10333 #define GDT_ENTRY_TLS_MIN 6
10334 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
10338 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
10340 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
10342 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
10344 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
10345 @@ -104,6 +111,12 @@
10346 #define __KERNEL_STACK_CANARY 0
10349 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
10350 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
10352 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
10353 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
10355 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
10358 @@ -141,7 +154,7 @@
10361 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
10362 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
10363 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
10367 @@ -165,6 +178,8 @@
10368 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
10369 #define __USER32_DS __USER_DS
10371 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
10373 #define GDT_ENTRY_TSS 8 /* needs two entries */
10374 #define GDT_ENTRY_LDT 10 /* needs two entries */
10375 #define GDT_ENTRY_TLS_MIN 12
10376 @@ -185,6 +200,7 @@
10379 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
10380 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
10381 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
10382 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
10383 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
10384 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
10385 index 73b11bc..d4a3b63 100644
10386 --- a/arch/x86/include/asm/smp.h
10387 +++ b/arch/x86/include/asm/smp.h
10388 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
10389 /* cpus sharing the last level cache: */
10390 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
10391 DECLARE_PER_CPU(u16, cpu_llc_id);
10392 -DECLARE_PER_CPU(int, cpu_number);
10393 +DECLARE_PER_CPU(unsigned int, cpu_number);
10395 static inline struct cpumask *cpu_sibling_mask(int cpu)
10397 @@ -77,7 +77,7 @@ struct smp_ops {
10399 void (*send_call_func_ipi)(const struct cpumask *mask);
10400 void (*send_call_func_single_ipi)(int cpu);
10404 /* Globals due to paravirt */
10405 extern void set_cpu_sibling_map(int cpu);
10406 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
10407 extern int safe_smp_processor_id(void);
10409 #elif defined(CONFIG_X86_64_SMP)
10410 -#define raw_smp_processor_id() (percpu_read(cpu_number))
10412 -#define stack_smp_processor_id() \
10414 - struct thread_info *ti; \
10415 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
10418 +#define raw_smp_processor_id() (percpu_read(cpu_number))
10419 +#define stack_smp_processor_id() raw_smp_processor_id()
10420 #define safe_smp_processor_id() smp_processor_id()
10423 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
10424 index 972c260..43ab1fd 100644
10425 --- a/arch/x86/include/asm/spinlock.h
10426 +++ b/arch/x86/include/asm/spinlock.h
10427 @@ -188,6 +188,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
10428 static inline void arch_read_lock(arch_rwlock_t *rw)
10430 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
10432 +#ifdef CONFIG_PAX_REFCOUNT
10434 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
10436 + _ASM_EXTABLE(0b, 0b)
10440 "call __read_lock_failed\n\t"
10442 @@ -197,6 +205,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
10443 static inline void arch_write_lock(arch_rwlock_t *rw)
10445 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
10447 +#ifdef CONFIG_PAX_REFCOUNT
10449 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
10451 + _ASM_EXTABLE(0b, 0b)
10455 "call __write_lock_failed\n\t"
10457 @@ -226,13 +242,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
10459 static inline void arch_read_unlock(arch_rwlock_t *rw)
10461 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
10462 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
10464 +#ifdef CONFIG_PAX_REFCOUNT
10466 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
10468 + _ASM_EXTABLE(0b, 0b)
10471 :"+m" (rw->lock) : : "memory");
10474 static inline void arch_write_unlock(arch_rwlock_t *rw)
10476 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
10477 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
10479 +#ifdef CONFIG_PAX_REFCOUNT
10481 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
10483 + _ASM_EXTABLE(0b, 0b)
10486 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
10489 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
10490 index 1575177..cb23f52 100644
10491 --- a/arch/x86/include/asm/stackprotector.h
10492 +++ b/arch/x86/include/asm/stackprotector.h
10494 * head_32 for boot CPU and setup_per_cpu_areas() for others.
10496 #define GDT_STACK_CANARY_INIT \
10497 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
10498 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
10501 * Initialize the stackprotector canary value.
10502 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
10504 static inline void load_stack_canary_segment(void)
10506 -#ifdef CONFIG_X86_32
10507 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
10508 asm volatile ("mov %0, %%gs" : : "r" (0));
10511 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
10512 index 70bbe39..4ae2bd4 100644
10513 --- a/arch/x86/include/asm/stacktrace.h
10514 +++ b/arch/x86/include/asm/stacktrace.h
10515 @@ -11,28 +11,20 @@
10517 extern int kstack_depth_to_print;
10519 -struct thread_info;
10520 +struct task_struct;
10521 struct stacktrace_ops;
10523 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
10524 - unsigned long *stack,
10525 - unsigned long bp,
10526 - const struct stacktrace_ops *ops,
10528 - unsigned long *end,
10530 +typedef unsigned long walk_stack_t(struct task_struct *task,
10531 + void *stack_start,
10532 + unsigned long *stack,
10533 + unsigned long bp,
10534 + const struct stacktrace_ops *ops,
10536 + unsigned long *end,
10539 -extern unsigned long
10540 -print_context_stack(struct thread_info *tinfo,
10541 - unsigned long *stack, unsigned long bp,
10542 - const struct stacktrace_ops *ops, void *data,
10543 - unsigned long *end, int *graph);
10545 -extern unsigned long
10546 -print_context_stack_bp(struct thread_info *tinfo,
10547 - unsigned long *stack, unsigned long bp,
10548 - const struct stacktrace_ops *ops, void *data,
10549 - unsigned long *end, int *graph);
10550 +extern walk_stack_t print_context_stack;
10551 +extern walk_stack_t print_context_stack_bp;
10553 /* Generic stack tracer with callbacks */
10555 @@ -40,7 +32,7 @@ struct stacktrace_ops {
10556 void (*address)(void *data, unsigned long address, int reliable);
10557 /* On negative return stop dumping */
10558 int (*stack)(void *data, char *name);
10559 - walk_stack_t walk_stack;
10560 + walk_stack_t *walk_stack;
10563 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
10564 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
10565 index cb23852..2dde194 100644
10566 --- a/arch/x86/include/asm/sys_ia32.h
10567 +++ b/arch/x86/include/asm/sys_ia32.h
10568 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
10569 compat_sigset_t __user *, unsigned int);
10570 asmlinkage long sys32_alarm(unsigned int);
10572 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
10573 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
10574 asmlinkage long sys32_sysfs(int, u32, u32);
10576 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
10577 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
10578 index 2d2f01c..f985723 100644
10579 --- a/arch/x86/include/asm/system.h
10580 +++ b/arch/x86/include/asm/system.h
10581 @@ -129,7 +129,7 @@ do { \
10582 "call __switch_to\n\t" \
10583 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
10585 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
10586 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
10587 "movq %%rax,%%rdi\n\t" \
10588 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
10589 "jnz ret_from_fork\n\t" \
10590 @@ -140,7 +140,7 @@ do { \
10591 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
10592 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
10593 [_tif_fork] "i" (_TIF_FORK), \
10594 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
10595 + [thread_info] "m" (current_tinfo), \
10596 [current_task] "m" (current_task) \
10597 __switch_canary_iparam \
10598 : "memory", "cc" __EXTRA_CLOBBER)
10599 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
10601 unsigned long __limit;
10602 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
10603 - return __limit + 1;
10607 static inline void native_clts(void)
10608 @@ -397,13 +397,13 @@ void enable_hlt(void);
10610 void cpu_idle_wait(void);
10612 -extern unsigned long arch_align_stack(unsigned long sp);
10613 +#define arch_align_stack(x) ((x) & ~0xfUL)
10614 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
10616 void default_idle(void);
10617 bool set_pm_idle_to_default(void);
10619 -void stop_this_cpu(void *dummy);
10620 +void stop_this_cpu(void *dummy) __noreturn;
10623 * Force strict CPU ordering.
10624 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
10625 index d7ef849..6af292e 100644
10626 --- a/arch/x86/include/asm/thread_info.h
10627 +++ b/arch/x86/include/asm/thread_info.h
10629 #include <linux/compiler.h>
10630 #include <asm/page.h>
10631 #include <asm/types.h>
10632 +#include <asm/percpu.h>
10635 * low level task data that entry.S needs immediate access to
10636 @@ -24,7 +25,6 @@ struct exec_domain;
10637 #include <linux/atomic.h>
10639 struct thread_info {
10640 - struct task_struct *task; /* main task structure */
10641 struct exec_domain *exec_domain; /* execution domain */
10642 __u32 flags; /* low level flags */
10643 __u32 status; /* thread synchronous flags */
10644 @@ -34,18 +34,12 @@ struct thread_info {
10645 mm_segment_t addr_limit;
10646 struct restart_block restart_block;
10647 void __user *sysenter_return;
10648 -#ifdef CONFIG_X86_32
10649 - unsigned long previous_esp; /* ESP of the previous stack in
10650 - case of nested (IRQ) stacks
10652 - __u8 supervisor_stack[0];
10654 + unsigned long lowest_stack;
10658 -#define INIT_THREAD_INFO(tsk) \
10659 +#define INIT_THREAD_INFO \
10662 .exec_domain = &default_exec_domain, \
10665 @@ -56,7 +50,7 @@ struct thread_info {
10669 -#define init_thread_info (init_thread_union.thread_info)
10670 +#define init_thread_info (init_thread_union.stack)
10671 #define init_stack (init_thread_union.stack)
10673 #else /* !__ASSEMBLY__ */
10674 @@ -170,45 +164,40 @@ struct thread_info {
10678 -#ifdef CONFIG_X86_32
10680 -#define STACK_WARN (THREAD_SIZE/8)
10682 - * macros/functions for gaining access to the thread information structure
10684 - * preempt_count needs to be 1 initially, until the scheduler is functional.
10686 -#ifndef __ASSEMBLY__
10689 -/* how to get the current stack pointer from C */
10690 -register unsigned long current_stack_pointer asm("esp") __used;
10692 -/* how to get the thread information struct from C */
10693 -static inline struct thread_info *current_thread_info(void)
10695 - return (struct thread_info *)
10696 - (current_stack_pointer & ~(THREAD_SIZE - 1));
10699 -#else /* !__ASSEMBLY__ */
10701 +#ifdef __ASSEMBLY__
10702 /* how to get the thread information struct from ASM */
10703 #define GET_THREAD_INFO(reg) \
10704 - movl $-THREAD_SIZE, reg; \
10706 + mov PER_CPU_VAR(current_tinfo), reg
10708 /* use this one if reg already contains %esp */
10709 -#define GET_THREAD_INFO_WITH_ESP(reg) \
10710 - andl $-THREAD_SIZE, reg
10711 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10713 +/* how to get the thread information struct from C */
10714 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10716 +static __always_inline struct thread_info *current_thread_info(void)
10718 + return percpu_read_stable(current_tinfo);
10722 +#ifdef CONFIG_X86_32
10724 +#define STACK_WARN (THREAD_SIZE/8)
10726 + * macros/functions for gaining access to the thread information structure
10728 + * preempt_count needs to be 1 initially, until the scheduler is functional.
10730 +#ifndef __ASSEMBLY__
10732 +/* how to get the current stack pointer from C */
10733 +register unsigned long current_stack_pointer asm("esp") __used;
10739 -#include <asm/percpu.h>
10740 -#define KERNEL_STACK_OFFSET (5*8)
10743 * macros/functions for gaining access to the thread information structure
10744 * preempt_count needs to be 1 initially, until the scheduler is functional.
10745 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
10746 #ifndef __ASSEMBLY__
10747 DECLARE_PER_CPU(unsigned long, kernel_stack);
10749 -static inline struct thread_info *current_thread_info(void)
10751 - struct thread_info *ti;
10752 - ti = (void *)(percpu_read_stable(kernel_stack) +
10753 - KERNEL_STACK_OFFSET - THREAD_SIZE);
10757 -#else /* !__ASSEMBLY__ */
10759 -/* how to get the thread information struct from ASM */
10760 -#define GET_THREAD_INFO(reg) \
10761 - movq PER_CPU_VAR(kernel_stack),reg ; \
10762 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10764 +/* how to get the current stack pointer from C */
10765 +register unsigned long current_stack_pointer asm("rsp") __used;
10768 #endif /* !X86_32 */
10769 @@ -264,5 +240,16 @@ extern void arch_task_cache_init(void);
10770 extern void free_thread_info(struct thread_info *ti);
10771 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10772 #define arch_task_cache_init arch_task_cache_init
10774 +#define __HAVE_THREAD_FUNCTIONS
10775 +#define task_thread_info(task) (&(task)->tinfo)
10776 +#define task_stack_page(task) ((task)->stack)
10777 +#define setup_thread_stack(p, org) do {} while (0)
10778 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10780 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10781 +extern struct task_struct *alloc_task_struct_node(int node);
10782 +extern void free_task_struct(struct task_struct *);
10785 #endif /* _ASM_X86_THREAD_INFO_H */
10786 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
10787 index 36361bf..324f262 100644
10788 --- a/arch/x86/include/asm/uaccess.h
10789 +++ b/arch/x86/include/asm/uaccess.h
10791 #include <linux/compiler.h>
10792 #include <linux/thread_info.h>
10793 #include <linux/string.h>
10794 +#include <linux/sched.h>
10795 #include <asm/asm.h>
10796 #include <asm/page.h>
10798 #define VERIFY_READ 0
10799 #define VERIFY_WRITE 1
10801 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
10804 * The fs value determines whether argument validity checking should be
10805 * performed or not. If get_fs() == USER_DS, checking is performed, with
10808 #define get_ds() (KERNEL_DS)
10809 #define get_fs() (current_thread_info()->addr_limit)
10810 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10811 +void __set_fs(mm_segment_t x);
10812 +void set_fs(mm_segment_t x);
10814 #define set_fs(x) (current_thread_info()->addr_limit = (x))
10817 #define segment_eq(a, b) ((a).seg == (b).seg)
10820 * checks that the pointer is in the user space range - after calling
10821 * this function, memory access functions may still return -EFAULT.
10823 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10824 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10825 +#define access_ok(type, addr, size) \
10827 + long __size = size; \
10828 + unsigned long __addr = (unsigned long)addr; \
10829 + unsigned long __addr_ao = __addr & PAGE_MASK; \
10830 + unsigned long __end_ao = __addr + __size - 1; \
10831 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
10832 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
10833 + while(__addr_ao <= __end_ao) { \
10835 + __addr_ao += PAGE_SIZE; \
10836 + if (__size > PAGE_SIZE) \
10837 + cond_resched(); \
10838 + if (__get_user(__c_ao, (char __user *)__addr)) \
10840 + if (type != VERIFY_WRITE) { \
10841 + __addr = __addr_ao; \
10844 + if (__put_user(__c_ao, (char __user *)__addr)) \
10846 + __addr = __addr_ao; \
10853 * The exception table consists of pairs of addresses: the first is the
10854 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
10855 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
10856 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
10859 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10860 +#define __copyuser_seg "gs;"
10861 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
10862 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
10864 +#define __copyuser_seg
10865 +#define __COPYUSER_SET_ES
10866 +#define __COPYUSER_RESTORE_ES
10869 #ifdef CONFIG_X86_32
10870 #define __put_user_asm_u64(x, addr, err, errret) \
10871 - asm volatile("1: movl %%eax,0(%2)\n" \
10872 - "2: movl %%edx,4(%2)\n" \
10873 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
10874 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
10876 ".section .fixup,\"ax\"\n" \
10877 "4: movl %3,%0\n" \
10878 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
10879 : "A" (x), "r" (addr), "i" (errret), "0" (err))
10881 #define __put_user_asm_ex_u64(x, addr) \
10882 - asm volatile("1: movl %%eax,0(%1)\n" \
10883 - "2: movl %%edx,4(%1)\n" \
10884 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
10885 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
10887 _ASM_EXTABLE(1b, 2b - 1b) \
10888 _ASM_EXTABLE(2b, 3b - 2b) \
10889 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
10890 __typeof__(*(ptr)) __pu_val; \
10891 __chk_user_ptr(ptr); \
10894 + __pu_val = (x); \
10895 switch (sizeof(*(ptr))) { \
10897 __put_user_x(1, __pu_val, ptr, __ret_pu); \
10898 @@ -373,7 +415,7 @@ do { \
10901 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10902 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
10903 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
10905 ".section .fixup,\"ax\"\n" \
10907 @@ -381,7 +423,7 @@ do { \
10910 _ASM_EXTABLE(1b, 3b) \
10911 - : "=r" (err), ltype(x) \
10912 + : "=r" (err), ltype (x) \
10913 : "m" (__m(addr)), "i" (errret), "0" (err))
10915 #define __get_user_size_ex(x, ptr, size) \
10916 @@ -406,7 +448,7 @@ do { \
10919 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
10920 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
10921 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
10923 _ASM_EXTABLE(1b, 2b - 1b) \
10924 : ltype(x) : "m" (__m(addr)))
10925 @@ -423,13 +465,24 @@ do { \
10927 unsigned long __gu_val; \
10928 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
10929 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
10930 + (x) = (__typeof__(*(ptr)))__gu_val; \
10934 /* FIXME: this hack is definitely wrong -AK */
10935 struct __large_struct { unsigned long buf[100]; };
10936 -#define __m(x) (*(struct __large_struct __user *)(x))
10937 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10938 +#define ____m(x) \
10940 + unsigned long ____x = (unsigned long)(x); \
10941 + if (____x < PAX_USER_SHADOW_BASE) \
10942 + ____x += PAX_USER_SHADOW_BASE; \
10943 + (void __user *)____x; \
10946 +#define ____m(x) (x)
10948 +#define __m(x) (*(struct __large_struct __user *)____m(x))
10951 * Tell gcc we read from memory instead of writing: this is because
10952 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
10955 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10956 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
10957 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
10959 ".section .fixup,\"ax\"\n" \
10961 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
10963 _ASM_EXTABLE(1b, 3b) \
10965 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
10966 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
10968 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
10969 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
10970 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
10972 _ASM_EXTABLE(1b, 2b - 1b) \
10973 : : ltype(x), "m" (__m(addr)))
10974 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
10975 * On error, the variable @x is set to zero.
10978 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10979 +#define __get_user(x, ptr) get_user((x), (ptr))
10981 #define __get_user(x, ptr) \
10982 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
10986 * __put_user: - Write a simple value into user space, with less checking.
10987 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
10988 * Returns zero on success, or -EFAULT on error.
10991 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10992 +#define __put_user(x, ptr) put_user((x), (ptr))
10994 #define __put_user(x, ptr) \
10995 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
10998 #define __get_user_unaligned __get_user
10999 #define __put_user_unaligned __put_user
11000 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
11001 #define get_user_ex(x, ptr) do { \
11002 unsigned long __gue_val; \
11003 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
11004 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
11005 + (x) = (__typeof__(*(ptr)))__gue_val; \
11008 #ifdef CONFIG_X86_WP_WORKS_OK
11009 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
11010 index 566e803..b9521e9 100644
11011 --- a/arch/x86/include/asm/uaccess_32.h
11012 +++ b/arch/x86/include/asm/uaccess_32.h
11013 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
11014 static __always_inline unsigned long __must_check
11015 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11020 if (__builtin_constant_p(n)) {
11023 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
11027 + if (!__builtin_constant_p(n))
11028 + check_object_size(from, n, true);
11029 return __copy_to_user_ll(to, from, n);
11032 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
11033 __copy_to_user(void __user *to, const void *from, unsigned long n)
11037 return __copy_to_user_inatomic(to, from, n);
11040 static __always_inline unsigned long
11041 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
11046 /* Avoid zeroing the tail if the copy fails..
11047 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
11048 * but as the zeroing behaviour is only significant when n is not
11049 @@ -137,6 +146,10 @@ static __always_inline unsigned long
11050 __copy_from_user(void *to, const void __user *from, unsigned long n)
11057 if (__builtin_constant_p(n)) {
11060 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
11064 + if (!__builtin_constant_p(n))
11065 + check_object_size(to, n, false);
11066 return __copy_from_user_ll(to, from, n);
11069 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
11070 const void __user *from, unsigned long n)
11077 if (__builtin_constant_p(n)) {
11080 @@ -181,15 +200,19 @@ static __always_inline unsigned long
11081 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11084 - return __copy_from_user_ll_nocache_nozero(to, from, n);
11088 + return __copy_from_user_ll_nocache_nozero(to, from, n);
11091 -unsigned long __must_check copy_to_user(void __user *to,
11092 - const void *from, unsigned long n);
11093 -unsigned long __must_check _copy_from_user(void *to,
11094 - const void __user *from,
11095 - unsigned long n);
11097 +extern void copy_to_user_overflow(void)
11098 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11099 + __compiletime_error("copy_to_user() buffer size is not provably correct")
11101 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
11105 extern void copy_from_user_overflow(void)
11106 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11107 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
11111 -static inline unsigned long __must_check copy_from_user(void *to,
11112 - const void __user *from,
11115 + * copy_to_user: - Copy a block of data into user space.
11116 + * @to: Destination address, in user space.
11117 + * @from: Source address, in kernel space.
11118 + * @n: Number of bytes to copy.
11120 + * Context: User context only. This function may sleep.
11122 + * Copy data from kernel space to user space.
11124 + * Returns number of bytes that could not be copied.
11125 + * On success, this will be zero.
11127 +static inline unsigned long __must_check
11128 +copy_to_user(void __user *to, const void *from, unsigned long n)
11130 + int sz = __compiletime_object_size(from);
11132 + if (unlikely(sz != -1 && sz < n))
11133 + copy_to_user_overflow();
11134 + else if (access_ok(VERIFY_WRITE, to, n))
11135 + n = __copy_to_user(to, from, n);
11140 + * copy_from_user: - Copy a block of data from user space.
11141 + * @to: Destination address, in kernel space.
11142 + * @from: Source address, in user space.
11143 + * @n: Number of bytes to copy.
11145 + * Context: User context only. This function may sleep.
11147 + * Copy data from user space to kernel space.
11149 + * Returns number of bytes that could not be copied.
11150 + * On success, this will be zero.
11152 + * If some data could not be copied, this function will pad the copied
11153 + * data to the requested size using zero bytes.
11155 +static inline unsigned long __must_check
11156 +copy_from_user(void *to, const void __user *from, unsigned long n)
11158 int sz = __compiletime_object_size(to);
11160 - if (likely(sz == -1 || sz >= n))
11161 - n = _copy_from_user(to, from, n);
11163 + if (unlikely(sz != -1 && sz < n))
11164 copy_from_user_overflow();
11166 + else if (access_ok(VERIFY_READ, from, n))
11167 + n = __copy_from_user(to, from, n);
11168 + else if ((long)n > 0) {
11169 + if (!__builtin_constant_p(n))
11170 + check_object_size(to, n, false);
11171 + memset(to, 0, n);
11176 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
11177 index 1c66d30..e66922c 100644
11178 --- a/arch/x86/include/asm/uaccess_64.h
11179 +++ b/arch/x86/include/asm/uaccess_64.h
11181 #include <asm/alternative.h>
11182 #include <asm/cpufeature.h>
11183 #include <asm/page.h>
11184 +#include <asm/pgtable.h>
11186 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
11189 * Copy To/From Userspace
11190 @@ -17,12 +20,12 @@
11192 /* Handles exceptions in both to and from, but doesn't do access_ok */
11193 __must_check unsigned long
11194 -copy_user_generic_string(void *to, const void *from, unsigned len);
11195 +copy_user_generic_string(void *to, const void *from, unsigned long len);
11196 __must_check unsigned long
11197 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
11198 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
11200 static __always_inline __must_check unsigned long
11201 -copy_user_generic(void *to, const void *from, unsigned len)
11202 +copy_user_generic(void *to, const void *from, unsigned long len)
11206 @@ -32,142 +35,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
11207 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
11209 "1" (to), "2" (from), "3" (len)
11210 - : "memory", "rcx", "r8", "r9", "r10", "r11");
11211 + : "memory", "rcx", "r8", "r9", "r11");
11215 +static __always_inline __must_check unsigned long
11216 +__copy_to_user(void __user *to, const void *from, unsigned long len);
11217 +static __always_inline __must_check unsigned long
11218 +__copy_from_user(void *to, const void __user *from, unsigned long len);
11219 __must_check unsigned long
11220 -_copy_to_user(void __user *to, const void *from, unsigned len);
11221 -__must_check unsigned long
11222 -_copy_from_user(void *to, const void __user *from, unsigned len);
11223 -__must_check unsigned long
11224 -copy_in_user(void __user *to, const void __user *from, unsigned len);
11225 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
11227 static inline unsigned long __must_check copy_from_user(void *to,
11228 const void __user *from,
11231 - int sz = __compiletime_object_size(to);
11234 - if (likely(sz == -1 || sz >= n))
11235 - n = _copy_from_user(to, from, n);
11236 -#ifdef CONFIG_DEBUG_VM
11238 - WARN(1, "Buffer overflow detected!\n");
11241 + if (access_ok(VERIFY_READ, from, n))
11242 + n = __copy_from_user(to, from, n);
11243 + else if (n < INT_MAX) {
11244 + if (!__builtin_constant_p(n))
11245 + check_object_size(to, n, false);
11246 + memset(to, 0, n);
11251 static __always_inline __must_check
11252 -int copy_to_user(void __user *dst, const void *src, unsigned size)
11253 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
11257 - return _copy_to_user(dst, src, size);
11258 + if (access_ok(VERIFY_WRITE, dst, size))
11259 + size = __copy_to_user(dst, src, size);
11263 static __always_inline __must_check
11264 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
11265 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
11268 + int sz = __compiletime_object_size(dst);
11269 + unsigned ret = 0;
11272 - if (!__builtin_constant_p(size))
11273 - return copy_user_generic(dst, (__force void *)src, size);
11275 + if (size > INT_MAX)
11278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11279 + if (!__access_ok(VERIFY_READ, src, size))
11283 + if (unlikely(sz != -1 && sz < size)) {
11284 +#ifdef CONFIG_DEBUG_VM
11285 + WARN(1, "Buffer overflow detected!\n");
11290 + if (!__builtin_constant_p(size)) {
11291 + check_object_size(dst, size, false);
11293 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11294 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11295 + src += PAX_USER_SHADOW_BASE;
11298 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11301 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11302 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11303 ret, "b", "b", "=q", 1);
11305 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11306 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11307 ret, "w", "w", "=r", 2);
11309 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11310 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11311 ret, "l", "k", "=r", 4);
11313 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11314 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11315 ret, "q", "", "=r", 8);
11318 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11319 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11320 ret, "q", "", "=r", 10);
11323 __get_user_asm(*(u16 *)(8 + (char *)dst),
11324 - (u16 __user *)(8 + (char __user *)src),
11325 + (const u16 __user *)(8 + (const char __user *)src),
11326 ret, "w", "w", "=r", 2);
11329 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11330 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11331 ret, "q", "", "=r", 16);
11334 __get_user_asm(*(u64 *)(8 + (char *)dst),
11335 - (u64 __user *)(8 + (char __user *)src),
11336 + (const u64 __user *)(8 + (const char __user *)src),
11337 ret, "q", "", "=r", 8);
11340 - return copy_user_generic(dst, (__force void *)src, size);
11342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11343 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11344 + src += PAX_USER_SHADOW_BASE;
11347 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11351 static __always_inline __must_check
11352 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11353 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
11356 + int sz = __compiletime_object_size(src);
11357 + unsigned ret = 0;
11360 - if (!__builtin_constant_p(size))
11361 - return copy_user_generic((__force void *)dst, src, size);
11363 + if (size > INT_MAX)
11366 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11367 + if (!__access_ok(VERIFY_WRITE, dst, size))
11371 + if (unlikely(sz != -1 && sz < size)) {
11372 +#ifdef CONFIG_DEBUG_VM
11373 + WARN(1, "Buffer overflow detected!\n");
11378 + if (!__builtin_constant_p(size)) {
11379 + check_object_size(src, size, true);
11381 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11382 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11383 + dst += PAX_USER_SHADOW_BASE;
11386 + return copy_user_generic((__force_kernel void *)dst, src, size);
11389 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11390 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11391 ret, "b", "b", "iq", 1);
11393 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11394 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11395 ret, "w", "w", "ir", 2);
11397 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11398 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11399 ret, "l", "k", "ir", 4);
11401 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11402 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11403 ret, "q", "", "er", 8);
11406 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11407 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11408 ret, "q", "", "er", 10);
11411 asm("":::"memory");
11412 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11413 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11414 ret, "w", "w", "ir", 2);
11417 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11418 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11419 ret, "q", "", "er", 16);
11422 asm("":::"memory");
11423 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11424 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11425 ret, "q", "", "er", 8);
11428 - return copy_user_generic((__force void *)dst, src, size);
11430 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11431 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11432 + dst += PAX_USER_SHADOW_BASE;
11435 + return copy_user_generic((__force_kernel void *)dst, src, size);
11439 static __always_inline __must_check
11440 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11441 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
11444 + unsigned ret = 0;
11447 - if (!__builtin_constant_p(size))
11448 - return copy_user_generic((__force void *)dst,
11449 - (__force void *)src, size);
11451 + if (size > INT_MAX)
11454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11455 + if (!__access_ok(VERIFY_READ, src, size))
11457 + if (!__access_ok(VERIFY_WRITE, dst, size))
11461 + if (!__builtin_constant_p(size)) {
11463 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11464 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11465 + src += PAX_USER_SHADOW_BASE;
11466 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11467 + dst += PAX_USER_SHADOW_BASE;
11470 + return copy_user_generic((__force_kernel void *)dst,
11471 + (__force_kernel const void *)src, size);
11476 - __get_user_asm(tmp, (u8 __user *)src,
11477 + __get_user_asm(tmp, (const u8 __user *)src,
11478 ret, "b", "b", "=q", 1);
11480 __put_user_asm(tmp, (u8 __user *)dst,
11481 @@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11485 - __get_user_asm(tmp, (u16 __user *)src,
11486 + __get_user_asm(tmp, (const u16 __user *)src,
11487 ret, "w", "w", "=r", 2);
11489 __put_user_asm(tmp, (u16 __user *)dst,
11490 @@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11494 - __get_user_asm(tmp, (u32 __user *)src,
11495 + __get_user_asm(tmp, (const u32 __user *)src,
11496 ret, "l", "k", "=r", 4);
11498 __put_user_asm(tmp, (u32 __user *)dst,
11499 @@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11503 - __get_user_asm(tmp, (u64 __user *)src,
11504 + __get_user_asm(tmp, (const u64 __user *)src,
11505 ret, "q", "", "=r", 8);
11507 __put_user_asm(tmp, (u64 __user *)dst,
11508 @@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11512 - return copy_user_generic((__force void *)dst,
11513 - (__force void *)src, size);
11515 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11516 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11517 + src += PAX_USER_SHADOW_BASE;
11518 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11519 + dst += PAX_USER_SHADOW_BASE;
11522 + return copy_user_generic((__force_kernel void *)dst,
11523 + (__force_kernel const void *)src, size);
11527 @@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
11528 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
11530 static __must_check __always_inline int
11531 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11532 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
11534 - return copy_user_generic(dst, (__force const void *)src, size);
11535 + if (size > INT_MAX)
11538 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11539 + if (!__access_ok(VERIFY_READ, src, size))
11542 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11543 + src += PAX_USER_SHADOW_BASE;
11546 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11549 -static __must_check __always_inline int
11550 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
11551 +static __must_check __always_inline unsigned long
11552 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
11554 - return copy_user_generic((__force void *)dst, src, size);
11555 + if (size > INT_MAX)
11558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11559 + if (!__access_ok(VERIFY_WRITE, dst, size))
11562 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11563 + dst += PAX_USER_SHADOW_BASE;
11566 + return copy_user_generic((__force_kernel void *)dst, src, size);
11569 -extern long __copy_user_nocache(void *dst, const void __user *src,
11570 - unsigned size, int zerorest);
11571 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
11572 + unsigned long size, int zerorest);
11575 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
11576 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
11580 + if (size > INT_MAX)
11583 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11584 + if (!__access_ok(VERIFY_READ, src, size))
11588 return __copy_user_nocache(dst, src, size, 1);
11592 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11594 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11595 + unsigned long size)
11597 + if (size > INT_MAX)
11600 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11601 + if (!__access_ok(VERIFY_READ, src, size))
11605 return __copy_user_nocache(dst, src, size, 0);
11609 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
11610 +extern unsigned long
11611 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
11613 #endif /* _ASM_X86_UACCESS_64_H */
11614 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
11615 index bb05228..d763d5b 100644
11616 --- a/arch/x86/include/asm/vdso.h
11617 +++ b/arch/x86/include/asm/vdso.h
11618 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
11619 #define VDSO32_SYMBOL(base, name) \
11621 extern const char VDSO32_##name[]; \
11622 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11623 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11627 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
11628 index 1971e65..1e3559b 100644
11629 --- a/arch/x86/include/asm/x86_init.h
11630 +++ b/arch/x86/include/asm/x86_init.h
11631 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
11632 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
11633 void (*find_smp_config)(void);
11634 void (*get_smp_config)(unsigned int early);
11639 * struct x86_init_resources - platform specific resource related ops
11640 @@ -42,7 +42,7 @@ struct x86_init_resources {
11641 void (*probe_roms)(void);
11642 void (*reserve_resources)(void);
11643 char *(*memory_setup)(void);
11648 * struct x86_init_irqs - platform specific interrupt setup
11649 @@ -55,7 +55,7 @@ struct x86_init_irqs {
11650 void (*pre_vector_init)(void);
11651 void (*intr_init)(void);
11652 void (*trap_init)(void);
11657 * struct x86_init_oem - oem platform specific customizing functions
11658 @@ -65,7 +65,7 @@ struct x86_init_irqs {
11659 struct x86_init_oem {
11660 void (*arch_setup)(void);
11661 void (*banner)(void);
11666 * struct x86_init_mapping - platform specific initial kernel pagetable setup
11667 @@ -76,7 +76,7 @@ struct x86_init_oem {
11669 struct x86_init_mapping {
11670 void (*pagetable_reserve)(u64 start, u64 end);
11675 * struct x86_init_paging - platform specific paging functions
11676 @@ -86,7 +86,7 @@ struct x86_init_mapping {
11677 struct x86_init_paging {
11678 void (*pagetable_setup_start)(pgd_t *base);
11679 void (*pagetable_setup_done)(pgd_t *base);
11684 * struct x86_init_timers - platform specific timer setup
11685 @@ -101,7 +101,7 @@ struct x86_init_timers {
11686 void (*tsc_pre_init)(void);
11687 void (*timer_init)(void);
11688 void (*wallclock_init)(void);
11693 * struct x86_init_iommu - platform specific iommu setup
11694 @@ -109,7 +109,7 @@ struct x86_init_timers {
11696 struct x86_init_iommu {
11697 int (*iommu_init)(void);
11702 * struct x86_init_pci - platform specific pci init functions
11703 @@ -123,7 +123,7 @@ struct x86_init_pci {
11705 void (*init_irq)(void);
11706 void (*fixup_irqs)(void);
11711 * struct x86_init_ops - functions for platform specific setup
11712 @@ -139,7 +139,7 @@ struct x86_init_ops {
11713 struct x86_init_timers timers;
11714 struct x86_init_iommu iommu;
11715 struct x86_init_pci pci;
11720 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
11721 @@ -147,7 +147,7 @@ struct x86_init_ops {
11723 struct x86_cpuinit_ops {
11724 void (*setup_percpu_clockev)(void);
11729 * struct x86_platform_ops - platform specific runtime functions
11730 @@ -169,7 +169,7 @@ struct x86_platform_ops {
11731 void (*nmi_init)(void);
11732 unsigned char (*get_nmi_reason)(void);
11733 int (*i8042_detect)(void);
11739 @@ -177,7 +177,7 @@ struct x86_msi_ops {
11740 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
11741 void (*teardown_msi_irq)(unsigned int irq);
11742 void (*teardown_msi_irqs)(struct pci_dev *dev);
11746 extern struct x86_init_ops x86_init;
11747 extern struct x86_cpuinit_ops x86_cpuinit;
11748 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
11749 index c6ce245..ffbdab7 100644
11750 --- a/arch/x86/include/asm/xsave.h
11751 +++ b/arch/x86/include/asm/xsave.h
11752 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11756 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11757 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
11758 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
11762 * Clear the xsave header first, so that reserved fields are
11763 * initialized to zero.
11764 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11765 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
11768 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
11769 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
11771 u32 hmask = mask >> 32;
11773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11774 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
11775 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
11778 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
11780 ".section .fixup,\"ax\"\n"
11781 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
11782 index 6a564ac..9b1340c 100644
11783 --- a/arch/x86/kernel/acpi/realmode/Makefile
11784 +++ b/arch/x86/kernel/acpi/realmode/Makefile
11785 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
11786 $(call cc-option, -fno-stack-protector) \
11787 $(call cc-option, -mpreferred-stack-boundary=2)
11788 KBUILD_CFLAGS += $(call cc-option, -m32)
11789 +ifdef CONSTIFY_PLUGIN
11790 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
11792 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11795 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
11796 index b4fd836..4358fe3 100644
11797 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
11798 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
11799 @@ -108,6 +108,9 @@ wakeup_code:
11800 /* Do any other stuff... */
11802 #ifndef CONFIG_64BIT
11803 + /* Recheck NX bit overrides (64bit path does this in trampoline */
11806 /* This could also be done in C code... */
11807 movl pmode_cr3, %eax
11809 @@ -131,6 +134,7 @@ wakeup_code:
11810 movl pmode_cr0, %eax
11813 +# include "../../verify_cpu.S"
11816 pushw trampoline_segment
11817 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
11818 index 103b6ab..2004d0a 100644
11819 --- a/arch/x86/kernel/acpi/sleep.c
11820 +++ b/arch/x86/kernel/acpi/sleep.c
11821 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
11822 header->trampoline_segment = trampoline_address() >> 4;
11824 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
11826 + pax_open_kernel();
11827 early_gdt_descr.address =
11828 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11829 + pax_close_kernel();
11831 initial_gs = per_cpu_offset(smp_processor_id());
11833 initial_code = (unsigned long)wakeup_long64;
11834 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
11835 index 13ab720..95d5442 100644
11836 --- a/arch/x86/kernel/acpi/wakeup_32.S
11837 +++ b/arch/x86/kernel/acpi/wakeup_32.S
11838 @@ -30,13 +30,11 @@ wakeup_pmode_return:
11839 # and restore the stack ... but you need gdt for this to work
11840 movl saved_context_esp, %esp
11842 - movl %cs:saved_magic, %eax
11843 - cmpl $0x12345678, %eax
11844 + cmpl $0x12345678, saved_magic
11847 # jump to place where we left off
11848 - movl saved_eip, %eax
11854 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
11855 index 1f84794..e23f862 100644
11856 --- a/arch/x86/kernel/alternative.c
11857 +++ b/arch/x86/kernel/alternative.c
11858 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
11860 for (a = start; a < end; a++) {
11861 instr = (u8 *)&a->instr_offset + a->instr_offset;
11863 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11864 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11865 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
11866 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11869 replacement = (u8 *)&a->repl_offset + a->repl_offset;
11870 BUG_ON(a->replacementlen > a->instrlen);
11871 BUG_ON(a->instrlen > sizeof(insnbuf));
11872 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
11873 for (poff = start; poff < end; poff++) {
11874 u8 *ptr = (u8 *)poff + *poff;
11876 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11877 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11878 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11879 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11882 if (!*poff || ptr < text || ptr >= text_end)
11884 /* turn DS segment override prefix into lock prefix */
11885 - if (*ptr == 0x3e)
11886 + if (*ktla_ktva(ptr) == 0x3e)
11887 text_poke(ptr, ((unsigned char []){0xf0}), 1);
11889 mutex_unlock(&text_mutex);
11890 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
11891 for (poff = start; poff < end; poff++) {
11892 u8 *ptr = (u8 *)poff + *poff;
11894 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11895 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11896 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11897 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11900 if (!*poff || ptr < text || ptr >= text_end)
11902 /* turn lock prefix into DS segment override prefix */
11903 - if (*ptr == 0xf0)
11904 + if (*ktla_ktva(ptr) == 0xf0)
11905 text_poke(ptr, ((unsigned char []){0x3E}), 1);
11907 mutex_unlock(&text_mutex);
11908 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
11910 BUG_ON(p->len > MAX_PATCH_LEN);
11911 /* prep the buffer with the original instructions */
11912 - memcpy(insnbuf, p->instr, p->len);
11913 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11914 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11915 (unsigned long)p->instr, p->len);
11917 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
11919 free_init_pages("SMP alternatives",
11920 (unsigned long)__smp_locks,
11921 - (unsigned long)__smp_locks_end);
11922 + PAGE_ALIGN((unsigned long)__smp_locks_end));
11926 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
11927 * instructions. And on the local CPU you need to be protected again NMI or MCE
11928 * handlers seeing an inconsistent instruction while you patch.
11930 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
11931 +void *__kprobes text_poke_early(void *addr, const void *opcode,
11934 unsigned long flags;
11935 local_irq_save(flags);
11936 - memcpy(addr, opcode, len);
11938 + pax_open_kernel();
11939 + memcpy(ktla_ktva(addr), opcode, len);
11941 + pax_close_kernel();
11943 local_irq_restore(flags);
11944 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11945 that causes hangs on some VIA CPUs. */
11946 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
11948 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11950 - unsigned long flags;
11952 + unsigned char *vaddr = ktla_ktva(addr);
11953 struct page *pages[2];
11957 if (!core_kernel_text((unsigned long)addr)) {
11958 - pages[0] = vmalloc_to_page(addr);
11959 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11960 + pages[0] = vmalloc_to_page(vaddr);
11961 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11963 - pages[0] = virt_to_page(addr);
11964 + pages[0] = virt_to_page(vaddr);
11965 WARN_ON(!PageReserved(pages[0]));
11966 - pages[1] = virt_to_page(addr + PAGE_SIZE);
11967 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11970 - local_irq_save(flags);
11971 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11973 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11974 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11975 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11976 - clear_fixmap(FIX_TEXT_POKE0);
11978 - clear_fixmap(FIX_TEXT_POKE1);
11979 - local_flush_tlb();
11981 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
11982 - that causes hangs on some VIA CPUs. */
11983 + text_poke_early(addr, opcode, len);
11984 for (i = 0; i < len; i++)
11985 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11986 - local_irq_restore(flags);
11987 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11991 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
11992 index f98d84c..e402a69 100644
11993 --- a/arch/x86/kernel/apic/apic.c
11994 +++ b/arch/x86/kernel/apic/apic.c
11995 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
11997 * Debug level, exported for io_apic.c
11999 -unsigned int apic_verbosity;
12000 +int apic_verbosity;
12004 @@ -1853,7 +1853,7 @@ void smp_error_interrupt(struct pt_regs *regs)
12005 apic_write(APIC_ESR, 0);
12006 v1 = apic_read(APIC_ESR);
12008 - atomic_inc(&irq_err_count);
12009 + atomic_inc_unchecked(&irq_err_count);
12011 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
12012 smp_processor_id(), v0 , v1);
12013 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
12014 index 6d939d7..0697fcc 100644
12015 --- a/arch/x86/kernel/apic/io_apic.c
12016 +++ b/arch/x86/kernel/apic/io_apic.c
12017 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
12019 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
12021 -void lock_vector_lock(void)
12022 +void lock_vector_lock(void) __acquires(vector_lock)
12024 /* Used to the online set of cpus does not change
12025 * during assign_irq_vector.
12026 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
12027 raw_spin_lock(&vector_lock);
12030 -void unlock_vector_lock(void)
12031 +void unlock_vector_lock(void) __releases(vector_lock)
12033 raw_spin_unlock(&vector_lock);
12035 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
12039 -atomic_t irq_mis_count;
12040 +atomic_unchecked_t irq_mis_count;
12042 static void ack_apic_level(struct irq_data *data)
12044 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
12047 if (!(v & (1 << (i & 0x1f)))) {
12048 - atomic_inc(&irq_mis_count);
12049 + atomic_inc_unchecked(&irq_mis_count);
12051 eoi_ioapic_irq(irq, cfg);
12053 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
12054 index a46bd38..6b906d7 100644
12055 --- a/arch/x86/kernel/apm_32.c
12056 +++ b/arch/x86/kernel/apm_32.c
12057 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
12058 * This is for buggy BIOS's that refer to (real mode) segment 0x40
12059 * even though they are called in protected mode.
12061 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
12062 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
12063 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
12065 static const char driver_version[] = "1.16ac"; /* no spaces */
12066 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
12068 gdt = get_cpu_gdt_table(cpu);
12069 save_desc_40 = gdt[0x40 / 8];
12071 + pax_open_kernel();
12072 gdt[0x40 / 8] = bad_bios_desc;
12073 + pax_close_kernel();
12075 apm_irq_save(flags);
12077 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
12079 APM_DO_RESTORE_SEGS;
12080 apm_irq_restore(flags);
12082 + pax_open_kernel();
12083 gdt[0x40 / 8] = save_desc_40;
12084 + pax_close_kernel();
12088 return call->eax & 0xff;
12089 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
12091 gdt = get_cpu_gdt_table(cpu);
12092 save_desc_40 = gdt[0x40 / 8];
12094 + pax_open_kernel();
12095 gdt[0x40 / 8] = bad_bios_desc;
12096 + pax_close_kernel();
12098 apm_irq_save(flags);
12100 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
12102 APM_DO_RESTORE_SEGS;
12103 apm_irq_restore(flags);
12105 + pax_open_kernel();
12106 gdt[0x40 / 8] = save_desc_40;
12107 + pax_close_kernel();
12112 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
12113 * code to that CPU.
12115 gdt = get_cpu_gdt_table(0);
12117 + pax_open_kernel();
12118 set_desc_base(&gdt[APM_CS >> 3],
12119 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12120 set_desc_base(&gdt[APM_CS_16 >> 3],
12121 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12122 set_desc_base(&gdt[APM_DS >> 3],
12123 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12124 + pax_close_kernel();
12126 proc_create("apm", 0, NULL, &apm_file_ops);
12128 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
12129 index 4f13faf..87db5d2 100644
12130 --- a/arch/x86/kernel/asm-offsets.c
12131 +++ b/arch/x86/kernel/asm-offsets.c
12132 @@ -33,6 +33,8 @@ void common(void) {
12133 OFFSET(TI_status, thread_info, status);
12134 OFFSET(TI_addr_limit, thread_info, addr_limit);
12135 OFFSET(TI_preempt_count, thread_info, preempt_count);
12136 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12137 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12140 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12141 @@ -53,8 +55,26 @@ void common(void) {
12142 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12143 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12144 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12146 +#ifdef CONFIG_PAX_KERNEXEC
12147 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12150 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12151 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12152 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12153 +#ifdef CONFIG_X86_64
12154 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
12161 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12162 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12163 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12167 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12168 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
12169 index e72a119..6e2955d 100644
12170 --- a/arch/x86/kernel/asm-offsets_64.c
12171 +++ b/arch/x86/kernel/asm-offsets_64.c
12172 @@ -69,6 +69,7 @@ int main(void)
12176 + DEFINE(TSS_size, sizeof(struct tss_struct));
12177 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12180 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
12181 index 25f24dc..4094a7f 100644
12182 --- a/arch/x86/kernel/cpu/Makefile
12183 +++ b/arch/x86/kernel/cpu/Makefile
12184 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
12185 CFLAGS_REMOVE_perf_event.o = -pg
12188 -# Make sure load_percpu_segment has no stackprotector
12189 -nostackp := $(call cc-option, -fno-stack-protector)
12190 -CFLAGS_common.o := $(nostackp)
12192 obj-y := intel_cacheinfo.o scattered.o topology.o
12193 obj-y += proc.o capflags.o powerflags.o common.o
12194 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
12195 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
12196 index 0bab2b1..d0a1bf8 100644
12197 --- a/arch/x86/kernel/cpu/amd.c
12198 +++ b/arch/x86/kernel/cpu/amd.c
12199 @@ -664,7 +664,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
12202 /* AMD errata T13 (order #21922) */
12203 - if ((c->x86 == 6)) {
12204 + if (c->x86 == 6) {
12206 if (c->x86_model == 3 && c->x86_mask == 0)
12208 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
12209 index aa003b1..47ea638 100644
12210 --- a/arch/x86/kernel/cpu/common.c
12211 +++ b/arch/x86/kernel/cpu/common.c
12212 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
12214 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12216 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12217 -#ifdef CONFIG_X86_64
12219 - * We need valid kernel segments for data and code in long mode too
12220 - * IRET will check the segment types kkeil 2000/10/28
12221 - * Also sysret mandates a special GDT layout
12223 - * TLS descriptors are currently at a different place compared to i386.
12224 - * Hopefully nobody expects them at a fixed place (Wine?)
12226 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12227 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12228 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12229 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12230 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12231 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12233 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12234 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12235 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12236 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12238 - * Segments used for calling PnP BIOS have byte granularity.
12239 - * They code segments and data segments have fixed 64k limits,
12240 - * the transfer segment sizes are set at run time.
12242 - /* 32-bit code */
12243 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12244 - /* 16-bit code */
12245 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12246 - /* 16-bit data */
12247 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12248 - /* 16-bit data */
12249 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12250 - /* 16-bit data */
12251 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12253 - * The APM segments have byte granularity and their bases
12254 - * are set at run time. All have 64k limits.
12256 - /* 32-bit code */
12257 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12258 - /* 16-bit code */
12259 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12261 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12263 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12264 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12265 - GDT_STACK_CANARY_INIT
12268 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12270 static int __init x86_xsave_setup(char *s)
12272 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12273 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
12275 struct desc_ptr gdt_descr;
12277 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12278 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12279 gdt_descr.size = GDT_SIZE - 1;
12280 load_gdt(&gdt_descr);
12281 /* Reload the per-cpu base */
12282 @@ -844,6 +790,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
12283 /* Filter out anything that depends on CPUID levels we don't have */
12284 filter_cpuid_features(c, true);
12286 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
12287 + setup_clear_cpu_cap(X86_FEATURE_SEP);
12290 /* If the model name is still unset, do table lookup. */
12291 if (!c->x86_model_id[0]) {
12293 @@ -1024,6 +974,9 @@ static __init int setup_disablecpuid(char *arg)
12295 __setup("clearcpuid=", setup_disablecpuid);
12297 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12298 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
12300 #ifdef CONFIG_X86_64
12301 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12303 @@ -1039,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
12304 EXPORT_PER_CPU_SYMBOL(current_task);
12306 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12307 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12308 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12309 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12311 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12312 @@ -1104,7 +1057,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
12314 memset(regs, 0, sizeof(struct pt_regs));
12315 regs->fs = __KERNEL_PERCPU;
12316 - regs->gs = __KERNEL_STACK_CANARY;
12317 + savesegment(gs, regs->gs);
12321 @@ -1159,7 +1112,7 @@ void __cpuinit cpu_init(void)
12324 cpu = stack_smp_processor_id();
12325 - t = &per_cpu(init_tss, cpu);
12326 + t = init_tss + cpu;
12327 oist = &per_cpu(orig_ist, cpu);
12330 @@ -1185,7 +1138,7 @@ void __cpuinit cpu_init(void)
12331 switch_to_new_gdt(cpu);
12332 loadsegment(fs, 0);
12334 - load_idt((const struct desc_ptr *)&idt_descr);
12335 + load_idt(&idt_descr);
12337 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12339 @@ -1194,7 +1147,6 @@ void __cpuinit cpu_init(void)
12340 wrmsrl(MSR_KERNEL_GS_BASE, 0);
12343 - x86_configure_nx();
12347 @@ -1248,7 +1200,7 @@ void __cpuinit cpu_init(void)
12349 int cpu = smp_processor_id();
12350 struct task_struct *curr = current;
12351 - struct tss_struct *t = &per_cpu(init_tss, cpu);
12352 + struct tss_struct *t = init_tss + cpu;
12353 struct thread_struct *thread = &curr->thread;
12355 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
12356 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
12357 index 5231312..a78a987 100644
12358 --- a/arch/x86/kernel/cpu/intel.c
12359 +++ b/arch/x86/kernel/cpu/intel.c
12360 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
12361 * Update the IDT descriptor and reload the IDT so that
12362 * it uses the read-only mapped virtual address.
12364 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
12365 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
12366 load_idt(&idt_descr);
12369 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
12370 index 2af127d..8ff7ac0 100644
12371 --- a/arch/x86/kernel/cpu/mcheck/mce.c
12372 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
12374 #include <asm/processor.h>
12375 #include <asm/mce.h>
12376 #include <asm/msr.h>
12377 +#include <asm/local.h>
12379 #include "mce-internal.h"
12381 @@ -202,7 +203,7 @@ static void print_mce(struct mce *m)
12382 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
12385 - if (m->cs == __KERNEL_CS)
12386 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
12387 print_symbol("{%s}", m->ip);
12390 @@ -235,10 +236,10 @@ static void print_mce(struct mce *m)
12392 #define PANIC_TIMEOUT 5 /* 5 seconds */
12394 -static atomic_t mce_paniced;
12395 +static atomic_unchecked_t mce_paniced;
12397 static int fake_panic;
12398 -static atomic_t mce_fake_paniced;
12399 +static atomic_unchecked_t mce_fake_paniced;
12401 /* Panic in progress. Enable interrupts and wait for final IPI */
12402 static void wait_for_panic(void)
12403 @@ -262,7 +263,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12405 * Make sure only one CPU runs in machine check panic
12407 - if (atomic_inc_return(&mce_paniced) > 1)
12408 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
12412 @@ -270,7 +271,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12415 /* Don't log too much for fake panic */
12416 - if (atomic_inc_return(&mce_fake_paniced) > 1)
12417 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
12420 /* First print corrected ones that are still unlogged */
12421 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
12422 * might have been modified by someone else.
12425 - if (atomic_read(&mce_paniced))
12426 + if (atomic_read_unchecked(&mce_paniced))
12428 if (!monarch_timeout)
12430 @@ -1398,7 +1399,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
12433 /* Call the installed machine check handler for this CPU setup. */
12434 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
12435 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
12436 unexpected_machine_check;
12439 @@ -1421,7 +1422,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12443 + pax_open_kernel();
12444 machine_check_vector = do_machine_check;
12445 + pax_close_kernel();
12447 __mcheck_cpu_init_generic();
12448 __mcheck_cpu_init_vendor(c);
12449 @@ -1435,7 +1438,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12452 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
12453 -static int mce_chrdev_open_count; /* #times opened */
12454 +static local_t mce_chrdev_open_count; /* #times opened */
12455 static int mce_chrdev_open_exclu; /* already open exclusive? */
12457 static int mce_chrdev_open(struct inode *inode, struct file *file)
12458 @@ -1443,7 +1446,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12459 spin_lock(&mce_chrdev_state_lock);
12461 if (mce_chrdev_open_exclu ||
12462 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
12463 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
12464 spin_unlock(&mce_chrdev_state_lock);
12467 @@ -1451,7 +1454,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12469 if (file->f_flags & O_EXCL)
12470 mce_chrdev_open_exclu = 1;
12471 - mce_chrdev_open_count++;
12472 + local_inc(&mce_chrdev_open_count);
12474 spin_unlock(&mce_chrdev_state_lock);
12476 @@ -1462,7 +1465,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
12478 spin_lock(&mce_chrdev_state_lock);
12480 - mce_chrdev_open_count--;
12481 + local_dec(&mce_chrdev_open_count);
12482 mce_chrdev_open_exclu = 0;
12484 spin_unlock(&mce_chrdev_state_lock);
12485 @@ -2171,7 +2174,7 @@ struct dentry *mce_get_debugfs_dir(void)
12486 static void mce_reset(void)
12489 - atomic_set(&mce_fake_paniced, 0);
12490 + atomic_set_unchecked(&mce_fake_paniced, 0);
12491 atomic_set(&mce_executing, 0);
12492 atomic_set(&mce_callin, 0);
12493 atomic_set(&global_nwo, 0);
12494 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
12495 index 5c0e653..0882b0a 100644
12496 --- a/arch/x86/kernel/cpu/mcheck/p5.c
12497 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
12499 #include <asm/system.h>
12500 #include <asm/mce.h>
12501 #include <asm/msr.h>
12502 +#include <asm/pgtable.h>
12504 /* By default disabled */
12505 int mce_p5_enabled __read_mostly;
12506 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
12507 if (!cpu_has(c, X86_FEATURE_MCE))
12510 + pax_open_kernel();
12511 machine_check_vector = pentium_machine_check;
12512 + pax_close_kernel();
12513 /* Make sure the vector pointer is visible before we enable MCEs: */
12516 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
12517 index 54060f5..c1a7577 100644
12518 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
12519 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
12521 #include <asm/system.h>
12522 #include <asm/mce.h>
12523 #include <asm/msr.h>
12524 +#include <asm/pgtable.h>
12526 /* Machine check handler for WinChip C6: */
12527 static void winchip_machine_check(struct pt_regs *regs, long error_code)
12528 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
12532 + pax_open_kernel();
12533 machine_check_vector = winchip_machine_check;
12534 + pax_close_kernel();
12535 /* Make sure the vector pointer is visible before we enable MCEs: */
12538 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
12539 index 6b96110..0da73eb 100644
12540 --- a/arch/x86/kernel/cpu/mtrr/main.c
12541 +++ b/arch/x86/kernel/cpu/mtrr/main.c
12542 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
12543 u64 size_or_mask, size_and_mask;
12544 static bool mtrr_aps_delayed_init;
12546 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12547 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12549 const struct mtrr_ops *mtrr_if;
12551 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
12552 index df5e41f..816c719 100644
12553 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
12554 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
12555 @@ -25,7 +25,7 @@ struct mtrr_ops {
12556 int (*validate_add_page)(unsigned long base, unsigned long size,
12557 unsigned int type);
12558 int (*have_wrcomb)(void);
12562 extern int generic_get_free_region(unsigned long base, unsigned long size,
12564 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
12565 index 2bda212..78cc605 100644
12566 --- a/arch/x86/kernel/cpu/perf_event.c
12567 +++ b/arch/x86/kernel/cpu/perf_event.c
12568 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
12571 perf_callchain_store(entry, frame.return_address);
12572 - fp = frame.next_frame;
12573 + fp = (const void __force_user *)frame.next_frame;
12577 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
12578 index 13ad899..f642b9a 100644
12579 --- a/arch/x86/kernel/crash.c
12580 +++ b/arch/x86/kernel/crash.c
12581 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
12583 #ifdef CONFIG_X86_32
12584 struct pt_regs fixed_regs;
12587 -#ifdef CONFIG_X86_32
12588 - if (!user_mode_vm(regs)) {
12589 + if (!user_mode(regs)) {
12590 crash_fixup_ss_esp(&fixed_regs, regs);
12591 regs = &fixed_regs;
12593 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
12594 index 37250fe..bf2ec74 100644
12595 --- a/arch/x86/kernel/doublefault_32.c
12596 +++ b/arch/x86/kernel/doublefault_32.c
12599 #define DOUBLEFAULT_STACKSIZE (1024)
12600 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12601 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12602 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12604 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12606 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
12607 unsigned long gdt, tss;
12609 store_gdt(&gdt_desc);
12610 - gdt = gdt_desc.address;
12611 + gdt = (unsigned long)gdt_desc.address;
12613 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12615 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
12616 /* 0x2 bit is always set */
12617 .flags = X86_EFLAGS_SF | 0x2,
12620 + .es = __KERNEL_DS,
12624 + .ds = __KERNEL_DS,
12625 .fs = __KERNEL_PERCPU,
12627 .__cr3 = __pa_nodebug(swapper_pg_dir),
12628 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
12629 index 1aae78f..aab3a3d 100644
12630 --- a/arch/x86/kernel/dumpstack.c
12631 +++ b/arch/x86/kernel/dumpstack.c
12633 * Copyright (C) 1991, 1992 Linus Torvalds
12634 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
12637 +#define __INCLUDED_BY_HIDESYM 1
12639 #include <linux/kallsyms.h>
12640 #include <linux/kprobes.h>
12641 #include <linux/uaccess.h>
12642 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
12644 print_ftrace_graph_addr(unsigned long addr, void *data,
12645 const struct stacktrace_ops *ops,
12646 - struct thread_info *tinfo, int *graph)
12647 + struct task_struct *task, int *graph)
12649 - struct task_struct *task = tinfo->task;
12650 unsigned long ret_addr;
12651 int index = task->curr_ret_stack;
12653 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12655 print_ftrace_graph_addr(unsigned long addr, void *data,
12656 const struct stacktrace_ops *ops,
12657 - struct thread_info *tinfo, int *graph)
12658 + struct task_struct *task, int *graph)
12662 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12663 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12666 -static inline int valid_stack_ptr(struct thread_info *tinfo,
12667 - void *p, unsigned int size, void *end)
12668 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12672 if (p < end && p >= (end-THREAD_SIZE))
12674 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
12678 -print_context_stack(struct thread_info *tinfo,
12679 +print_context_stack(struct task_struct *task, void *stack_start,
12680 unsigned long *stack, unsigned long bp,
12681 const struct stacktrace_ops *ops, void *data,
12682 unsigned long *end, int *graph)
12684 struct stack_frame *frame = (struct stack_frame *)bp;
12686 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12687 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12688 unsigned long addr;
12691 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
12693 ops->address(data, addr, 0);
12695 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12696 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12700 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
12701 EXPORT_SYMBOL_GPL(print_context_stack);
12704 -print_context_stack_bp(struct thread_info *tinfo,
12705 +print_context_stack_bp(struct task_struct *task, void *stack_start,
12706 unsigned long *stack, unsigned long bp,
12707 const struct stacktrace_ops *ops, void *data,
12708 unsigned long *end, int *graph)
12709 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12710 struct stack_frame *frame = (struct stack_frame *)bp;
12711 unsigned long *ret_addr = &frame->return_address;
12713 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
12714 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
12715 unsigned long addr = *ret_addr;
12717 if (!__kernel_text_address(addr))
12718 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12719 ops->address(data, addr, 1);
12720 frame = frame->next_frame;
12721 ret_addr = &frame->return_address;
12722 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12723 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12726 return (unsigned long)frame;
12727 @@ -186,7 +186,7 @@ void dump_stack(void)
12729 bp = stack_frame(current, NULL);
12730 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12731 - current->pid, current->comm, print_tainted(),
12732 + task_pid_nr(current), current->comm, print_tainted(),
12733 init_utsname()->release,
12734 (int)strcspn(init_utsname()->version, " "),
12735 init_utsname()->version);
12736 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
12738 EXPORT_SYMBOL_GPL(oops_begin);
12740 +extern void gr_handle_kernel_exploit(void);
12742 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12744 if (regs && kexec_should_crash(current))
12745 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12746 panic("Fatal exception in interrupt");
12748 panic("Fatal exception");
12751 + gr_handle_kernel_exploit();
12753 + do_group_exit(signr);
12756 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12757 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12759 show_registers(regs);
12760 #ifdef CONFIG_X86_32
12761 - if (user_mode_vm(regs)) {
12762 + if (user_mode(regs)) {
12764 ss = regs->ss & 0xffff;
12766 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
12767 unsigned long flags = oops_begin();
12770 - if (!user_mode_vm(regs))
12771 + if (!user_mode(regs))
12772 report_bug(regs->ip, regs);
12774 if (__die(str, regs, err))
12775 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
12776 index c99f9ed..2a15d80 100644
12777 --- a/arch/x86/kernel/dumpstack_32.c
12778 +++ b/arch/x86/kernel/dumpstack_32.c
12779 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12780 bp = stack_frame(task, regs);
12783 - struct thread_info *context;
12784 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12786 - context = (struct thread_info *)
12787 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12788 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
12789 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12791 - stack = (unsigned long *)context->previous_esp;
12793 + if (stack_start == task_stack_page(task))
12795 + stack = *(unsigned long **)stack_start;
12796 if (ops->stack(data, "IRQ") < 0)
12798 touch_nmi_watchdog();
12799 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
12800 * When in-kernel, we also print out the stack and code at the
12801 * time of the fault..
12803 - if (!user_mode_vm(regs)) {
12804 + if (!user_mode(regs)) {
12805 unsigned int code_prologue = code_bytes * 43 / 64;
12806 unsigned int code_len = code_bytes;
12809 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12811 printk(KERN_EMERG "Stack:\n");
12812 show_stack_log_lvl(NULL, regs, ®s->sp, 0, KERN_EMERG);
12814 printk(KERN_EMERG "Code: ");
12816 - ip = (u8 *)regs->ip - code_prologue;
12817 + ip = (u8 *)regs->ip - code_prologue + cs_base;
12818 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12819 /* try starting at IP */
12820 - ip = (u8 *)regs->ip;
12821 + ip = (u8 *)regs->ip + cs_base;
12822 code_len = code_len - code_prologue + 1;
12824 for (i = 0; i < code_len; i++, ip++) {
12825 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
12826 printk(KERN_CONT " Bad EIP value.");
12829 - if (ip == (u8 *)regs->ip)
12830 + if (ip == (u8 *)regs->ip + cs_base)
12831 printk(KERN_CONT "<%02x> ", c);
12833 printk(KERN_CONT "%02x ", c);
12834 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
12836 unsigned short ud2;
12838 + ip = ktla_ktva(ip);
12839 if (ip < PAGE_OFFSET)
12841 if (probe_kernel_address((unsigned short *)ip, ud2))
12842 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
12844 return ud2 == 0x0b0f;
12847 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12848 +void pax_check_alloca(unsigned long size)
12850 + unsigned long sp = (unsigned long)&sp, stack_left;
12852 + /* all kernel stacks are of the same size */
12853 + stack_left = sp & (THREAD_SIZE - 1);
12854 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12856 +EXPORT_SYMBOL(pax_check_alloca);
12858 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
12859 index 6d728d9..279514e 100644
12860 --- a/arch/x86/kernel/dumpstack_64.c
12861 +++ b/arch/x86/kernel/dumpstack_64.c
12862 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12863 unsigned long *irq_stack_end =
12864 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12866 - struct thread_info *tinfo;
12868 unsigned long dummy;
12869 + void *stack_start;
12873 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12874 * current stack address. If the stacks consist of nested
12877 - tinfo = task_thread_info(task);
12880 unsigned long *estack_end;
12882 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12885 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12886 if (ops->stack(data, id) < 0)
12889 - bp = ops->walk_stack(tinfo, stack, bp, ops,
12890 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12891 data, estack_end, &graph);
12892 ops->stack(data, "<EOE>");
12894 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12895 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
12896 if (ops->stack(data, "IRQ") < 0)
12898 - bp = ops->walk_stack(tinfo, stack, bp,
12899 + bp = ops->walk_stack(task, irq_stack, stack, bp,
12900 ops, data, irq_stack_end, &graph);
12902 * We link to the next stack (which would be
12903 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12905 * This handles the process stack:
12907 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12908 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12909 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12912 EXPORT_SYMBOL(dump_trace);
12913 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
12915 return ud2 == 0x0b0f;
12918 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12919 +void pax_check_alloca(unsigned long size)
12921 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
12922 + unsigned cpu, used;
12925 + /* check the process stack first */
12926 + stack_start = (unsigned long)task_stack_page(current);
12927 + stack_end = stack_start + THREAD_SIZE;
12928 + if (likely(stack_start <= sp && sp < stack_end)) {
12929 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
12930 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12936 + /* check the irq stacks */
12937 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
12938 + stack_start = stack_end - IRQ_STACK_SIZE;
12939 + if (stack_start <= sp && sp < stack_end) {
12940 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
12942 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12946 + /* check the exception stacks */
12948 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
12949 + stack_start = stack_end - EXCEPTION_STKSZ;
12950 + if (stack_end && stack_start <= sp && sp < stack_end) {
12951 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
12953 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12959 + /* unknown stack */
12962 +EXPORT_SYMBOL(pax_check_alloca);
12964 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
12965 index cd28a35..c72ed9a 100644
12966 --- a/arch/x86/kernel/early_printk.c
12967 +++ b/arch/x86/kernel/early_printk.c
12969 #include <linux/pci_regs.h>
12970 #include <linux/pci_ids.h>
12971 #include <linux/errno.h>
12972 +#include <linux/sched.h>
12973 #include <asm/io.h>
12974 #include <asm/processor.h>
12975 #include <asm/fcntl.h>
12976 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
12977 index f3f6f53..0841b66 100644
12978 --- a/arch/x86/kernel/entry_32.S
12979 +++ b/arch/x86/kernel/entry_32.S
12980 @@ -186,13 +186,146 @@
12981 /*CFI_REL_OFFSET gs, PT_GS*/
12983 .macro SET_KERNEL_GS reg
12985 +#ifdef CONFIG_CC_STACKPROTECTOR
12986 movl $(__KERNEL_STACK_CANARY), \reg
12987 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12988 + movl $(__USER_DS), \reg
12996 #endif /* CONFIG_X86_32_LAZY_GS */
12999 +.macro pax_enter_kernel
13000 +#ifdef CONFIG_PAX_KERNEXEC
13001 + call pax_enter_kernel
13005 +.macro pax_exit_kernel
13006 +#ifdef CONFIG_PAX_KERNEXEC
13007 + call pax_exit_kernel
13011 +#ifdef CONFIG_PAX_KERNEXEC
13012 +ENTRY(pax_enter_kernel)
13013 +#ifdef CONFIG_PARAVIRT
13016 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
13024 + cmp $__KERNEL_CS, %esi
13026 + ljmp $__KERNEL_CS, $3f
13027 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
13029 +#ifdef CONFIG_PARAVIRT
13031 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13036 +#ifdef CONFIG_PARAVIRT
13041 +ENDPROC(pax_enter_kernel)
13043 +ENTRY(pax_exit_kernel)
13044 +#ifdef CONFIG_PARAVIRT
13049 + cmp $__KERNEXEC_KERNEL_CS, %esi
13051 +#ifdef CONFIG_PARAVIRT
13052 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
13058 + ljmp $__KERNEL_CS, $1f
13060 +#ifdef CONFIG_PARAVIRT
13062 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
13067 +#ifdef CONFIG_PARAVIRT
13072 +ENDPROC(pax_exit_kernel)
13075 +.macro pax_erase_kstack
13076 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13077 + call pax_erase_kstack
13081 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13083 + * ebp: thread_info
13084 + * ecx, edx: can be clobbered
13086 +ENTRY(pax_erase_kstack)
13090 + mov TI_lowest_stack(%ebp), %edi
13091 + mov $-0xBEEF, %eax
13095 + and $THREAD_SIZE_asm - 1, %ecx
13114 + mov TI_task_thread_sp0(%ebp), %edi
13116 + mov %edi, TI_lowest_stack(%ebp)
13121 +ENDPROC(pax_erase_kstack)
13124 +.macro __SAVE_ALL _DS
13128 @@ -215,7 +348,7 @@
13129 CFI_REL_OFFSET ecx, 0
13131 CFI_REL_OFFSET ebx, 0
13132 - movl $(__USER_DS), %edx
13136 movl $(__KERNEL_PERCPU), %edx
13137 @@ -223,6 +356,15 @@
13142 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13143 + __SAVE_ALL __KERNEL_DS
13146 + __SAVE_ALL __USER_DS
13150 .macro RESTORE_INT_REGS
13153 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
13157 -END(ret_from_fork)
13158 +ENDPROC(ret_from_fork)
13161 * Interrupt exit functions should be protected against kprobes
13162 @@ -333,7 +475,15 @@ check_userspace:
13163 movb PT_CS(%esp), %al
13164 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13165 cmpl $USER_RPL, %eax
13167 +#ifdef CONFIG_PAX_KERNEXEC
13168 + jae resume_userspace
13171 + jmp resume_kernel
13173 jb resume_kernel # not returning to v8086 or userspace
13176 ENTRY(resume_userspace)
13178 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
13179 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13180 # int/exception return?
13183 -END(ret_from_exception)
13184 + jmp restore_all_pax
13185 +ENDPROC(ret_from_exception)
13187 #ifdef CONFIG_PREEMPT
13188 ENTRY(resume_kernel)
13189 @@ -361,7 +511,7 @@ need_resched:
13191 call preempt_schedule_irq
13193 -END(resume_kernel)
13194 +ENDPROC(resume_kernel)
13198 @@ -395,23 +545,34 @@ sysenter_past_esp:
13199 /*CFI_REL_OFFSET cs, 0*/
13201 * Push current_thread_info()->sysenter_return to the stack.
13202 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13203 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
13205 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13207 CFI_REL_OFFSET eip, 0
13211 + GET_THREAD_INFO(%ebp)
13212 + movl TI_sysenter_return(%ebp),%ebp
13213 + movl %ebp,PT_EIP(%esp)
13214 ENABLE_INTERRUPTS(CLBR_NONE)
13217 * Load the potential sixth argument from user stack.
13218 * Careful about security.
13220 + movl PT_OLDESP(%esp),%ebp
13222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13223 + mov PT_OLDSS(%esp),%ds
13224 +1: movl %ds:(%ebp),%ebp
13228 cmpl $__PAGE_OFFSET-3,%ebp
13230 1: movl (%ebp),%ebp
13233 movl %ebp,PT_EBP(%esp)
13234 .section __ex_table,"a"
13236 @@ -434,12 +595,24 @@ sysenter_do_call:
13237 testl $_TIF_ALLWORK_MASK, %ecx
13241 +#ifdef CONFIG_PAX_RANDKSTACK
13244 + call pax_randomize_kstack
13250 /* if something modifies registers it must also disable sysexit */
13251 movl PT_EIP(%esp), %edx
13252 movl PT_OLDESP(%esp), %ecx
13255 1: mov PT_FS(%esp), %fs
13256 +2: mov PT_DS(%esp), %ds
13257 +3: mov PT_ES(%esp), %es
13259 ENABLE_INTERRUPTS_SYSEXIT
13261 @@ -456,6 +629,9 @@ sysenter_audit:
13262 movl %eax,%edx /* 2nd arg: syscall number */
13263 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13264 call audit_syscall_entry
13269 movl PT_EAX(%esp),%eax /* reload syscall number */
13270 jmp sysenter_do_call
13271 @@ -482,11 +658,17 @@ sysexit_audit:
13274 .pushsection .fixup,"ax"
13275 -2: movl $0,PT_FS(%esp)
13276 +4: movl $0,PT_FS(%esp)
13278 +5: movl $0,PT_DS(%esp)
13280 +6: movl $0,PT_ES(%esp)
13282 .section __ex_table,"a"
13290 ENDPROC(ia32_sysenter_target)
13291 @@ -519,6 +701,15 @@ syscall_exit:
13292 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13293 jne syscall_exit_work
13297 +#ifdef CONFIG_PAX_RANDKSTACK
13299 + call pax_randomize_kstack
13306 restore_all_notrace:
13307 @@ -578,14 +769,34 @@ ldt_ss:
13308 * compensating for the offset by changing to the ESPFIX segment with
13309 * a base address that matches for the difference.
13311 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13312 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13313 mov %esp, %edx /* load kernel esp */
13314 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13315 mov %dx, %ax /* eax: new kernel esp */
13316 sub %eax, %edx /* offset (low word is 0) */
13318 + movl PER_CPU_VAR(cpu_number), %ebx
13319 + shll $PAGE_SHIFT_asm, %ebx
13320 + addl $cpu_gdt_table, %ebx
13322 + movl $cpu_gdt_table, %ebx
13325 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13326 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13328 +#ifdef CONFIG_PAX_KERNEXEC
13334 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13335 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13337 +#ifdef CONFIG_PAX_KERNEXEC
13342 pushl_cfi $__ESPFIX_SS
13343 pushl_cfi %eax /* new kernel esp */
13344 /* Disable interrupts, but do not irqtrace this section: we
13345 @@ -614,34 +825,28 @@ work_resched:
13346 movl TI_flags(%ebp), %ecx
13347 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13348 # than syscall tracing?
13350 + jz restore_all_pax
13351 testb $_TIF_NEED_RESCHED, %cl
13354 work_notifysig: # deal with pending signals and
13355 # notify-resume requests
13358 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13360 - jne work_notifysig_v86 # returning to kernel-space or
13361 + jz 1f # returning to kernel-space or
13364 - call do_notify_resume
13365 - jmp resume_userspace_sig
13368 -work_notifysig_v86:
13369 pushl_cfi %ecx # save ti_flags for do_notify_resume
13370 call save_v86_state # %eax contains pt_regs pointer
13378 call do_notify_resume
13379 jmp resume_userspace_sig
13381 +ENDPROC(work_pending)
13383 # perform syscall exit tracing
13385 @@ -649,11 +854,14 @@ syscall_trace_entry:
13386 movl $-ENOSYS,PT_EAX(%esp)
13388 call syscall_trace_enter
13392 /* What it returned is what we'll actually use. */
13393 cmpl $(nr_syscalls), %eax
13396 -END(syscall_trace_entry)
13397 +ENDPROC(syscall_trace_entry)
13399 # perform syscall exit tracing
13401 @@ -666,20 +874,24 @@ syscall_exit_work:
13403 call syscall_trace_leave
13404 jmp resume_userspace
13405 -END(syscall_exit_work)
13406 +ENDPROC(syscall_exit_work)
13409 RING0_INT_FRAME # can't unwind into user space anyway
13411 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13415 GET_THREAD_INFO(%ebp)
13416 movl $-EFAULT,PT_EAX(%esp)
13417 jmp resume_userspace
13418 -END(syscall_fault)
13419 +ENDPROC(syscall_fault)
13422 movl $-ENOSYS,PT_EAX(%esp)
13423 jmp resume_userspace
13424 -END(syscall_badsys)
13425 +ENDPROC(syscall_badsys)
13428 * End of kprobes section
13429 @@ -753,6 +965,36 @@ ptregs_clone:
13431 ENDPROC(ptregs_clone)
13434 +ENTRY(kernel_execve)
13437 + sub $PT_OLDSS+4,%esp
13441 + lea 3*4(%esp),%edi
13442 + mov $PT_OLDSS/4+1,%ecx
13448 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13452 + CFI_ADJUST_CFA_OFFSET -4
13453 + GET_THREAD_INFO(%ebp)
13456 + add $PT_OLDSS+4,%esp
13457 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13461 +ENDPROC(kernel_execve)
13463 .macro FIXUP_ESPFIX_STACK
13465 * Switch back for ESPFIX stack to the normal zerobased stack
13466 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
13467 * normal stack and adjusts ESP with the matching offset.
13469 /* fixup the stack */
13470 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13471 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13473 + movl PER_CPU_VAR(cpu_number), %ebx
13474 + shll $PAGE_SHIFT_asm, %ebx
13475 + addl $cpu_gdt_table, %ebx
13477 + movl $cpu_gdt_table, %ebx
13479 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
13480 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
13482 addl %esp, %eax /* the adjusted stack pointer */
13483 pushl_cfi $__KERNEL_DS
13484 @@ -816,7 +1065,7 @@ vector=vector+1
13486 2: jmp common_interrupt
13488 -END(irq_entries_start)
13489 +ENDPROC(irq_entries_start)
13493 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
13494 pushl_cfi $do_coprocessor_error
13497 -END(coprocessor_error)
13498 +ENDPROC(coprocessor_error)
13500 ENTRY(simd_coprocessor_error)
13502 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
13506 -END(simd_coprocessor_error)
13507 +ENDPROC(simd_coprocessor_error)
13509 ENTRY(device_not_available)
13511 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
13512 pushl_cfi $do_device_not_available
13515 -END(device_not_available)
13516 +ENDPROC(device_not_available)
13518 #ifdef CONFIG_PARAVIRT
13520 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
13522 .long native_iret, iret_exc
13525 +ENDPROC(native_iret)
13527 ENTRY(native_irq_enable_sysexit)
13530 -END(native_irq_enable_sysexit)
13531 +ENDPROC(native_irq_enable_sysexit)
13535 @@ -916,7 +1165,7 @@ ENTRY(overflow)
13536 pushl_cfi $do_overflow
13544 @@ -924,7 +1173,7 @@ ENTRY(bounds)
13545 pushl_cfi $do_bounds
13553 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
13554 pushl_cfi $do_invalid_op
13558 +ENDPROC(invalid_op)
13560 ENTRY(coprocessor_segment_overrun)
13562 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
13563 pushl_cfi $do_coprocessor_segment_overrun
13566 -END(coprocessor_segment_overrun)
13567 +ENDPROC(coprocessor_segment_overrun)
13571 pushl_cfi $do_invalid_TSS
13575 +ENDPROC(invalid_TSS)
13577 ENTRY(segment_not_present)
13579 pushl_cfi $do_segment_not_present
13582 -END(segment_not_present)
13583 +ENDPROC(segment_not_present)
13585 ENTRY(stack_segment)
13587 pushl_cfi $do_stack_segment
13590 -END(stack_segment)
13591 +ENDPROC(stack_segment)
13593 ENTRY(alignment_check)
13595 pushl_cfi $do_alignment_check
13598 -END(alignment_check)
13599 +ENDPROC(alignment_check)
13601 ENTRY(divide_error)
13603 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
13604 pushl_cfi $do_divide_error
13608 +ENDPROC(divide_error)
13610 #ifdef CONFIG_X86_MCE
13611 ENTRY(machine_check)
13612 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
13613 pushl_cfi machine_check_vector
13616 -END(machine_check)
13617 +ENDPROC(machine_check)
13620 ENTRY(spurious_interrupt_bug)
13621 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
13622 pushl_cfi $do_spurious_interrupt_bug
13625 -END(spurious_interrupt_bug)
13626 +ENDPROC(spurious_interrupt_bug)
13628 * End of kprobes section
13630 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
13637 ENTRY(ftrace_caller)
13638 cmpl $0, function_trace_stop
13639 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
13643 -END(ftrace_caller)
13644 +ENDPROC(ftrace_caller)
13646 #else /* ! CONFIG_DYNAMIC_FTRACE */
13648 @@ -1174,7 +1423,7 @@ trace:
13654 #endif /* CONFIG_DYNAMIC_FTRACE */
13655 #endif /* CONFIG_FUNCTION_TRACER */
13657 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
13661 -END(ftrace_graph_caller)
13662 +ENDPROC(ftrace_graph_caller)
13664 .globl return_to_handler
13666 @@ -1209,7 +1458,6 @@ return_to_handler:
13670 -.section .rodata,"a"
13671 #include "syscall_table_32.S"
13673 syscall_table_size=(.-sys_call_table)
13674 @@ -1255,15 +1503,18 @@ error_code:
13675 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13678 - movl $(__USER_DS), %ecx
13679 + movl $(__KERNEL_DS), %ecx
13686 movl %esp,%eax # pt_regs pointer
13688 jmp ret_from_exception
13691 +ENDPROC(page_fault)
13694 * Debug traps and NMI can happen at the one SYSENTER instruction
13695 @@ -1305,7 +1556,7 @@ debug_stack_correct:
13697 jmp ret_from_exception
13703 * NMI is doubly nasty. It can happen _while_ we're handling
13704 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
13705 xorl %edx,%edx # zero error code
13706 movl %esp,%eax # pt_regs pointer
13711 jmp restore_all_notrace
13714 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
13715 FIXUP_ESPFIX_STACK # %eax == %esp
13716 xorl %edx,%edx # zero error code
13722 lss 12+4(%esp), %esp # back to espfix stack
13723 CFI_ADJUST_CFA_OFFSET -24
13731 @@ -1395,14 +1652,14 @@ ENTRY(int3)
13733 jmp ret_from_exception
13738 ENTRY(general_protection)
13740 pushl_cfi $do_general_protection
13743 -END(general_protection)
13744 +ENDPROC(general_protection)
13746 #ifdef CONFIG_KVM_GUEST
13747 ENTRY(async_page_fault)
13748 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
13749 pushl_cfi $do_async_page_fault
13752 -END(async_page_fault)
13753 +ENDPROC(async_page_fault)
13757 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
13758 index faf8d5e..4f16a68 100644
13759 --- a/arch/x86/kernel/entry_64.S
13760 +++ b/arch/x86/kernel/entry_64.S
13762 #include <asm/paravirt.h>
13763 #include <asm/ftrace.h>
13764 #include <asm/percpu.h>
13765 +#include <asm/pgtable.h>
13766 +#include <asm/alternative-asm.h>
13768 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13769 #include <linux/elf-em.h>
13771 #ifdef CONFIG_FUNCTION_TRACER
13772 #ifdef CONFIG_DYNAMIC_FTRACE
13774 + pax_force_retaddr
13779 ENTRY(ftrace_caller)
13780 cmpl $0, function_trace_stop
13781 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
13784 GLOBAL(ftrace_stub)
13785 + pax_force_retaddr
13787 -END(ftrace_caller)
13788 +ENDPROC(ftrace_caller)
13790 #else /* ! CONFIG_DYNAMIC_FTRACE */
13792 @@ -112,6 +116,7 @@ ENTRY(mcount)
13795 GLOBAL(ftrace_stub)
13796 + pax_force_retaddr
13800 @@ -121,12 +126,13 @@ trace:
13802 subq $MCOUNT_INSN_SIZE, %rdi
13804 + pax_force_fptr ftrace_trace_function
13805 call *ftrace_trace_function
13807 MCOUNT_RESTORE_FRAME
13812 #endif /* CONFIG_DYNAMIC_FTRACE */
13813 #endif /* CONFIG_FUNCTION_TRACER */
13815 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
13817 MCOUNT_RESTORE_FRAME
13819 + pax_force_retaddr
13821 -END(ftrace_graph_caller)
13822 +ENDPROC(ftrace_graph_caller)
13824 GLOBAL(return_to_handler)
13826 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
13830 + pax_force_fptr %rdi
13834 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
13835 ENDPROC(native_usergs_sysret64)
13836 #endif /* CONFIG_PARAVIRT */
13838 + .macro ljmpq sel, off
13839 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13840 + .byte 0x48; ljmp *1234f(%rip)
13841 + .pushsection .rodata
13843 + 1234: .quad \off; .word \sel
13852 + .macro pax_enter_kernel
13853 + pax_set_fptr_mask
13854 +#ifdef CONFIG_PAX_KERNEXEC
13855 + call pax_enter_kernel
13859 + .macro pax_exit_kernel
13860 +#ifdef CONFIG_PAX_KERNEXEC
13861 + call pax_exit_kernel
13865 +#ifdef CONFIG_PAX_KERNEXEC
13866 +ENTRY(pax_enter_kernel)
13869 +#ifdef CONFIG_PARAVIRT
13870 + PV_SAVE_REGS(CLBR_RDI)
13877 + cmp $__KERNEL_CS,%edi
13881 +#ifdef CONFIG_PARAVIRT
13882 + PV_RESTORE_REGS(CLBR_RDI)
13886 + pax_force_retaddr
13889 +2: ljmpq __KERNEL_CS,1f
13890 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
13891 +4: SET_RDI_INTO_CR0
13893 +ENDPROC(pax_enter_kernel)
13895 +ENTRY(pax_exit_kernel)
13898 +#ifdef CONFIG_PARAVIRT
13899 + PV_SAVE_REGS(CLBR_RDI)
13903 + cmp $__KERNEXEC_KERNEL_CS,%edi
13907 +#ifdef CONFIG_PARAVIRT
13908 + PV_RESTORE_REGS(CLBR_RDI);
13912 + pax_force_retaddr
13915 +2: GET_CR0_INTO_RDI
13917 + ljmpq __KERNEL_CS,3f
13918 +3: SET_RDI_INTO_CR0
13920 +#ifdef CONFIG_PARAVIRT
13921 + PV_RESTORE_REGS(CLBR_RDI);
13925 + pax_force_retaddr
13927 +ENDPROC(pax_exit_kernel)
13930 + .macro pax_enter_kernel_user
13931 + pax_set_fptr_mask
13932 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13933 + call pax_enter_kernel_user
13937 + .macro pax_exit_kernel_user
13938 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13939 + call pax_exit_kernel_user
13941 +#ifdef CONFIG_PAX_RANDKSTACK
13943 + call pax_randomize_kstack
13948 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13949 +ENTRY(pax_enter_kernel_user)
13953 +#ifdef CONFIG_PARAVIRT
13954 + PV_SAVE_REGS(CLBR_RDI)
13959 + add $__START_KERNEL_map,%rbx
13960 + sub phys_base(%rip),%rbx
13962 +#ifdef CONFIG_PARAVIRT
13964 + cmpl $0, pv_info+PARAVIRT_enabled
13967 + .rept USER_PGD_PTRS
13968 + mov i*8(%rbx),%rsi
13970 + lea i*8(%rbx),%rdi
13971 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13979 + .rept USER_PGD_PTRS
13980 + movb $0,i*8(%rbx)
13984 +#ifdef CONFIG_PARAVIRT
13989 +#ifdef CONFIG_PAX_KERNEXEC
13995 +#ifdef CONFIG_PARAVIRT
13996 + PV_RESTORE_REGS(CLBR_RDI)
14001 + pax_force_retaddr
14003 +ENDPROC(pax_enter_kernel_user)
14005 +ENTRY(pax_exit_kernel_user)
14008 +#ifdef CONFIG_PARAVIRT
14010 + PV_SAVE_REGS(CLBR_RDI)
14013 +#ifdef CONFIG_PAX_KERNEXEC
14020 + add $__START_KERNEL_map,%rdi
14021 + sub phys_base(%rip),%rdi
14023 +#ifdef CONFIG_PARAVIRT
14024 + cmpl $0, pv_info+PARAVIRT_enabled
14028 + .rept USER_PGD_PTRS
14029 + mov i*8(%rbx),%rsi
14031 + lea i*8(%rbx),%rdi
14032 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
14040 + .rept USER_PGD_PTRS
14041 + movb $0x67,i*8(%rdi)
14045 +#ifdef CONFIG_PARAVIRT
14046 +2: PV_RESTORE_REGS(CLBR_RDI)
14051 + pax_force_retaddr
14053 +ENDPROC(pax_exit_kernel_user)
14056 +.macro pax_erase_kstack
14057 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14058 + call pax_erase_kstack
14062 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14064 + * r11: thread_info
14065 + * rcx, rdx: can be clobbered
14067 +ENTRY(pax_erase_kstack)
14072 + GET_THREAD_INFO(%r11)
14073 + mov TI_lowest_stack(%r11), %rdi
14074 + mov $-0xBEEF, %rax
14078 + and $THREAD_SIZE_asm - 1, %ecx
14095 + cmp $THREAD_SIZE_asm, %rcx
14103 + mov TI_task_thread_sp0(%r11), %rdi
14105 + mov %rdi, TI_lowest_stack(%r11)
14110 + pax_force_retaddr
14112 +ENDPROC(pax_erase_kstack)
14115 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14116 #ifdef CONFIG_TRACE_IRQFLAGS
14117 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
14120 .macro UNFAKE_STACK_FRAME
14122 - CFI_ADJUST_CFA_OFFSET -(6*8)
14123 + addq $8*6 + ARG_SKIP, %rsp
14124 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
14128 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
14131 leaq -RBP(%rsp),%rdi /* arg1 for handler */
14132 - testl $3, CS(%rdi)
14133 + testb $3, CS(%rdi)
14137 @@ -355,9 +639,10 @@ ENTRY(save_rest)
14138 movq_cfi r15, R15+16
14139 movq %r11, 8(%rsp) /* return address */
14140 FIXUP_TOP_OF_STACK %r11, 16
14141 + pax_force_retaddr
14145 +ENDPROC(save_rest)
14147 /* save complete stack frame */
14148 .pushsection .kprobes.text, "ax"
14149 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
14150 js 1f /* negative -> in kernel */
14154 +1: pax_force_retaddr_bts
14157 -END(save_paranoid)
14158 +ENDPROC(save_paranoid)
14162 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
14166 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14167 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14168 je int_ret_from_sys_call
14170 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14171 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
14172 jmp ret_from_sys_call # go to the SYSRET fastpath
14175 -END(ret_from_fork)
14176 +ENDPROC(ret_from_fork)
14179 * System call entry. Up to 6 arguments in registers are supported.
14180 @@ -456,7 +742,7 @@ END(ret_from_fork)
14182 CFI_STARTPROC simple
14184 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14185 + CFI_DEF_CFA rsp,0
14186 CFI_REGISTER rip,rcx
14187 /*CFI_REGISTER rflags,r11*/
14188 SWAPGS_UNSAFE_STACK
14189 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
14191 movq %rsp,PER_CPU_VAR(old_rsp)
14192 movq PER_CPU_VAR(kernel_stack),%rsp
14194 + pax_enter_kernel_user
14196 * No need to follow this irqs off/on section - it's straight
14199 ENABLE_INTERRUPTS(CLBR_NONE)
14201 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14202 movq %rcx,RIP-ARGOFFSET(%rsp)
14203 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14204 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
14205 system_call_fastpath:
14206 cmpq $__NR_syscall_max,%rax
14209 + movq R10-ARGOFFSET(%rsp),%rcx
14210 call *sys_call_table(,%rax,8) # XXX: rip relative
14211 movq %rax,RAX-ARGOFFSET(%rsp)
14213 @@ -503,6 +790,8 @@ sysret_check:
14217 + pax_exit_kernel_user
14220 * sysretq will re-enable interrupts:
14222 @@ -554,14 +843,18 @@ badsys:
14223 * jump back to the normal fast path.
14226 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
14227 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
14228 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
14229 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
14230 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
14231 movq %rax,%rsi /* 2nd arg: syscall number */
14232 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14233 call audit_syscall_entry
14237 LOAD_ARGS 0 /* reload call-clobbered registers */
14238 + pax_set_fptr_mask
14239 jmp system_call_fastpath
14242 @@ -591,16 +884,20 @@ tracesys:
14243 FIXUP_TOP_OF_STACK %rdi
14245 call syscall_trace_enter
14250 * Reload arg registers from stack in case ptrace changed them.
14251 * We don't reload %rax because syscall_trace_enter() returned
14252 * the value it wants us to use in the table lookup.
14254 LOAD_ARGS ARGOFFSET, 1
14255 + pax_set_fptr_mask
14257 cmpq $__NR_syscall_max,%rax
14258 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
14259 - movq %r10,%rcx /* fixup for C */
14260 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
14261 call *sys_call_table(,%rax,8)
14262 movq %rax,RAX-ARGOFFSET(%rsp)
14263 /* Use IRET because user could have changed frame */
14264 @@ -612,7 +909,7 @@ tracesys:
14265 GLOBAL(int_ret_from_sys_call)
14266 DISABLE_INTERRUPTS(CLBR_NONE)
14268 - testl $3,CS-ARGOFFSET(%rsp)
14269 + testb $3,CS-ARGOFFSET(%rsp)
14270 je retint_restore_args
14271 movl $_TIF_ALLWORK_MASK,%edi
14272 /* edi: mask to check */
14273 @@ -623,6 +920,7 @@ GLOBAL(int_with_check)
14276 andl $~TS_COMPAT,TI_status(%rcx)
14280 /* Either reschedule or signal or syscall exit tracking needed. */
14281 @@ -669,7 +967,7 @@ int_restore_rest:
14286 +ENDPROC(system_call)
14289 * Certain special system calls that need to save a complete full stack frame.
14290 @@ -685,7 +983,7 @@ ENTRY(\label)
14292 jmp ptregscall_common
14298 PTREGSCALL stub_clone, sys_clone, %r8
14299 @@ -703,9 +1001,10 @@ ENTRY(ptregscall_common)
14300 movq_cfi_restore R12+8, r12
14301 movq_cfi_restore RBP+8, rbp
14302 movq_cfi_restore RBX+8, rbx
14303 + pax_force_retaddr
14304 ret $REST_SKIP /* pop extended registers */
14306 -END(ptregscall_common)
14307 +ENDPROC(ptregscall_common)
14311 @@ -720,7 +1019,7 @@ ENTRY(stub_execve)
14313 jmp int_ret_from_sys_call
14316 +ENDPROC(stub_execve)
14319 * sigreturn is special because it needs to restore all registers on return.
14320 @@ -738,7 +1037,7 @@ ENTRY(stub_rt_sigreturn)
14322 jmp int_ret_from_sys_call
14324 -END(stub_rt_sigreturn)
14325 +ENDPROC(stub_rt_sigreturn)
14328 * Build the entry stubs and pointer table with some assembler magic.
14329 @@ -773,7 +1072,7 @@ vector=vector+1
14330 2: jmp common_interrupt
14333 -END(irq_entries_start)
14334 +ENDPROC(irq_entries_start)
14338 @@ -793,6 +1092,16 @@ END(interrupt)
14339 subq $ORIG_RAX-RBP, %rsp
14340 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14343 + testb $3, CS(%rdi)
14347 +1: pax_enter_kernel_user
14355 @@ -824,7 +1133,7 @@ ret_from_intr:
14358 GET_THREAD_INFO(%rcx)
14359 - testl $3,CS-ARGOFFSET(%rsp)
14360 + testb $3,CS-ARGOFFSET(%rsp)
14363 /* Interrupt came from user space */
14364 @@ -846,12 +1155,15 @@ retint_swapgs: /* return to user-space */
14365 * The iretq could re-enable interrupts:
14367 DISABLE_INTERRUPTS(CLBR_ANY)
14368 + pax_exit_kernel_user
14373 retint_restore_args: /* return to kernel space */
14374 DISABLE_INTERRUPTS(CLBR_ANY)
14376 + pax_force_retaddr RIP-ARGOFFSET
14378 * The iretq could re-enable interrupts:
14380 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
14384 -END(common_interrupt)
14385 +ENDPROC(common_interrupt)
14387 * End of kprobes section
14389 @@ -956,7 +1268,7 @@ ENTRY(\sym)
14398 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
14399 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14403 + testb $3, CS(%rsp)
14407 +1: pax_enter_kernel_user
14412 movq %rsp,%rdi /* pt_regs pointer */
14413 xorl %esi,%esi /* no error code */
14415 jmp error_exit /* %ebx: no swapgs flag */
14421 .macro paranoidzeroentry sym do_sym
14422 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
14423 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14426 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14427 + testb $3, CS(%rsp)
14431 +1: pax_enter_kernel_user
14436 movq %rsp,%rdi /* pt_regs pointer */
14437 xorl %esi,%esi /* no error code */
14439 jmp paranoid_exit /* %ebx: no swapgs flag */
14445 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14446 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14447 .macro paranoidzeroentry_ist sym do_sym ist
14450 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
14451 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14455 + testb $3, CS(%rsp)
14459 +1: pax_enter_kernel_user
14464 movq %rsp,%rdi /* pt_regs pointer */
14465 xorl %esi,%esi /* no error code */
14467 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14468 + lea init_tss(%r12), %r12
14470 + lea init_tss(%rip), %r12
14472 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14474 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14475 jmp paranoid_exit /* %ebx: no swapgs flag */
14481 .macro errorentry sym do_sym
14482 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
14483 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14487 + testb $3, CS(%rsp)
14491 +1: pax_enter_kernel_user
14496 movq %rsp,%rdi /* pt_regs pointer */
14497 movq ORIG_RAX(%rsp),%rsi /* get error code */
14498 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14500 jmp error_exit /* %ebx: no swapgs flag */
14506 /* error code is on the stack already */
14507 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
14511 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14512 + testb $3, CS(%rsp)
14516 +1: pax_enter_kernel_user
14521 movq %rsp,%rdi /* pt_regs pointer */
14522 movq ORIG_RAX(%rsp),%rsi /* get error code */
14523 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14525 jmp paranoid_exit /* %ebx: no swapgs flag */
14531 zeroentry divide_error do_divide_error
14532 @@ -1129,9 +1497,10 @@ gs_change:
14533 2: mfence /* workaround */
14536 + pax_force_retaddr
14539 -END(native_load_gs_index)
14540 +ENDPROC(native_load_gs_index)
14542 .section __ex_table,"a"
14544 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
14545 * Here we are in the child and the registers are set as they were
14546 * at kernel_thread() invocation in the parent.
14548 + pax_force_fptr %rsi
14553 ud2 # padding for call trace
14555 -END(kernel_thread_helper)
14556 +ENDPROC(kernel_thread_helper)
14559 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
14560 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
14563 je int_ret_from_sys_call
14566 + pax_force_retaddr
14569 -END(kernel_execve)
14570 +ENDPROC(kernel_execve)
14572 /* Call softirq on interrupt stack. Interrupts are off. */
14573 ENTRY(call_softirq)
14574 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
14575 CFI_DEF_CFA_REGISTER rsp
14576 CFI_ADJUST_CFA_OFFSET -8
14577 decl PER_CPU_VAR(irq_count)
14578 + pax_force_retaddr
14582 +ENDPROC(call_softirq)
14585 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
14586 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
14587 decl PER_CPU_VAR(irq_count)
14590 -END(xen_do_hypervisor_callback)
14591 +ENDPROC(xen_do_hypervisor_callback)
14594 * Hypervisor uses this for application faults while it executes.
14595 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
14599 -END(xen_failsafe_callback)
14600 +ENDPROC(xen_failsafe_callback)
14602 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
14603 xen_hvm_callback_vector xen_evtchn_do_upcall
14604 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
14606 testl %ebx,%ebx /* swapgs needed? */
14607 jnz paranoid_restore
14608 - testl $3,CS(%rsp)
14609 + testb $3,CS(%rsp)
14610 jnz paranoid_userspace
14611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14613 + TRACE_IRQS_IRETQ 0
14614 + SWAPGS_UNSAFE_STACK
14616 + pax_force_retaddr_bts
14620 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14621 + pax_exit_kernel_user
14626 SWAPGS_UNSAFE_STACK
14633 + pax_force_retaddr_bts
14635 paranoid_userspace:
14636 GET_THREAD_INFO(%rcx)
14637 @@ -1394,7 +1780,7 @@ paranoid_schedule:
14639 jmp paranoid_userspace
14641 -END(paranoid_exit)
14642 +ENDPROC(paranoid_exit)
14645 * Exception entry point. This expects an error code/orig_rax on the stack.
14646 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
14647 movq_cfi r14, R14+8
14648 movq_cfi r15, R15+8
14650 - testl $3,CS+8(%rsp)
14651 + testb $3,CS+8(%rsp)
14652 je error_kernelspace
14657 + pax_force_retaddr_bts
14661 @@ -1453,7 +1840,7 @@ bstep_iret:
14662 movq %rcx,RIP+8(%rsp)
14666 +ENDPROC(error_entry)
14669 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
14670 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
14675 +ENDPROC(error_exit)
14678 /* runs on exception stack */
14679 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
14680 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14684 + testb $3, CS(%rsp)
14688 +1: pax_enter_kernel_user
14693 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14696 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
14697 DISABLE_INTERRUPTS(CLBR_NONE)
14698 testl %ebx,%ebx /* swapgs needed? */
14700 - testl $3,CS(%rsp)
14701 + testb $3,CS(%rsp)
14703 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14705 + SWAPGS_UNSAFE_STACK
14707 + pax_force_retaddr_bts
14711 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14712 + pax_exit_kernel_user
14716 SWAPGS_UNSAFE_STACK
14722 + pax_force_retaddr_bts
14725 GET_THREAD_INFO(%rcx)
14726 @@ -1529,14 +1942,14 @@ nmi_schedule:
14733 ENTRY(ignore_sysret)
14738 -END(ignore_sysret)
14739 +ENDPROC(ignore_sysret)
14742 * End of kprobes section
14743 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
14744 index c9a281f..ce2f317 100644
14745 --- a/arch/x86/kernel/ftrace.c
14746 +++ b/arch/x86/kernel/ftrace.c
14747 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
14748 static const void *mod_code_newcode; /* holds the text to write to the IP */
14750 static unsigned nmi_wait_count;
14751 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14752 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14754 int ftrace_arch_read_dyn_info(char *buf, int size)
14756 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
14758 r = snprintf(buf, size, "%u %u",
14760 - atomic_read(&nmi_update_count));
14761 + atomic_read_unchecked(&nmi_update_count));
14765 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14767 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14769 + pax_open_kernel();
14771 - atomic_inc(&nmi_update_count);
14772 + pax_close_kernel();
14773 + atomic_inc_unchecked(&nmi_update_count);
14775 /* Must have previous changes seen before executions */
14777 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
14779 unsigned char replaced[MCOUNT_INSN_SIZE];
14781 + ip = ktla_ktva(ip);
14784 * Note: Due to modules and __init, code can
14785 * disappear and change, we need to protect against faulting
14786 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
14787 unsigned char old[MCOUNT_INSN_SIZE], *new;
14790 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14791 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14792 new = ftrace_call_replace(ip, (unsigned long)func);
14793 ret = ftrace_modify_code(ip, old, new);
14795 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
14797 unsigned char code[MCOUNT_INSN_SIZE];
14799 + ip = ktla_ktva(ip);
14801 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14804 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
14805 index 3bb0850..55a56f4 100644
14806 --- a/arch/x86/kernel/head32.c
14807 +++ b/arch/x86/kernel/head32.c
14809 #include <asm/io_apic.h>
14810 #include <asm/bios_ebda.h>
14811 #include <asm/tlbflush.h>
14812 +#include <asm/boot.h>
14814 static void __init i386_default_early_setup(void)
14816 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
14820 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14821 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14823 #ifdef CONFIG_BLK_DEV_INITRD
14824 /* Reserve INITRD */
14825 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
14826 index ce0be7c..c41476e 100644
14827 --- a/arch/x86/kernel/head_32.S
14828 +++ b/arch/x86/kernel/head_32.S
14830 /* Physical address */
14831 #define pa(X) ((X) - __PAGE_OFFSET)
14833 +#ifdef CONFIG_PAX_KERNEXEC
14836 +#define ta(X) ((X) - __PAGE_OFFSET)
14840 * References to members of the new_cpu_data structure.
14843 * and small than max_low_pfn, otherwise will waste some page table entries
14846 -#if PTRS_PER_PMD > 1
14847 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14849 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14851 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14853 /* Number of possible pages in the lowmem region */
14854 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14855 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
14856 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14859 + * Real beginning of normal "text" segment
14865 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14866 * %esi points to the real-mode code as a 32-bit pointer.
14867 * CS and DS must be 4 GB flat segments, but we don't depend on
14868 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14873 +#ifdef CONFIG_PAX_KERNEXEC
14875 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14876 +.fill PAGE_SIZE-5,1,0xcc
14880 movl pa(stack_start),%ecx
14882 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14884 leal -__PAGE_OFFSET(%ecx),%esp
14887 + movl $pa(cpu_gdt_table),%edi
14888 + movl $__per_cpu_load,%eax
14889 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14891 + movb %al,__KERNEL_PERCPU + 4(%edi)
14892 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14893 + movl $__per_cpu_end - 1,%eax
14894 + subl $__per_cpu_start,%eax
14895 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14898 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14899 + movl $NR_CPUS,%ecx
14900 + movl $pa(cpu_gdt_table),%edi
14902 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14903 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14904 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14905 + addl $PAGE_SIZE_asm,%edi
14909 +#ifdef CONFIG_PAX_KERNEXEC
14910 + movl $pa(boot_gdt),%edi
14911 + movl $__LOAD_PHYSICAL_ADDR,%eax
14912 + movw %ax,__BOOT_CS + 2(%edi)
14914 + movb %al,__BOOT_CS + 4(%edi)
14915 + movb %ah,__BOOT_CS + 7(%edi)
14918 + ljmp $(__BOOT_CS),$1f
14921 + movl $NR_CPUS,%ecx
14922 + movl $pa(cpu_gdt_table),%edi
14923 + addl $__PAGE_OFFSET,%eax
14925 + movw %ax,__KERNEL_CS + 2(%edi)
14926 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14928 + movb %al,__KERNEL_CS + 4(%edi)
14929 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14930 + movb %ah,__KERNEL_CS + 7(%edi)
14931 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14933 + addl $PAGE_SIZE_asm,%edi
14938 * Clear BSS first so that there are no surprises...
14940 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14941 movl %eax, pa(max_pfn_mapped)
14943 /* Do early initialization of the fixmap area */
14944 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14945 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14946 +#ifdef CONFIG_COMPAT_VDSO
14947 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14949 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14951 #else /* Not PAE */
14953 page_pde_offset = (__PAGE_OFFSET >> 20);
14954 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14955 movl %eax, pa(max_pfn_mapped)
14957 /* Do early initialization of the fixmap area */
14958 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14959 - movl %eax,pa(initial_page_table+0xffc)
14960 +#ifdef CONFIG_COMPAT_VDSO
14961 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14963 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14967 #ifdef CONFIG_PARAVIRT
14968 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14969 cmpl $num_subarch_entries, %eax
14972 - movl pa(subarch_entries)(,%eax,4), %eax
14973 - subl $__PAGE_OFFSET, %eax
14975 + jmp *pa(subarch_entries)(,%eax,4)
14979 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14983 - .long default_entry /* normal x86/PC */
14984 - .long lguest_entry /* lguest hypervisor */
14985 - .long xen_entry /* Xen hypervisor */
14986 - .long default_entry /* Moorestown MID */
14987 + .long ta(default_entry) /* normal x86/PC */
14988 + .long ta(lguest_entry) /* lguest hypervisor */
14989 + .long ta(xen_entry) /* Xen hypervisor */
14990 + .long ta(default_entry) /* Moorestown MID */
14991 num_subarch_entries = (. - subarch_entries) / 4
14994 @@ -312,6 +382,7 @@ default_entry:
14998 +#ifdef CONFIG_X86_PAE
14999 testb $X86_CR4_PAE, %al # check if PAE is enabled
15002 @@ -340,6 +411,9 @@ default_entry:
15003 /* Make changes effective */
15006 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
15012 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
15013 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
15014 movl %eax,%ss # after changing gdt.
15016 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
15017 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
15021 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
15025 - movl $gdt_page,%eax
15026 + movl $cpu_gdt_table,%eax
15027 movl $stack_canary,%ecx
15029 + addl $__per_cpu_load,%ecx
15031 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
15033 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
15034 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
15037 movl $(__KERNEL_STACK_CANARY),%eax
15038 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15039 + movl $(__USER_DS),%eax
15045 xorl %eax,%eax # Clear LDT
15046 @@ -558,22 +639,22 @@ early_page_fault:
15051 #ifdef CONFIG_PRINTK
15052 + cmpl $1,%ss:early_recursion_flag
15054 + incl %ss:early_recursion_flag
15057 movl $(__KERNEL_DS),%eax
15060 - cmpl $2,early_recursion_flag
15062 - incl early_recursion_flag
15065 pushl %edx /* trapno */
15074 @@ -581,8 +662,11 @@ hlt_loop:
15075 /* This is the default interrupt "handler" :-) */
15079 #ifdef CONFIG_PRINTK
15080 + cmpl $2,%ss:early_recursion_flag
15082 + incl %ss:early_recursion_flag
15087 @@ -591,9 +675,6 @@ ignore_int:
15088 movl $(__KERNEL_DS),%eax
15091 - cmpl $2,early_recursion_flag
15093 - incl early_recursion_flag
15097 @@ -622,29 +703,43 @@ ENTRY(initial_code)
15101 -__PAGE_ALIGNED_BSS
15103 #ifdef CONFIG_X86_PAE
15104 +.section .initial_pg_pmd,"a",@progbits
15106 .fill 1024*KPMDS,4,0
15108 +.section .initial_page_table,"a",@progbits
15109 ENTRY(initial_page_table)
15112 +.section .initial_pg_fixmap,"a",@progbits
15115 +.section .empty_zero_page,"a",@progbits
15116 ENTRY(empty_zero_page)
15118 +.section .swapper_pg_dir,"a",@progbits
15119 ENTRY(swapper_pg_dir)
15120 +#ifdef CONFIG_X86_PAE
15127 + * The IDT has to be page-aligned to simplify the Pentium
15128 + * F0 0F bug workaround.. We have a special link segment
15131 +.section .idt,"a",@progbits
15136 * This starts the data section.
15138 #ifdef CONFIG_X86_PAE
15139 -__PAGE_ALIGNED_DATA
15140 - /* Page-aligned for the benefit of paravirt? */
15142 +.section .initial_page_table,"a",@progbits
15143 ENTRY(initial_page_table)
15144 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15146 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15147 # error "Kernel PMDs should be 1, 2 or 3"
15149 .align PAGE_SIZE /* needs to be page-sized too */
15151 +#ifdef CONFIG_PAX_PER_CPU_PGD
15163 - .long init_thread_union+THREAD_SIZE
15164 + .long init_thread_union+THREAD_SIZE-8
15168 +.section .rodata,"a",@progbits
15169 early_recursion_flag:
15175 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15177 @@ -707,7 +811,7 @@ fault_msg:
15178 .word 0 # 32 bit align gdt_desc.address
15181 - .long boot_gdt - __PAGE_OFFSET
15182 + .long pa(boot_gdt)
15184 .word 0 # 32-bit align idt_desc.address
15186 @@ -718,7 +822,7 @@ idt_descr:
15187 .word 0 # 32 bit align gdt_desc.address
15188 ENTRY(early_gdt_descr)
15189 .word GDT_ENTRIES*8-1
15190 - .long gdt_page /* Overwritten for secondary CPUs */
15191 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
15194 * The boot_gdt must mirror the equivalent in setup.S and is
15195 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15196 .align L1_CACHE_BYTES
15198 .fill GDT_ENTRY_BOOT_CS,8,0
15199 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15200 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15201 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15202 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15204 + .align PAGE_SIZE_asm
15205 +ENTRY(cpu_gdt_table)
15207 + .quad 0x0000000000000000 /* NULL descriptor */
15208 + .quad 0x0000000000000000 /* 0x0b reserved */
15209 + .quad 0x0000000000000000 /* 0x13 reserved */
15210 + .quad 0x0000000000000000 /* 0x1b reserved */
15212 +#ifdef CONFIG_PAX_KERNEXEC
15213 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15215 + .quad 0x0000000000000000 /* 0x20 unused */
15218 + .quad 0x0000000000000000 /* 0x28 unused */
15219 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15220 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15221 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15222 + .quad 0x0000000000000000 /* 0x4b reserved */
15223 + .quad 0x0000000000000000 /* 0x53 reserved */
15224 + .quad 0x0000000000000000 /* 0x5b reserved */
15226 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15227 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15228 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15229 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15231 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15232 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15235 + * Segments used for calling PnP BIOS have byte granularity.
15236 + * The code segments and data segments have fixed 64k limits,
15237 + * the transfer segment sizes are set at run time.
15239 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
15240 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
15241 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
15242 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
15243 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
15246 + * The APM segments have byte granularity and their bases
15247 + * are set at run time. All have 64k limits.
15249 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15250 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15251 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
15253 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15254 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15255 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
15256 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15257 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15258 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15260 + /* Be sure this is zeroed to avoid false validations in Xen */
15261 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15263 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
15264 index e11e394..9aebc5d 100644
15265 --- a/arch/x86/kernel/head_64.S
15266 +++ b/arch/x86/kernel/head_64.S
15268 #include <asm/cache.h>
15269 #include <asm/processor-flags.h>
15270 #include <asm/percpu.h>
15271 +#include <asm/cpufeature.h>
15272 +#include <asm/alternative-asm.h>
15274 #ifdef CONFIG_PARAVIRT
15275 #include <asm/asm-offsets.h>
15276 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
15277 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15278 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15279 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15280 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15281 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15282 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
15283 +L3_VMALLOC_END = pud_index(VMALLOC_END)
15284 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15285 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15289 @@ -85,35 +93,23 @@ startup_64:
15291 addq %rbp, init_level4_pgt + 0(%rip)
15292 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15293 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15294 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
15295 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15296 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15298 addq %rbp, level3_ident_pgt + 0(%rip)
15299 +#ifndef CONFIG_XEN
15300 + addq %rbp, level3_ident_pgt + 8(%rip)
15303 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15304 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15305 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15307 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15308 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15310 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15312 - /* Add an Identity mapping if I am above 1G */
15313 - leaq _text(%rip), %rdi
15314 - andq $PMD_PAGE_MASK, %rdi
15317 - shrq $PUD_SHIFT, %rax
15318 - andq $(PTRS_PER_PUD - 1), %rax
15319 - jz ident_complete
15321 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15322 - leaq level3_ident_pgt(%rip), %rbx
15323 - movq %rdx, 0(%rbx, %rax, 8)
15326 - shrq $PMD_SHIFT, %rax
15327 - andq $(PTRS_PER_PMD - 1), %rax
15328 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15329 - leaq level2_spare_pgt(%rip), %rbx
15330 - movq %rdx, 0(%rbx, %rax, 8)
15332 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15335 * Fixup the kernel text+data virtual addresses. Note that
15336 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
15337 * after the boot processor executes this code.
15340 - /* Enable PAE mode and PGE */
15341 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15342 + /* Enable PAE mode and PSE/PGE */
15343 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15346 /* Setup early boot stage 4 level pagetables. */
15347 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
15348 movl $MSR_EFER, %ecx
15350 btsl $_EFER_SCE, %eax /* Enable System Call */
15351 - btl $20,%edi /* No Execute supported? */
15352 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15354 btsl $_EFER_NX, %eax
15355 + leaq init_level4_pgt(%rip), %rdi
15356 +#ifndef CONFIG_EFI
15357 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15359 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15360 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
15361 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15362 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15363 1: wrmsr /* Make changes effective */
15366 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
15367 * jump. In addition we need to ensure %cs is set so we make this
15370 + pax_set_fptr_mask
15371 movq initial_code(%rip),%rax
15372 pushq $0 # fake return address to stop unwinder
15373 pushq $__KERNEL_CS # set correct cs
15374 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
15378 - .section ".init.text","ax"
15380 #ifdef CONFIG_EARLY_PRINTK
15381 .globl early_idt_handlers
15382 early_idt_handlers:
15383 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
15384 #endif /* EARLY_PRINTK */
15389 #ifdef CONFIG_EARLY_PRINTK
15391 early_recursion_flag:
15395 + .section .rodata,"a",@progbits
15397 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15401 #endif /* CONFIG_EARLY_PRINTK */
15404 + .section .rodata,"a",@progbits
15405 #define NEXT_PAGE(name) \
15406 .balign PAGE_SIZE; \
15408 @@ -338,7 +348,6 @@ ENTRY(name)
15414 * This default setting generates an ident mapping at address 0x100000
15415 * and a mapping for the kernel that precisely maps virtual address
15416 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
15417 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15418 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15419 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15420 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15421 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
15422 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
15423 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
15424 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15425 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15426 .org init_level4_pgt + L4_START_KERNEL*8, 0
15427 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15428 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15430 +#ifdef CONFIG_PAX_PER_CPU_PGD
15431 +NEXT_PAGE(cpu_pgd)
15437 NEXT_PAGE(level3_ident_pgt)
15438 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15442 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15446 +NEXT_PAGE(level3_vmalloc_start_pgt)
15449 +NEXT_PAGE(level3_vmalloc_end_pgt)
15452 +NEXT_PAGE(level3_vmemmap_pgt)
15453 + .fill L3_VMEMMAP_START,8,0
15454 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15456 NEXT_PAGE(level3_kernel_pgt)
15457 .fill L3_START_KERNEL,8,0
15458 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
15459 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15460 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15462 +NEXT_PAGE(level2_vmemmap_pgt)
15465 NEXT_PAGE(level2_fixmap_pgt)
15467 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15468 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15471 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15472 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15475 -NEXT_PAGE(level1_fixmap_pgt)
15476 +NEXT_PAGE(level1_vsyscall_pgt)
15479 -NEXT_PAGE(level2_ident_pgt)
15480 - /* Since I easily can, map the first 1G.
15481 + /* Since I easily can, map the first 2G.
15482 * Don't set NX because code runs from these pages.
15484 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15485 +NEXT_PAGE(level2_ident_pgt)
15486 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15488 NEXT_PAGE(level2_kernel_pgt)
15490 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
15491 * If you want to increase this then increase MODULES_VADDR
15494 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15495 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15497 -NEXT_PAGE(level2_spare_pgt)
15499 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15506 +ENTRY(cpu_gdt_table)
15508 + .quad 0x0000000000000000 /* NULL descriptor */
15509 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15510 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15511 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15512 + .quad 0x00cffb000000ffff /* __USER32_CS */
15513 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15514 + .quad 0x00affb000000ffff /* __USER_CS */
15516 +#ifdef CONFIG_PAX_KERNEXEC
15517 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15519 + .quad 0x0 /* unused */
15522 + .quad 0,0 /* TSS */
15523 + .quad 0,0 /* LDT */
15524 + .quad 0,0,0 /* three TLS descriptors */
15525 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15526 + /* asm/segment.h:GDT_ENTRIES must match this */
15528 + /* zero the remaining page */
15529 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15533 .globl early_gdt_descr
15535 .word GDT_ENTRIES*8-1
15536 early_gdt_descr_base:
15537 - .quad INIT_PER_CPU_VAR(gdt_page)
15538 + .quad cpu_gdt_table
15541 /* This must match the first entry in level2_kernel_pgt */
15542 .quad 0x0000000000000000
15544 #include "../../x86/xen/xen-head.S"
15546 - .section .bss, "aw", @nobits
15548 + .section .rodata,"a",@progbits
15549 .align L1_CACHE_BYTES
15551 - .skip IDT_ENTRIES * 16
15556 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
15557 index 9c3bd4a..e1d9b35 100644
15558 --- a/arch/x86/kernel/i386_ksyms_32.c
15559 +++ b/arch/x86/kernel/i386_ksyms_32.c
15560 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15561 EXPORT_SYMBOL(cmpxchg8b_emu);
15564 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15566 /* Networking helper routines. */
15567 EXPORT_SYMBOL(csum_partial_copy_generic);
15568 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15569 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15571 EXPORT_SYMBOL(__get_user_1);
15572 EXPORT_SYMBOL(__get_user_2);
15573 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15575 EXPORT_SYMBOL(csum_partial);
15576 EXPORT_SYMBOL(empty_zero_page);
15578 +#ifdef CONFIG_PAX_KERNEXEC
15579 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15581 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
15582 index 6104852..6114160 100644
15583 --- a/arch/x86/kernel/i8259.c
15584 +++ b/arch/x86/kernel/i8259.c
15585 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15586 "spurious 8259A interrupt: IRQ%d.\n", irq);
15587 spurious_irq_mask |= irqmask;
15589 - atomic_inc(&irq_err_count);
15590 + atomic_inc_unchecked(&irq_err_count);
15592 * Theoretically we do not have to handle this IRQ,
15593 * but in Linux this does not cause problems and is
15594 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
15595 index 43e9ccf..44ccf6f 100644
15596 --- a/arch/x86/kernel/init_task.c
15597 +++ b/arch/x86/kernel/init_task.c
15598 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
15599 * way process stacks are handled. This is done by having a special
15600 * "init_task" linker map entry..
15602 -union thread_union init_thread_union __init_task_data =
15603 - { INIT_THREAD_INFO(init_task) };
15604 +union thread_union init_thread_union __init_task_data;
15607 * Initial task structure.
15608 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15609 * section. Since TSS's are completely CPU-local, we want them
15610 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15612 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15614 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15615 +EXPORT_SYMBOL(init_tss);
15616 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
15617 index 8c96897..be66bfa 100644
15618 --- a/arch/x86/kernel/ioport.c
15619 +++ b/arch/x86/kernel/ioport.c
15621 #include <linux/sched.h>
15622 #include <linux/kernel.h>
15623 #include <linux/capability.h>
15624 +#include <linux/security.h>
15625 #include <linux/errno.h>
15626 #include <linux/types.h>
15627 #include <linux/ioport.h>
15628 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15630 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15632 +#ifdef CONFIG_GRKERNSEC_IO
15633 + if (turn_on && grsec_disable_privio) {
15634 + gr_handle_ioperm();
15638 if (turn_on && !capable(CAP_SYS_RAWIO))
15641 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15642 * because the ->io_bitmap_max value must match the bitmap
15645 - tss = &per_cpu(init_tss, get_cpu());
15646 + tss = init_tss + get_cpu();
15649 bitmap_clear(t->io_bitmap_ptr, from, num);
15650 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
15652 /* Trying to gain more privileges? */
15654 +#ifdef CONFIG_GRKERNSEC_IO
15655 + if (grsec_disable_privio) {
15656 + gr_handle_iopl();
15660 if (!capable(CAP_SYS_RAWIO))
15663 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
15664 index 429e0c9..17b3ece 100644
15665 --- a/arch/x86/kernel/irq.c
15666 +++ b/arch/x86/kernel/irq.c
15668 #include <asm/mce.h>
15669 #include <asm/hw_irq.h>
15671 -atomic_t irq_err_count;
15672 +atomic_unchecked_t irq_err_count;
15674 /* Function pointer for generic interrupt vector handling */
15675 void (*x86_platform_ipi_callback)(void) = NULL;
15676 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
15677 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15678 seq_printf(p, " Machine check polls\n");
15680 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15681 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15682 #if defined(CONFIG_X86_IO_APIC)
15683 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15684 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15688 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15690 u64 arch_irq_stat(void)
15692 - u64 sum = atomic_read(&irq_err_count);
15693 + u64 sum = atomic_read_unchecked(&irq_err_count);
15695 #ifdef CONFIG_X86_IO_APIC
15696 - sum += atomic_read(&irq_mis_count);
15697 + sum += atomic_read_unchecked(&irq_mis_count);
15701 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
15702 index 7209070..cbcd71a 100644
15703 --- a/arch/x86/kernel/irq_32.c
15704 +++ b/arch/x86/kernel/irq_32.c
15705 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15706 __asm__ __volatile__("andl %%esp,%0" :
15707 "=r" (sp) : "0" (THREAD_SIZE - 1));
15709 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15710 + return sp < STACK_WARN;
15713 static void print_stack_overflow(void)
15714 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
15715 * per-CPU IRQ handling contexts (thread information and stack)
15718 - struct thread_info tinfo;
15719 - u32 stack[THREAD_SIZE/sizeof(u32)];
15720 + unsigned long previous_esp;
15721 + u32 stack[THREAD_SIZE/sizeof(u32)];
15722 } __attribute__((aligned(THREAD_SIZE)));
15724 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15725 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
15727 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15729 - union irq_ctx *curctx, *irqctx;
15730 + union irq_ctx *irqctx;
15731 u32 *isp, arg1, arg2;
15733 - curctx = (union irq_ctx *) current_thread_info();
15734 irqctx = __this_cpu_read(hardirq_ctx);
15737 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15738 * handler) we can't do that and just have to keep using the
15739 * current stack (which is the irq stack already after all)
15741 - if (unlikely(curctx == irqctx))
15742 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15745 /* build the stack frame on the IRQ stack */
15746 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15747 - irqctx->tinfo.task = curctx->tinfo.task;
15748 - irqctx->tinfo.previous_esp = current_stack_pointer;
15749 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15750 + irqctx->previous_esp = current_stack_pointer;
15753 - * Copy the softirq bits in preempt_count so that the
15754 - * softirq checks work in the hardirq context.
15756 - irqctx->tinfo.preempt_count =
15757 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15758 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15759 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15760 + __set_fs(MAKE_MM_SEG(0));
15763 if (unlikely(overflow))
15764 call_on_stack(print_stack_overflow, isp);
15765 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15766 : "0" (irq), "1" (desc), "2" (isp),
15767 "D" (desc->handle_irq)
15768 : "memory", "cc", "ecx");
15770 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15771 + __set_fs(current_thread_info()->addr_limit);
15777 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15779 void __cpuinit irq_ctx_init(int cpu)
15781 - union irq_ctx *irqctx;
15783 if (per_cpu(hardirq_ctx, cpu))
15786 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15789 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15790 - irqctx->tinfo.cpu = cpu;
15791 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15792 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15794 - per_cpu(hardirq_ctx, cpu) = irqctx;
15796 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15799 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15800 - irqctx->tinfo.cpu = cpu;
15801 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15803 - per_cpu(softirq_ctx, cpu) = irqctx;
15804 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15805 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15807 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15808 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15809 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
15810 asmlinkage void do_softirq(void)
15812 unsigned long flags;
15813 - struct thread_info *curctx;
15814 union irq_ctx *irqctx;
15817 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
15818 local_irq_save(flags);
15820 if (local_softirq_pending()) {
15821 - curctx = current_thread_info();
15822 irqctx = __this_cpu_read(softirq_ctx);
15823 - irqctx->tinfo.task = curctx->task;
15824 - irqctx->tinfo.previous_esp = current_stack_pointer;
15825 + irqctx->previous_esp = current_stack_pointer;
15827 /* build the stack frame on the softirq stack */
15828 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15829 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15831 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15832 + __set_fs(MAKE_MM_SEG(0));
15835 call_on_stack(__do_softirq, isp);
15837 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15838 + __set_fs(current_thread_info()->addr_limit);
15842 * Shouldn't happen, we returned above if in_interrupt():
15844 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
15845 index 69bca46..0bac999 100644
15846 --- a/arch/x86/kernel/irq_64.c
15847 +++ b/arch/x86/kernel/irq_64.c
15848 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
15849 #ifdef CONFIG_DEBUG_STACKOVERFLOW
15850 u64 curbase = (u64)task_stack_page(current);
15852 - if (user_mode_vm(regs))
15853 + if (user_mode(regs))
15856 WARN_ONCE(regs->sp >= curbase &&
15857 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
15858 index faba577..93b9e71 100644
15859 --- a/arch/x86/kernel/kgdb.c
15860 +++ b/arch/x86/kernel/kgdb.c
15861 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
15862 #ifdef CONFIG_X86_32
15865 - if (!user_mode_vm(regs))
15866 + if (!user_mode(regs))
15867 *(unsigned long *)mem = __KERNEL_DS;
15870 - if (!user_mode_vm(regs))
15871 + if (!user_mode(regs))
15872 *(unsigned long *)mem = kernel_stack_pointer(regs);
15875 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
15877 /* clear the trace bit */
15878 linux_regs->flags &= ~X86_EFLAGS_TF;
15879 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15880 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15882 /* set the trace bit if we're stepping */
15883 if (remcomInBuffer[0] == 's') {
15884 linux_regs->flags |= X86_EFLAGS_TF;
15885 - atomic_set(&kgdb_cpu_doing_single_step,
15886 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15887 raw_smp_processor_id());
15890 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
15894 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15895 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15896 if (user_mode(regs))
15897 return single_step_cont(regs, args);
15899 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
15900 index 7da647d..56fe348 100644
15901 --- a/arch/x86/kernel/kprobes.c
15902 +++ b/arch/x86/kernel/kprobes.c
15903 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
15904 } __attribute__((packed)) *insn;
15906 insn = (struct __arch_relative_insn *)from;
15908 + pax_open_kernel();
15909 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15911 + pax_close_kernel();
15914 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15915 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
15916 kprobe_opcode_t opcode;
15917 kprobe_opcode_t *orig_opcodes = opcodes;
15919 - if (search_exception_tables((unsigned long)opcodes))
15920 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15921 return 0; /* Page fault may occur on this address. */
15924 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15927 insn_get_length(&insn);
15928 + pax_open_kernel();
15929 memcpy(dest, insn.kaddr, insn.length);
15930 + pax_close_kernel();
15932 #ifdef CONFIG_X86_64
15933 if (insn_rip_relative(&insn)) {
15934 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15936 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15937 disp = (u8 *) dest + insn_offset_displacement(&insn);
15938 + pax_open_kernel();
15939 *(s32 *) disp = (s32) newdisp;
15940 + pax_close_kernel();
15943 return insn.length;
15944 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
15946 __copy_instruction(p->ainsn.insn, p->addr, 0);
15948 - if (can_boost(p->addr))
15949 + if (can_boost(ktla_ktva(p->addr)))
15950 p->ainsn.boostable = 0;
15952 p->ainsn.boostable = -1;
15954 - p->opcode = *p->addr;
15955 + p->opcode = *(ktla_ktva(p->addr));
15958 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15959 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15960 * nor set current_kprobe, because it doesn't use single
15963 - regs->ip = (unsigned long)p->ainsn.insn;
15964 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15965 preempt_enable_no_resched();
15968 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15969 if (p->opcode == BREAKPOINT_INSTRUCTION)
15970 regs->ip = (unsigned long)p->addr;
15972 - regs->ip = (unsigned long)p->ainsn.insn;
15973 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15977 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
15978 setup_singlestep(p, regs, kcb, 0);
15981 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15982 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15984 * The breakpoint instruction was removed right
15985 * after we hit it. Another cpu has removed
15986 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
15987 " movq %rax, 152(%rsp)\n"
15988 RESTORE_REGS_STRING
15990 +#ifdef KERNEXEC_PLUGIN
15991 + " btsq $63,(%rsp)\n"
15996 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
15997 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15999 unsigned long *tos = stack_addr(regs);
16000 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
16001 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
16002 unsigned long orig_ip = (unsigned long)p->addr;
16003 kprobe_opcode_t *insn = p->ainsn.insn;
16005 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
16006 struct die_args *args = data;
16007 int ret = NOTIFY_DONE;
16009 - if (args->regs && user_mode_vm(args->regs))
16010 + if (args->regs && user_mode(args->regs))
16014 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
16015 * Verify if the address gap is in 2GB range, because this uses
16018 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
16019 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
16020 if (abs(rel) > 0x7fffffff)
16023 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
16024 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
16026 /* Set probe function call */
16027 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
16028 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
16030 /* Set returning jmp instruction at the tail of out-of-line buffer */
16031 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
16032 - (u8 *)op->kp.addr + op->optinsn.size);
16033 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
16035 flush_icache_range((unsigned long) buf,
16036 (unsigned long) buf + TMPL_END_IDX +
16037 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
16038 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
16040 /* Backup instructions which will be replaced by jump address */
16041 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
16042 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
16043 RELATIVE_ADDR_SIZE);
16045 insn_buf[0] = RELATIVEJUMP_OPCODE;
16046 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
16047 index a9c2116..a52d4fc 100644
16048 --- a/arch/x86/kernel/kvm.c
16049 +++ b/arch/x86/kernel/kvm.c
16050 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
16051 pv_mmu_ops.set_pud = kvm_set_pud;
16052 #if PAGETABLE_LEVELS == 4
16053 pv_mmu_ops.set_pgd = kvm_set_pgd;
16054 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
16057 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
16058 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
16059 index ea69726..604d066 100644
16060 --- a/arch/x86/kernel/ldt.c
16061 +++ b/arch/x86/kernel/ldt.c
16062 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
16067 + load_LDT_nolock(pc);
16068 if (!cpumask_equal(mm_cpumask(current->mm),
16069 cpumask_of(smp_processor_id())))
16070 smp_call_function(flush_ldt, current->mm, 1);
16074 + load_LDT_nolock(pc);
16078 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
16081 for (i = 0; i < old->size; i++)
16082 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
16083 + write_ldt_entry(new->ldt, i, old->ldt + i);
16087 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
16088 retval = copy_ldt(&mm->context, &old_mm->context);
16089 mutex_unlock(&old_mm->context.lock);
16092 + if (tsk == current) {
16093 + mm->context.vdso = 0;
16095 +#ifdef CONFIG_X86_32
16096 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16097 + mm->context.user_cs_base = 0UL;
16098 + mm->context.user_cs_limit = ~0UL;
16100 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16101 + cpus_clear(mm->context.cpu_user_cs_mask);
16112 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
16116 +#ifdef CONFIG_PAX_SEGMEXEC
16117 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
16123 fill_ldt(&ldt, &ldt_info);
16126 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
16127 index a3fa43b..8966f4c 100644
16128 --- a/arch/x86/kernel/machine_kexec_32.c
16129 +++ b/arch/x86/kernel/machine_kexec_32.c
16131 #include <asm/cacheflush.h>
16132 #include <asm/debugreg.h>
16134 -static void set_idt(void *newidt, __u16 limit)
16135 +static void set_idt(struct desc_struct *newidt, __u16 limit)
16137 struct desc_ptr curidt;
16139 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
16143 -static void set_gdt(void *newgdt, __u16 limit)
16144 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
16146 struct desc_ptr curgdt;
16148 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
16151 control_page = page_address(image->control_code_page);
16152 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
16153 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
16155 relocate_kernel_ptr = control_page;
16156 page_list[PA_CONTROL_PAGE] = __pa(control_page);
16157 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
16158 index 3ca42d0..7cff8cc 100644
16159 --- a/arch/x86/kernel/microcode_intel.c
16160 +++ b/arch/x86/kernel/microcode_intel.c
16161 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
16163 static int get_ucode_user(void *to, const void *from, size_t n)
16165 - return copy_from_user(to, from, n);
16166 + return copy_from_user(to, (const void __force_user *)from, n);
16169 static enum ucode_state
16170 request_microcode_user(int cpu, const void __user *buf, size_t size)
16172 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16173 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
16176 static void microcode_fini_cpu(int cpu)
16177 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
16178 index 925179f..267ac7a 100644
16179 --- a/arch/x86/kernel/module.c
16180 +++ b/arch/x86/kernel/module.c
16181 @@ -36,15 +36,60 @@
16182 #define DEBUGP(fmt...)
16185 -void *module_alloc(unsigned long size)
16186 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16188 - if (PAGE_ALIGN(size) > MODULES_LEN)
16189 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
16191 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16192 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16193 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16194 -1, __builtin_return_address(0));
16197 +void *module_alloc(unsigned long size)
16200 +#ifdef CONFIG_PAX_KERNEXEC
16201 + return __module_alloc(size, PAGE_KERNEL);
16203 + return __module_alloc(size, PAGE_KERNEL_EXEC);
16208 +#ifdef CONFIG_PAX_KERNEXEC
16209 +#ifdef CONFIG_X86_32
16210 +void *module_alloc_exec(unsigned long size)
16212 + struct vm_struct *area;
16217 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16218 + return area ? area->addr : NULL;
16220 +EXPORT_SYMBOL(module_alloc_exec);
16222 +void module_free_exec(struct module *mod, void *module_region)
16224 + vunmap(module_region);
16226 +EXPORT_SYMBOL(module_free_exec);
16228 +void module_free_exec(struct module *mod, void *module_region)
16230 + module_free(mod, module_region);
16232 +EXPORT_SYMBOL(module_free_exec);
16234 +void *module_alloc_exec(unsigned long size)
16236 + return __module_alloc(size, PAGE_KERNEL_RX);
16238 +EXPORT_SYMBOL(module_alloc_exec);
16242 #ifdef CONFIG_X86_32
16243 int apply_relocate(Elf32_Shdr *sechdrs,
16244 const char *strtab,
16245 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16247 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16249 - uint32_t *location;
16250 + uint32_t *plocation, location;
16252 DEBUGP("Applying relocate section %u to %u\n", relsec,
16253 sechdrs[relsec].sh_info);
16254 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16255 /* This is where to make the change */
16256 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16257 - + rel[i].r_offset;
16258 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16259 + location = (uint32_t)plocation;
16260 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16261 + plocation = ktla_ktva((void *)plocation);
16262 /* This is the symbol it is referring to. Note that all
16263 undefined symbols have been resolved. */
16264 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16265 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16266 switch (ELF32_R_TYPE(rel[i].r_info)) {
16268 /* We add the value into the location given */
16269 - *location += sym->st_value;
16270 + pax_open_kernel();
16271 + *plocation += sym->st_value;
16272 + pax_close_kernel();
16275 /* Add the value, subtract its postition */
16276 - *location += sym->st_value - (uint32_t)location;
16277 + pax_open_kernel();
16278 + *plocation += sym->st_value - location;
16279 + pax_close_kernel();
16282 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16283 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
16284 case R_X86_64_NONE:
16287 + pax_open_kernel();
16289 + pax_close_kernel();
16292 + pax_open_kernel();
16294 + pax_close_kernel();
16295 if (val != *(u32 *)loc)
16299 + pax_open_kernel();
16301 + pax_close_kernel();
16302 if ((s64)val != *(s32 *)loc)
16305 case R_X86_64_PC32:
16307 + pax_open_kernel();
16309 + pax_close_kernel();
16312 if ((s64)val != *(s32 *)loc)
16314 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
16315 index e88f37b..1353db6 100644
16316 --- a/arch/x86/kernel/nmi.c
16317 +++ b/arch/x86/kernel/nmi.c
16318 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
16319 dotraplinkage notrace __kprobes void
16320 do_nmi(struct pt_regs *regs, long error_code)
16323 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16324 + if (!user_mode(regs)) {
16325 + unsigned long cs = regs->cs & 0xFFFF;
16326 + unsigned long ip = ktva_ktla(regs->ip);
16328 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
16335 inc_irq_stat(__nmi_count);
16336 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
16337 index 676b8c7..870ba04 100644
16338 --- a/arch/x86/kernel/paravirt-spinlocks.c
16339 +++ b/arch/x86/kernel/paravirt-spinlocks.c
16340 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
16341 arch_spin_lock(lock);
16344 -struct pv_lock_ops pv_lock_ops = {
16345 +struct pv_lock_ops pv_lock_ops __read_only = {
16347 .spin_is_locked = __ticket_spin_is_locked,
16348 .spin_is_contended = __ticket_spin_is_contended,
16349 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
16350 index d90272e..6bb013b 100644
16351 --- a/arch/x86/kernel/paravirt.c
16352 +++ b/arch/x86/kernel/paravirt.c
16353 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
16357 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16358 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
16361 void __init default_banner(void)
16363 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
16364 if (opfunc == NULL)
16365 /* If there's no function, patch it with a ud2a (BUG) */
16366 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16367 - else if (opfunc == _paravirt_nop)
16368 + else if (opfunc == (void *)_paravirt_nop)
16369 /* If the operation is a nop, then nop the callsite */
16370 ret = paravirt_patch_nop();
16372 /* identity functions just return their single argument */
16373 - else if (opfunc == _paravirt_ident_32)
16374 + else if (opfunc == (void *)_paravirt_ident_32)
16375 ret = paravirt_patch_ident_32(insnbuf, len);
16376 - else if (opfunc == _paravirt_ident_64)
16377 + else if (opfunc == (void *)_paravirt_ident_64)
16378 ret = paravirt_patch_ident_64(insnbuf, len);
16379 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16380 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
16381 + ret = paravirt_patch_ident_64(insnbuf, len);
16384 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16385 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
16386 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
16387 if (insn_len > len || start == NULL)
16390 - memcpy(insnbuf, start, insn_len);
16391 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16395 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
16399 -struct pv_info pv_info = {
16400 +struct pv_info pv_info __read_only = {
16401 .name = "bare hardware",
16402 .paravirt_enabled = 0,
16404 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
16408 -struct pv_init_ops pv_init_ops = {
16409 +struct pv_init_ops pv_init_ops __read_only = {
16410 .patch = native_patch,
16413 -struct pv_time_ops pv_time_ops = {
16414 +struct pv_time_ops pv_time_ops __read_only = {
16415 .sched_clock = native_sched_clock,
16416 .steal_clock = native_steal_clock,
16419 -struct pv_irq_ops pv_irq_ops = {
16420 +struct pv_irq_ops pv_irq_ops __read_only = {
16421 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16422 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16423 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16424 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
16428 -struct pv_cpu_ops pv_cpu_ops = {
16429 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16430 .cpuid = native_cpuid,
16431 .get_debugreg = native_get_debugreg,
16432 .set_debugreg = native_set_debugreg,
16433 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
16434 .end_context_switch = paravirt_nop,
16437 -struct pv_apic_ops pv_apic_ops = {
16438 +struct pv_apic_ops pv_apic_ops __read_only = {
16439 #ifdef CONFIG_X86_LOCAL_APIC
16440 .startup_ipi_hook = paravirt_nop,
16444 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
16445 +#ifdef CONFIG_X86_32
16446 +#ifdef CONFIG_X86_PAE
16447 +/* 64-bit pagetable entries */
16448 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
16450 /* 32-bit pagetable entries */
16451 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
16454 /* 64-bit pagetable entries */
16455 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16458 -struct pv_mmu_ops pv_mmu_ops = {
16459 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16461 .read_cr2 = native_read_cr2,
16462 .write_cr2 = native_write_cr2,
16463 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
16464 .make_pud = PTE_IDENT,
16466 .set_pgd = native_set_pgd,
16467 + .set_pgd_batched = native_set_pgd_batched,
16469 #endif /* PAGETABLE_LEVELS >= 3 */
16471 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16474 .set_fixmap = native_set_fixmap,
16476 +#ifdef CONFIG_PAX_KERNEXEC
16477 + .pax_open_kernel = native_pax_open_kernel,
16478 + .pax_close_kernel = native_pax_close_kernel,
16483 EXPORT_SYMBOL_GPL(pv_time_ops);
16484 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
16485 index 35ccf75..7a15747 100644
16486 --- a/arch/x86/kernel/pci-iommu_table.c
16487 +++ b/arch/x86/kernel/pci-iommu_table.c
16489 #include <asm/iommu_table.h>
16490 #include <linux/string.h>
16491 #include <linux/kallsyms.h>
16493 +#include <linux/sched.h>
16497 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
16498 index ee5d4fb..426649b 100644
16499 --- a/arch/x86/kernel/process.c
16500 +++ b/arch/x86/kernel/process.c
16501 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
16503 void free_thread_info(struct thread_info *ti)
16505 - free_thread_xstate(ti->task);
16506 free_pages((unsigned long)ti, THREAD_ORDER);
16509 +static struct kmem_cache *task_struct_cachep;
16511 void arch_task_cache_init(void)
16513 - task_xstate_cachep =
16514 - kmem_cache_create("task_xstate", xstate_size,
16515 + /* create a slab on which task_structs can be allocated */
16516 + task_struct_cachep =
16517 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16518 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16520 + task_xstate_cachep =
16521 + kmem_cache_create("task_xstate", xstate_size,
16522 __alignof__(union thread_xstate),
16523 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16524 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16527 +struct task_struct *alloc_task_struct_node(int node)
16529 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16532 +void free_task_struct(struct task_struct *task)
16534 + free_thread_xstate(task);
16535 + kmem_cache_free(task_struct_cachep, task);
16539 @@ -70,7 +87,7 @@ void exit_thread(void)
16540 unsigned long *bp = t->io_bitmap_ptr;
16543 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16544 + struct tss_struct *tss = init_tss + get_cpu();
16546 t->io_bitmap_ptr = NULL;
16547 clear_thread_flag(TIF_IO_BITMAP);
16548 @@ -106,7 +123,7 @@ void show_regs_common(void)
16550 printk(KERN_CONT "\n");
16551 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16552 - current->pid, current->comm, print_tainted(),
16553 + task_pid_nr(current), current->comm, print_tainted(),
16554 init_utsname()->release,
16555 (int)strcspn(init_utsname()->version, " "),
16556 init_utsname()->version);
16557 @@ -120,6 +137,9 @@ void flush_thread(void)
16559 struct task_struct *tsk = current;
16561 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16562 + loadsegment(gs, 0);
16564 flush_ptrace_hw_breakpoint(tsk);
16565 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16567 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
16568 regs.di = (unsigned long) arg;
16570 #ifdef CONFIG_X86_32
16571 - regs.ds = __USER_DS;
16572 - regs.es = __USER_DS;
16573 + regs.ds = __KERNEL_DS;
16574 + regs.es = __KERNEL_DS;
16575 regs.fs = __KERNEL_PERCPU;
16576 - regs.gs = __KERNEL_STACK_CANARY;
16577 + savesegment(gs, regs.gs);
16579 regs.ss = __KERNEL_DS;
16581 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
16585 -void stop_this_cpu(void *dummy)
16586 +__noreturn void stop_this_cpu(void *dummy)
16588 local_irq_disable();
16590 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
16592 early_param("idle", idle_setup);
16594 -unsigned long arch_align_stack(unsigned long sp)
16595 +#ifdef CONFIG_PAX_RANDKSTACK
16596 +void pax_randomize_kstack(struct pt_regs *regs)
16598 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16599 - sp -= get_random_int() % 8192;
16600 - return sp & ~0xf;
16602 + struct thread_struct *thread = ¤t->thread;
16603 + unsigned long time;
16605 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16607 - unsigned long range_end = mm->brk + 0x02000000;
16608 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16610 + if (!randomize_va_space)
16613 + if (v8086_mode(regs))
16618 + /* P4 seems to return a 0 LSB, ignore it */
16619 +#ifdef CONFIG_MPENTIUM4
16622 +#elif defined(CONFIG_X86_64)
16630 + thread->sp0 ^= time;
16631 + load_sp0(init_tss + smp_processor_id(), thread);
16633 +#ifdef CONFIG_X86_64
16634 + percpu_write(kernel_stack, thread->sp0);
16638 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
16639 index 8598296..bfadef0 100644
16640 --- a/arch/x86/kernel/process_32.c
16641 +++ b/arch/x86/kernel/process_32.c
16642 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
16643 unsigned long thread_saved_pc(struct task_struct *tsk)
16645 return ((unsigned long *)tsk->thread.sp)[3];
16646 +//XXX return tsk->thread.eip;
16650 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
16652 unsigned short ss, gs;
16654 - if (user_mode_vm(regs)) {
16655 + if (user_mode(regs)) {
16657 ss = regs->ss & 0xffff;
16658 - gs = get_user_gs(regs);
16660 sp = kernel_stack_pointer(regs);
16661 savesegment(ss, ss);
16662 - savesegment(gs, gs);
16664 + gs = get_user_gs(regs);
16666 show_regs_common();
16668 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16669 struct task_struct *tsk;
16672 - childregs = task_pt_regs(p);
16673 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16674 *childregs = *regs;
16676 childregs->sp = sp;
16678 p->thread.sp = (unsigned long) childregs;
16679 p->thread.sp0 = (unsigned long) (childregs+1);
16680 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16682 p->thread.ip = (unsigned long) ret_from_fork;
16684 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16685 struct thread_struct *prev = &prev_p->thread,
16686 *next = &next_p->thread;
16687 int cpu = smp_processor_id();
16688 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16689 + struct tss_struct *tss = init_tss + cpu;
16692 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16693 @@ -320,6 +321,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16695 lazy_save_gs(prev->gs);
16697 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16698 + __set_fs(task_thread_info(next_p)->addr_limit);
16702 * Load the per-thread Thread-Local Storage descriptor.
16704 @@ -350,6 +355,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16706 arch_end_context_switch(next_p);
16708 + percpu_write(current_task, next_p);
16709 + percpu_write(current_tinfo, &next_p->tinfo);
16712 * Restore %gs if needed (which is common)
16714 @@ -358,8 +366,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16716 switch_fpu_finish(next_p, fpu);
16718 - percpu_write(current_task, next_p);
16723 @@ -389,4 +395,3 @@ unsigned long get_wchan(struct task_struct *p)
16724 } while (count++ < 16);
16728 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
16729 index 6a364a6..b147d11 100644
16730 --- a/arch/x86/kernel/process_64.c
16731 +++ b/arch/x86/kernel/process_64.c
16732 @@ -89,7 +89,7 @@ static void __exit_idle(void)
16733 void exit_idle(void)
16735 /* idle loop has pid 0 */
16736 - if (current->pid)
16737 + if (task_pid_nr(current))
16741 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16742 struct pt_regs *childregs;
16743 struct task_struct *me = current;
16745 - childregs = ((struct pt_regs *)
16746 - (THREAD_SIZE + task_stack_page(p))) - 1;
16747 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16748 *childregs = *regs;
16751 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16752 p->thread.sp = (unsigned long) childregs;
16753 p->thread.sp0 = (unsigned long) (childregs+1);
16754 p->thread.usersp = me->thread.usersp;
16755 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16757 set_tsk_thread_flag(p, TIF_FORK);
16759 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16760 struct thread_struct *prev = &prev_p->thread;
16761 struct thread_struct *next = &next_p->thread;
16762 int cpu = smp_processor_id();
16763 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16764 + struct tss_struct *tss = init_tss + cpu;
16765 unsigned fsindex, gsindex;
16768 @@ -461,10 +461,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16769 prev->usersp = percpu_read(old_rsp);
16770 percpu_write(old_rsp, next->usersp);
16771 percpu_write(current_task, next_p);
16772 + percpu_write(current_tinfo, &next_p->tinfo);
16774 - percpu_write(kernel_stack,
16775 - (unsigned long)task_stack_page(next_p) +
16776 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16777 + percpu_write(kernel_stack, next->sp0);
16780 * Now maybe reload the debug registers and handle I/O bitmaps
16781 @@ -519,12 +518,11 @@ unsigned long get_wchan(struct task_struct *p)
16782 if (!p || p == current || p->state == TASK_RUNNING)
16784 stack = (unsigned long)task_stack_page(p);
16785 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16786 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16788 fp = *(u64 *)(p->thread.sp);
16790 - if (fp < (unsigned long)stack ||
16791 - fp >= (unsigned long)stack+THREAD_SIZE)
16792 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16794 ip = *(u64 *)(fp+8);
16795 if (!in_sched_functions(ip))
16796 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
16797 index 8252879..d3219e0 100644
16798 --- a/arch/x86/kernel/ptrace.c
16799 +++ b/arch/x86/kernel/ptrace.c
16800 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
16801 unsigned long addr, unsigned long data)
16804 - unsigned long __user *datap = (unsigned long __user *)data;
16805 + unsigned long __user *datap = (__force unsigned long __user *)data;
16808 /* read the word at location addr in the USER area. */
16809 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
16810 if ((int) addr < 0)
16812 ret = do_get_thread_area(child, addr,
16813 - (struct user_desc __user *)data);
16814 + (__force struct user_desc __user *) data);
16817 case PTRACE_SET_THREAD_AREA:
16818 if ((int) addr < 0)
16820 ret = do_set_thread_area(child, addr,
16821 - (struct user_desc __user *)data, 0);
16822 + (__force struct user_desc __user *) data, 0);
16826 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
16827 memset(info, 0, sizeof(*info));
16828 info->si_signo = SIGTRAP;
16829 info->si_code = si_code;
16830 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16831 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16834 void user_single_step_siginfo(struct task_struct *tsk,
16835 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
16836 index 42eb330..139955c 100644
16837 --- a/arch/x86/kernel/pvclock.c
16838 +++ b/arch/x86/kernel/pvclock.c
16839 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
16843 -static atomic64_t last_value = ATOMIC64_INIT(0);
16844 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16846 void pvclock_resume(void)
16848 - atomic64_set(&last_value, 0);
16849 + atomic64_set_unchecked(&last_value, 0);
16852 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16853 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16854 * updating at the same time, and one of them could be slightly behind,
16855 * making the assumption that last_value always go forward fail to hold.
16857 - last = atomic64_read(&last_value);
16858 + last = atomic64_read_unchecked(&last_value);
16862 - last = atomic64_cmpxchg(&last_value, last, ret);
16863 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16864 } while (unlikely(last != ret));
16867 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
16868 index 37a458b..e63d183 100644
16869 --- a/arch/x86/kernel/reboot.c
16870 +++ b/arch/x86/kernel/reboot.c
16871 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16872 EXPORT_SYMBOL(pm_power_off);
16874 static const struct desc_ptr no_idt = {};
16875 -static int reboot_mode;
16876 +static unsigned short reboot_mode;
16877 enum reboot_type reboot_type = BOOT_ACPI;
16880 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
16881 extern const unsigned char machine_real_restart_asm[];
16882 extern const u64 machine_real_restart_gdt[3];
16884 -void machine_real_restart(unsigned int type)
16885 +__noreturn void machine_real_restart(unsigned int type)
16888 unsigned long restart_pa;
16889 - void (*restart_lowmem)(unsigned int);
16890 + void (* __noreturn restart_lowmem)(unsigned int);
16893 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16894 + struct desc_struct *gdt;
16897 local_irq_disable();
16899 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16900 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
16901 boot)". This seems like a fairly standard thing that gets set by
16902 REBOOT.COM programs, and the previous reset routine did this
16904 - *((unsigned short *)0x472) = reboot_mode;
16905 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16907 /* Patch the GDT in the low memory trampoline */
16908 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16910 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16911 restart_pa = virt_to_phys(restart_va);
16912 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16913 + restart_lowmem = (void *)restart_pa;
16915 /* GDT[0]: GDT self-pointer */
16917 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
16918 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16920 /* Jump to the identity-mapped low memory code */
16922 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16923 + gdt = get_cpu_gdt_table(smp_processor_id());
16924 + pax_open_kernel();
16925 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16926 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16927 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16928 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16930 +#ifdef CONFIG_PAX_KERNEXEC
16931 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16932 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16933 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16934 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16935 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16936 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16938 + pax_close_kernel();
16941 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16942 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16945 restart_lowmem(type);
16949 #ifdef CONFIG_APM_MODULE
16950 EXPORT_SYMBOL(machine_real_restart);
16951 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
16952 * try to force a triple fault and then cycle between hitting the keyboard
16953 * controller and doing that
16955 -static void native_machine_emergency_restart(void)
16956 +__noreturn static void native_machine_emergency_restart(void)
16960 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
16964 -static void __machine_emergency_restart(int emergency)
16965 +static __noreturn void __machine_emergency_restart(int emergency)
16967 reboot_emergency = emergency;
16968 machine_ops.emergency_restart();
16971 -static void native_machine_restart(char *__unused)
16972 +static __noreturn void native_machine_restart(char *__unused)
16974 printk("machine restart\n");
16976 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
16977 __machine_emergency_restart(0);
16980 -static void native_machine_halt(void)
16981 +static __noreturn void native_machine_halt(void)
16983 /* stop other cpus and apics */
16984 machine_shutdown();
16985 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
16986 stop_this_cpu(NULL);
16989 -static void native_machine_power_off(void)
16990 +__noreturn static void native_machine_power_off(void)
16992 if (pm_power_off) {
16994 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
16996 /* a fallback in case there is no PM info available */
16997 tboot_shutdown(TB_SHUTDOWN_HALT);
17001 struct machine_ops machine_ops = {
17002 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
17003 index 7a6f3b3..bed145d7 100644
17004 --- a/arch/x86/kernel/relocate_kernel_64.S
17005 +++ b/arch/x86/kernel/relocate_kernel_64.S
17007 #include <asm/kexec.h>
17008 #include <asm/processor-flags.h>
17009 #include <asm/pgtable_types.h>
17010 +#include <asm/alternative-asm.h>
17013 * Must be relocatable PIC code callable as a C function
17014 @@ -160,13 +161,14 @@ identity_mapped:
17026 + pax_force_retaddr 0, 1
17030 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
17031 index cf0ef98..e3f780b 100644
17032 --- a/arch/x86/kernel/setup.c
17033 +++ b/arch/x86/kernel/setup.c
17034 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
17036 switch (data->type) {
17037 case SETUP_E820_EXT:
17038 - parse_e820_ext(data);
17039 + parse_e820_ext((struct setup_data __force_kernel *)data);
17043 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
17044 * area (640->1Mb) as ram even though it is not.
17047 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
17048 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
17049 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
17052 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
17054 if (!boot_params.hdr.root_flags)
17055 root_mountflags &= ~MS_RDONLY;
17056 - init_mm.start_code = (unsigned long) _text;
17057 - init_mm.end_code = (unsigned long) _etext;
17058 + init_mm.start_code = ktla_ktva((unsigned long) _text);
17059 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
17060 init_mm.end_data = (unsigned long) _edata;
17061 init_mm.brk = _brk_end;
17063 - code_resource.start = virt_to_phys(_text);
17064 - code_resource.end = virt_to_phys(_etext)-1;
17065 - data_resource.start = virt_to_phys(_etext);
17066 + code_resource.start = virt_to_phys(ktla_ktva(_text));
17067 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
17068 + data_resource.start = virt_to_phys(_sdata);
17069 data_resource.end = virt_to_phys(_edata)-1;
17070 bss_resource.start = virt_to_phys(&__bss_start);
17071 bss_resource.end = virt_to_phys(&__bss_stop)-1;
17072 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
17073 index 71f4727..16dc9f7 100644
17074 --- a/arch/x86/kernel/setup_percpu.c
17075 +++ b/arch/x86/kernel/setup_percpu.c
17076 @@ -21,19 +21,17 @@
17077 #include <asm/cpu.h>
17078 #include <asm/stackprotector.h>
17080 -DEFINE_PER_CPU(int, cpu_number);
17082 +DEFINE_PER_CPU(unsigned int, cpu_number);
17083 EXPORT_PER_CPU_SYMBOL(cpu_number);
17086 -#ifdef CONFIG_X86_64
17087 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
17089 -#define BOOT_PERCPU_OFFSET 0
17092 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
17093 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
17095 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
17096 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
17097 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17099 EXPORT_SYMBOL(__per_cpu_offset);
17100 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
17102 #ifdef CONFIG_X86_32
17103 struct desc_struct gdt;
17104 + unsigned long base = per_cpu_offset(cpu);
17106 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17107 - 0x2 | DESCTYPE_S, 0x8);
17109 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17110 + 0x83 | DESCTYPE_S, 0xC);
17111 write_gdt_entry(get_cpu_gdt_table(cpu),
17112 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17114 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
17115 /* alrighty, percpu areas up and running */
17116 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17117 for_each_possible_cpu(cpu) {
17118 +#ifdef CONFIG_CC_STACKPROTECTOR
17119 +#ifdef CONFIG_X86_32
17120 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
17123 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17124 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17125 per_cpu(cpu_number, cpu) = cpu;
17126 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17128 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17130 +#ifdef CONFIG_CC_STACKPROTECTOR
17131 +#ifdef CONFIG_X86_32
17133 + per_cpu(stack_canary.canary, cpu) = canary;
17137 * Up to this point, the boot CPU has been using .init.data
17138 * area. Reload any changed state for the boot CPU.
17139 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
17140 index 54ddaeb2..22c3bdc 100644
17141 --- a/arch/x86/kernel/signal.c
17142 +++ b/arch/x86/kernel/signal.c
17143 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
17144 * Align the stack pointer according to the i386 ABI,
17145 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17147 - sp = ((sp + 4) & -16ul) - 4;
17148 + sp = ((sp - 12) & -16ul) - 4;
17149 #else /* !CONFIG_X86_32 */
17150 sp = round_down(sp, 16) - 8;
17152 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
17153 * Return an always-bogus address instead so we will die with SIGSEGV.
17155 if (onsigstack && !likely(on_sig_stack(sp)))
17156 - return (void __user *)-1L;
17157 + return (__force void __user *)-1L;
17159 /* save i387 state */
17160 if (used_math() && save_i387_xstate(*fpstate) < 0)
17161 - return (void __user *)-1L;
17162 + return (__force void __user *)-1L;
17164 return (void __user *)sp;
17166 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
17169 if (current->mm->context.vdso)
17170 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17171 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17173 - restorer = &frame->retcode;
17174 + restorer = (void __user *)&frame->retcode;
17175 if (ka->sa.sa_flags & SA_RESTORER)
17176 restorer = ka->sa.sa_restorer;
17178 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
17179 * reasons and because gdb uses it as a signature to notice
17180 * signal handler stack frames.
17182 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17183 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17187 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
17188 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17190 /* Set up to return from userspace. */
17191 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17192 + if (current->mm->context.vdso)
17193 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17195 + restorer = (void __user *)&frame->retcode;
17196 if (ka->sa.sa_flags & SA_RESTORER)
17197 restorer = ka->sa.sa_restorer;
17198 put_user_ex(restorer, &frame->pretcode);
17199 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
17200 * reasons and because gdb uses it as a signature to notice
17201 * signal handler stack frames.
17203 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17204 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17205 } put_user_catch(err);
17208 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
17209 * X86_32: vm86 regs switched out by assembly code before reaching
17210 * here, so testing against kernel CS suffices.
17212 - if (!user_mode(regs))
17213 + if (!user_mode_novm(regs))
17216 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
17217 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
17218 index 9f548cb..caf76f7 100644
17219 --- a/arch/x86/kernel/smpboot.c
17220 +++ b/arch/x86/kernel/smpboot.c
17221 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
17222 set_idle_for_cpu(cpu, c_idle.idle);
17224 per_cpu(current_task, cpu) = c_idle.idle;
17225 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17226 #ifdef CONFIG_X86_32
17227 /* Stack for startup_32 can be just as for start_secondary onwards */
17230 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17231 initial_gs = per_cpu_offset(cpu);
17232 - per_cpu(kernel_stack, cpu) =
17233 - (unsigned long)task_stack_page(c_idle.idle) -
17234 - KERNEL_STACK_OFFSET + THREAD_SIZE;
17235 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17238 + pax_open_kernel();
17239 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17240 + pax_close_kernel();
17242 initial_code = (unsigned long)start_secondary;
17243 stack_start = c_idle.idle->thread.sp;
17245 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
17247 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17249 +#ifdef CONFIG_PAX_PER_CPU_PGD
17250 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17251 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17252 + KERNEL_PGD_PTRS);
17255 err = do_boot_cpu(apicid, cpu);
17257 pr_debug("do_boot_cpu failed %d\n", err);
17258 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
17259 index c346d11..d43b163 100644
17260 --- a/arch/x86/kernel/step.c
17261 +++ b/arch/x86/kernel/step.c
17262 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
17263 struct desc_struct *desc;
17264 unsigned long base;
17269 mutex_lock(&child->mm->context.lock);
17270 - if (unlikely((seg >> 3) >= child->mm->context.size))
17271 + if (unlikely(seg >= child->mm->context.size))
17272 addr = -1L; /* bogus selector, access would fault */
17274 desc = child->mm->context.ldt + seg;
17275 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
17278 mutex_unlock(&child->mm->context.lock);
17280 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17281 + addr = ktla_ktva(addr);
17285 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
17286 unsigned char opcode[15];
17287 unsigned long addr = convert_ip_to_linear(child, regs);
17289 + if (addr == -EINVAL)
17292 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17293 for (i = 0; i < copied; i++) {
17294 switch (opcode[i]) {
17295 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
17296 index 0b0cb5f..db6b9ed 100644
17297 --- a/arch/x86/kernel/sys_i386_32.c
17298 +++ b/arch/x86/kernel/sys_i386_32.c
17299 @@ -24,17 +24,224 @@
17301 #include <asm/syscalls.h>
17304 - * Do a system call from kernel instead of calling sys_execve so we
17305 - * end up with proper pt_regs.
17307 -int kernel_execve(const char *filename,
17308 - const char *const argv[],
17309 - const char *const envp[])
17310 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17313 - asm volatile ("int $0x80"
17315 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17317 + unsigned long pax_task_size = TASK_SIZE;
17319 +#ifdef CONFIG_PAX_SEGMEXEC
17320 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17321 + pax_task_size = SEGMEXEC_TASK_SIZE;
17324 + if (len > pax_task_size || addr > pax_task_size - len)
17331 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17332 + unsigned long len, unsigned long pgoff, unsigned long flags)
17334 + struct mm_struct *mm = current->mm;
17335 + struct vm_area_struct *vma;
17336 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17338 +#ifdef CONFIG_PAX_SEGMEXEC
17339 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17340 + pax_task_size = SEGMEXEC_TASK_SIZE;
17343 + pax_task_size -= PAGE_SIZE;
17345 + if (len > pax_task_size)
17348 + if (flags & MAP_FIXED)
17351 +#ifdef CONFIG_PAX_RANDMMAP
17352 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17356 + addr = PAGE_ALIGN(addr);
17357 + if (pax_task_size - len >= addr) {
17358 + vma = find_vma(mm, addr);
17359 + if (check_heap_stack_gap(vma, addr, len))
17363 + if (len > mm->cached_hole_size) {
17364 + start_addr = addr = mm->free_area_cache;
17366 + start_addr = addr = mm->mmap_base;
17367 + mm->cached_hole_size = 0;
17370 +#ifdef CONFIG_PAX_PAGEEXEC
17371 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17372 + start_addr = 0x00110000UL;
17374 +#ifdef CONFIG_PAX_RANDMMAP
17375 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17376 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17379 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17380 + start_addr = addr = mm->mmap_base;
17382 + addr = start_addr;
17387 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17388 + /* At this point: (!vma || addr < vma->vm_end). */
17389 + if (pax_task_size - len < addr) {
17391 + * Start a new search - just in case we missed
17394 + if (start_addr != mm->mmap_base) {
17395 + start_addr = addr = mm->mmap_base;
17396 + mm->cached_hole_size = 0;
17397 + goto full_search;
17401 + if (check_heap_stack_gap(vma, addr, len))
17403 + if (addr + mm->cached_hole_size < vma->vm_start)
17404 + mm->cached_hole_size = vma->vm_start - addr;
17405 + addr = vma->vm_end;
17406 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17407 + start_addr = addr = mm->mmap_base;
17408 + mm->cached_hole_size = 0;
17409 + goto full_search;
17414 + * Remember the place where we stopped the search:
17416 + mm->free_area_cache = addr + len;
17421 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17422 + const unsigned long len, const unsigned long pgoff,
17423 + const unsigned long flags)
17425 + struct vm_area_struct *vma;
17426 + struct mm_struct *mm = current->mm;
17427 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17429 +#ifdef CONFIG_PAX_SEGMEXEC
17430 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17431 + pax_task_size = SEGMEXEC_TASK_SIZE;
17434 + pax_task_size -= PAGE_SIZE;
17436 + /* requested length too big for entire address space */
17437 + if (len > pax_task_size)
17440 + if (flags & MAP_FIXED)
17443 +#ifdef CONFIG_PAX_PAGEEXEC
17444 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17448 +#ifdef CONFIG_PAX_RANDMMAP
17449 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17452 + /* requesting a specific address */
17454 + addr = PAGE_ALIGN(addr);
17455 + if (pax_task_size - len >= addr) {
17456 + vma = find_vma(mm, addr);
17457 + if (check_heap_stack_gap(vma, addr, len))
17462 + /* check if free_area_cache is useful for us */
17463 + if (len <= mm->cached_hole_size) {
17464 + mm->cached_hole_size = 0;
17465 + mm->free_area_cache = mm->mmap_base;
17468 + /* either no address requested or can't fit in requested address hole */
17469 + addr = mm->free_area_cache;
17471 + /* make sure it can fit in the remaining address space */
17472 + if (addr > len) {
17473 + vma = find_vma(mm, addr-len);
17474 + if (check_heap_stack_gap(vma, addr - len, len))
17475 + /* remember the address as a hint for next time */
17476 + return (mm->free_area_cache = addr-len);
17479 + if (mm->mmap_base < len)
17482 + addr = mm->mmap_base-len;
17486 + * Lookup failure means no vma is above this address,
17487 + * else if new region fits below vma->vm_start,
17488 + * return with success:
17490 + vma = find_vma(mm, addr);
17491 + if (check_heap_stack_gap(vma, addr, len))
17492 + /* remember the address as a hint for next time */
17493 + return (mm->free_area_cache = addr);
17495 + /* remember the largest hole we saw so far */
17496 + if (addr + mm->cached_hole_size < vma->vm_start)
17497 + mm->cached_hole_size = vma->vm_start - addr;
17499 + /* try just below the current vma->vm_start */
17500 + addr = skip_heap_stack_gap(vma, len);
17501 + } while (!IS_ERR_VALUE(addr));
17505 + * A failed mmap() very likely causes application failure,
17506 + * so fall back to the bottom-up function here. This scenario
17507 + * can happen with large stack limits and large mmap()
17511 +#ifdef CONFIG_PAX_SEGMEXEC
17512 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17513 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17517 + mm->mmap_base = TASK_UNMAPPED_BASE;
17519 +#ifdef CONFIG_PAX_RANDMMAP
17520 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17521 + mm->mmap_base += mm->delta_mmap;
17524 + mm->free_area_cache = mm->mmap_base;
17525 + mm->cached_hole_size = ~0UL;
17526 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17528 + * Restore the topdown base:
17530 + mm->mmap_base = base;
17531 + mm->free_area_cache = base;
17532 + mm->cached_hole_size = ~0UL;
17536 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
17537 index 0514890..3dbebce 100644
17538 --- a/arch/x86/kernel/sys_x86_64.c
17539 +++ b/arch/x86/kernel/sys_x86_64.c
17540 @@ -95,8 +95,8 @@ out:
17544 -static void find_start_end(unsigned long flags, unsigned long *begin,
17545 - unsigned long *end)
17546 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17547 + unsigned long *begin, unsigned long *end)
17549 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17550 unsigned long new_begin;
17551 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
17552 *begin = new_begin;
17555 - *begin = TASK_UNMAPPED_BASE;
17556 + *begin = mm->mmap_base;
17560 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
17561 if (flags & MAP_FIXED)
17564 - find_start_end(flags, &begin, &end);
17565 + find_start_end(mm, flags, &begin, &end);
17570 +#ifdef CONFIG_PAX_RANDMMAP
17571 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17575 addr = PAGE_ALIGN(addr);
17576 vma = find_vma(mm, addr);
17577 - if (end - len >= addr &&
17578 - (!vma || addr + len <= vma->vm_start))
17579 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17582 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17583 @@ -172,7 +175,7 @@ full_search:
17587 - if (!vma || addr + len <= vma->vm_start) {
17588 + if (check_heap_stack_gap(vma, addr, len)) {
17590 * Remember the place where we stopped the search:
17592 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17594 struct vm_area_struct *vma;
17595 struct mm_struct *mm = current->mm;
17596 - unsigned long addr = addr0;
17597 + unsigned long base = mm->mmap_base, addr = addr0;
17599 /* requested length too big for entire address space */
17600 if (len > TASK_SIZE)
17601 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17602 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17605 +#ifdef CONFIG_PAX_RANDMMAP
17606 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17609 /* requesting a specific address */
17611 addr = PAGE_ALIGN(addr);
17612 - vma = find_vma(mm, addr);
17613 - if (TASK_SIZE - len >= addr &&
17614 - (!vma || addr + len <= vma->vm_start))
17616 + if (TASK_SIZE - len >= addr) {
17617 + vma = find_vma(mm, addr);
17618 + if (check_heap_stack_gap(vma, addr, len))
17623 /* check if free_area_cache is useful for us */
17624 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17627 vma = find_vma(mm, tmp_addr);
17628 - if (!vma || tmp_addr + len <= vma->vm_start)
17629 + if (check_heap_stack_gap(vma, tmp_addr, len))
17630 /* remember the address as a hint for next time */
17631 return mm->free_area_cache = tmp_addr;
17633 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17634 * return with success:
17636 vma = find_vma(mm, addr);
17637 - if (!vma || addr+len <= vma->vm_start)
17638 + if (check_heap_stack_gap(vma, addr, len))
17639 /* remember the address as a hint for next time */
17640 return mm->free_area_cache = addr;
17642 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17643 mm->cached_hole_size = vma->vm_start - addr;
17645 /* try just below the current vma->vm_start */
17646 - addr = vma->vm_start-len;
17647 - } while (len < vma->vm_start);
17648 + addr = skip_heap_stack_gap(vma, len);
17649 + } while (!IS_ERR_VALUE(addr));
17653 @@ -270,13 +278,21 @@ bottomup:
17654 * can happen with large stack limits and large mmap()
17657 + mm->mmap_base = TASK_UNMAPPED_BASE;
17659 +#ifdef CONFIG_PAX_RANDMMAP
17660 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17661 + mm->mmap_base += mm->delta_mmap;
17664 + mm->free_area_cache = mm->mmap_base;
17665 mm->cached_hole_size = ~0UL;
17666 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17667 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17669 * Restore the topdown base:
17671 - mm->free_area_cache = mm->mmap_base;
17672 + mm->mmap_base = base;
17673 + mm->free_area_cache = base;
17674 mm->cached_hole_size = ~0UL;
17677 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
17678 index 9a0e312..e6f66f2 100644
17679 --- a/arch/x86/kernel/syscall_table_32.S
17680 +++ b/arch/x86/kernel/syscall_table_32.S
17682 +.section .rodata,"a",@progbits
17683 ENTRY(sys_call_table)
17684 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17686 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
17687 index e2410e2..4fe3fbc 100644
17688 --- a/arch/x86/kernel/tboot.c
17689 +++ b/arch/x86/kernel/tboot.c
17690 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
17692 void tboot_shutdown(u32 shutdown_type)
17694 - void (*shutdown)(void);
17695 + void (* __noreturn shutdown)(void);
17697 if (!tboot_enabled())
17699 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
17701 switch_to_tboot_pt();
17703 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17704 + shutdown = (void *)tboot->shutdown_entry;
17707 /* should not reach here */
17708 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
17709 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17712 -static atomic_t ap_wfs_count;
17713 +static atomic_unchecked_t ap_wfs_count;
17715 static int tboot_wait_for_aps(int num_aps)
17717 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
17721 - atomic_inc(&ap_wfs_count);
17722 + atomic_inc_unchecked(&ap_wfs_count);
17723 if (num_online_cpus() == 1)
17724 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17725 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17729 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
17731 tboot_create_trampoline();
17733 - atomic_set(&ap_wfs_count, 0);
17734 + atomic_set_unchecked(&ap_wfs_count, 0);
17735 register_hotcpu_notifier(&tboot_cpu_notifier);
17738 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
17739 index dd5fbf4..b7f2232 100644
17740 --- a/arch/x86/kernel/time.c
17741 +++ b/arch/x86/kernel/time.c
17742 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
17744 unsigned long pc = instruction_pointer(regs);
17746 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17747 + if (!user_mode(regs) && in_lock_functions(pc)) {
17748 #ifdef CONFIG_FRAME_POINTER
17749 - return *(unsigned long *)(regs->bp + sizeof(long));
17750 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17752 unsigned long *sp =
17753 (unsigned long *)kernel_stack_pointer(regs);
17754 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
17755 * or above a saved flags. Eflags has bits 22-31 zero,
17756 * kernel addresses don't.
17759 +#ifdef CONFIG_PAX_KERNEXEC
17760 + return ktla_ktva(sp[0]);
17772 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
17773 index 6bb7b85..dd853e1 100644
17774 --- a/arch/x86/kernel/tls.c
17775 +++ b/arch/x86/kernel/tls.c
17776 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
17777 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17780 +#ifdef CONFIG_PAX_SEGMEXEC
17781 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17785 set_tls_desc(p, idx, &info, 1);
17788 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
17789 index 451c0a7..e57f551 100644
17790 --- a/arch/x86/kernel/trampoline_32.S
17791 +++ b/arch/x86/kernel/trampoline_32.S
17793 #include <asm/segment.h>
17794 #include <asm/page_types.h>
17796 +#ifdef CONFIG_PAX_KERNEXEC
17799 +#define ta(X) ((X) - __PAGE_OFFSET)
17804 .section ".x86_trampoline","a"
17805 @@ -62,7 +68,7 @@ r_base = .
17806 inc %ax # protected mode (PE) bit
17807 lmsw %ax # into protected mode
17808 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17809 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17810 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17812 # These need to be in the same 64K segment as the above;
17813 # hence we don't use the boot_gdt_descr defined in head.S
17814 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
17815 index 09ff517..df19fbff 100644
17816 --- a/arch/x86/kernel/trampoline_64.S
17817 +++ b/arch/x86/kernel/trampoline_64.S
17818 @@ -90,7 +90,7 @@ startup_32:
17819 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17822 - movl $X86_CR4_PAE, %eax
17823 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17824 movl %eax, %cr4 # Enable PAE mode
17826 # Setup trampoline 4 level pagetables
17827 @@ -138,7 +138,7 @@ tidt:
17828 # so the kernel can live anywhere
17831 - .short tgdt_end - tgdt # gdt limit
17832 + .short tgdt_end - tgdt - 1 # gdt limit
17833 .long tgdt - r_base
17835 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17836 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
17837 index 31d9d0f..e244dd9 100644
17838 --- a/arch/x86/kernel/traps.c
17839 +++ b/arch/x86/kernel/traps.c
17840 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17842 /* Do we ignore FPU interrupts ? */
17843 char ignore_fpu_irq;
17846 - * The IDT has to be page-aligned to simplify the Pentium
17847 - * F0 0F bug workaround.
17849 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17852 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17853 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
17856 static void __kprobes
17857 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17858 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17859 long error_code, siginfo_t *info)
17861 struct task_struct *tsk = current;
17863 #ifdef CONFIG_X86_32
17864 - if (regs->flags & X86_VM_MASK) {
17865 + if (v8086_mode(regs)) {
17867 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17868 * On nmi (interrupt 2), do_trap should not be called.
17869 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17873 - if (!user_mode(regs))
17874 + if (!user_mode_novm(regs))
17877 #ifdef CONFIG_X86_32
17878 @@ -148,7 +142,7 @@ trap_signal:
17879 printk_ratelimit()) {
17881 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17882 - tsk->comm, tsk->pid, str,
17883 + tsk->comm, task_pid_nr(tsk), str,
17884 regs->ip, regs->sp, error_code);
17885 print_vma_addr(" in ", regs->ip);
17887 @@ -165,8 +159,20 @@ kernel_trap:
17888 if (!fixup_exception(regs)) {
17889 tsk->thread.error_code = error_code;
17890 tsk->thread.trap_no = trapnr;
17892 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17893 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17894 + str = "PAX: suspicious stack segment fault";
17897 die(str, regs, error_code);
17900 +#ifdef CONFIG_PAX_REFCOUNT
17902 + pax_report_refcount_overflow(regs);
17907 #ifdef CONFIG_X86_32
17908 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
17909 conditional_sti(regs);
17911 #ifdef CONFIG_X86_32
17912 - if (regs->flags & X86_VM_MASK)
17913 + if (v8086_mode(regs))
17918 - if (!user_mode(regs))
17919 + if (!user_mode_novm(regs))
17922 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17923 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17924 + struct mm_struct *mm = tsk->mm;
17925 + unsigned long limit;
17927 + down_write(&mm->mmap_sem);
17928 + limit = mm->context.user_cs_limit;
17929 + if (limit < TASK_SIZE) {
17930 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17931 + up_write(&mm->mmap_sem);
17934 + up_write(&mm->mmap_sem);
17938 tsk->thread.error_code = error_code;
17939 tsk->thread.trap_no = 13;
17941 @@ -295,6 +317,13 @@ gp_in_kernel:
17942 if (notify_die(DIE_GPF, "general protection fault", regs,
17943 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17947 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17948 + die("PAX: suspicious general protection fault", regs, error_code);
17952 die("general protection fault", regs, error_code);
17955 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17956 /* It's safe to allow irq's after DR6 has been saved */
17957 preempt_conditional_sti(regs);
17959 - if (regs->flags & X86_VM_MASK) {
17960 + if (v8086_mode(regs)) {
17961 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17963 preempt_conditional_cli(regs);
17964 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17965 * We already checked v86 mode above, so we can check for kernel mode
17966 * by just checking the CPL of CS.
17968 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17969 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17970 tsk->thread.debugreg6 &= ~DR_STEP;
17971 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17972 regs->flags &= ~X86_EFLAGS_TF;
17973 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
17975 conditional_sti(regs);
17977 - if (!user_mode_vm(regs))
17978 + if (!user_mode(regs))
17980 if (!fixup_exception(regs)) {
17981 task->thread.error_code = error_code;
17982 @@ -569,8 +598,8 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
17983 void __math_state_restore(struct task_struct *tsk)
17985 /* We need a safe address that is cheap to find and that is already
17986 - in L1. We've just brought in "tsk->thread.has_fpu", so use that */
17987 -#define safe_address (tsk->thread.has_fpu)
17989 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
17991 /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
17992 is pending. Clear the x87 state here by setting it to fixed
17993 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
17994 index b9242ba..50c5edd 100644
17995 --- a/arch/x86/kernel/verify_cpu.S
17996 +++ b/arch/x86/kernel/verify_cpu.S
17998 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17999 * arch/x86/kernel/trampoline_64.S: secondary processor verification
18000 * arch/x86/kernel/head_32.S: processor startup
18001 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
18003 * verify_cpu, returns the status of longmode and SSE in register %eax.
18004 * 0: Success 1: Failure
18005 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
18006 index 863f875..4307295 100644
18007 --- a/arch/x86/kernel/vm86_32.c
18008 +++ b/arch/x86/kernel/vm86_32.c
18010 #include <linux/ptrace.h>
18011 #include <linux/audit.h>
18012 #include <linux/stddef.h>
18013 +#include <linux/grsecurity.h>
18015 #include <asm/uaccess.h>
18016 #include <asm/io.h>
18017 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
18021 - tss = &per_cpu(init_tss, get_cpu());
18022 + tss = init_tss + get_cpu();
18023 current->thread.sp0 = current->thread.saved_sp0;
18024 current->thread.sysenter_cs = __KERNEL_CS;
18025 load_sp0(tss, ¤t->thread);
18026 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
18027 struct task_struct *tsk;
18028 int tmp, ret = -EPERM;
18030 +#ifdef CONFIG_GRKERNSEC_VM86
18031 + if (!capable(CAP_SYS_RAWIO)) {
18032 + gr_handle_vm86();
18038 if (tsk->thread.saved_sp0)
18040 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
18042 struct vm86plus_struct __user *v86;
18044 +#ifdef CONFIG_GRKERNSEC_VM86
18045 + if (!capable(CAP_SYS_RAWIO)) {
18046 + gr_handle_vm86();
18054 case VM86_REQUEST_IRQ:
18055 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
18056 tsk->thread.saved_fs = info->regs32->fs;
18057 tsk->thread.saved_gs = get_user_gs(info->regs32);
18059 - tss = &per_cpu(init_tss, get_cpu());
18060 + tss = init_tss + get_cpu();
18061 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
18063 tsk->thread.sysenter_cs = 0;
18064 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
18065 goto cannot_handle;
18066 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
18067 goto cannot_handle;
18068 - intr_ptr = (unsigned long __user *) (i << 2);
18069 + intr_ptr = (__force unsigned long __user *) (i << 2);
18070 if (get_user(segoffs, intr_ptr))
18071 goto cannot_handle;
18072 if ((segoffs >> 16) == BIOSSEG)
18073 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
18074 index 0f703f1..9e15f64 100644
18075 --- a/arch/x86/kernel/vmlinux.lds.S
18076 +++ b/arch/x86/kernel/vmlinux.lds.S
18078 #include <asm/page_types.h>
18079 #include <asm/cache.h>
18080 #include <asm/boot.h>
18081 +#include <asm/segment.h>
18083 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18084 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
18086 +#define __KERNEL_TEXT_OFFSET 0
18089 #undef i386 /* in case the preprocessor is a 32bit one */
18091 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
18094 text PT_LOAD FLAGS(5); /* R_E */
18095 +#ifdef CONFIG_X86_32
18096 + module PT_LOAD FLAGS(5); /* R_E */
18099 + rodata PT_LOAD FLAGS(5); /* R_E */
18101 + rodata PT_LOAD FLAGS(4); /* R__ */
18103 data PT_LOAD FLAGS(6); /* RW_ */
18104 -#ifdef CONFIG_X86_64
18105 + init.begin PT_LOAD FLAGS(6); /* RW_ */
18107 percpu PT_LOAD FLAGS(6); /* RW_ */
18109 + text.init PT_LOAD FLAGS(5); /* R_E */
18110 + text.exit PT_LOAD FLAGS(5); /* R_E */
18111 init PT_LOAD FLAGS(7); /* RWE */
18113 note PT_NOTE FLAGS(0); /* ___ */
18118 #ifdef CONFIG_X86_32
18119 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18120 - phys_startup_32 = startup_32 - LOAD_OFFSET;
18121 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18123 - . = __START_KERNEL;
18124 - phys_startup_64 = startup_64 - LOAD_OFFSET;
18125 + . = __START_KERNEL;
18128 /* Text and read-only data */
18129 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
18131 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18132 /* bootstrapping code */
18133 +#ifdef CONFIG_X86_32
18134 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18136 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18138 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18141 #ifdef CONFIG_X86_32
18142 . = ALIGN(PAGE_SIZE);
18143 @@ -108,13 +128,47 @@ SECTIONS
18147 - /* End of text section */
18151 - NOTES :text :note
18152 + . += __KERNEL_TEXT_OFFSET;
18154 - EXCEPTION_TABLE(16) :text = 0x9090
18155 +#ifdef CONFIG_X86_32
18156 + . = ALIGN(PAGE_SIZE);
18157 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18159 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18160 + MODULES_EXEC_VADDR = .;
18162 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18163 + . = ALIGN(HPAGE_SIZE);
18164 + MODULES_EXEC_END = . - 1;
18170 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18171 + /* End of text section */
18172 + _etext = . - __KERNEL_TEXT_OFFSET;
18175 +#ifdef CONFIG_X86_32
18176 + . = ALIGN(PAGE_SIZE);
18177 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18179 + . = ALIGN(PAGE_SIZE);
18180 + *(.empty_zero_page)
18181 + *(.initial_pg_fixmap)
18182 + *(.initial_pg_pmd)
18183 + *(.initial_page_table)
18184 + *(.swapper_pg_dir)
18188 + . = ALIGN(PAGE_SIZE);
18189 + NOTES :rodata :note
18191 + EXCEPTION_TABLE(16) :rodata
18193 #if defined(CONFIG_DEBUG_RODATA)
18194 /* .text should occupy whole number of pages */
18195 @@ -126,16 +180,20 @@ SECTIONS
18198 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18200 +#ifdef CONFIG_PAX_KERNEXEC
18201 + . = ALIGN(HPAGE_SIZE);
18203 + . = ALIGN(PAGE_SIZE);
18206 /* Start of data section */
18210 INIT_TASK_DATA(THREAD_SIZE)
18212 -#ifdef CONFIG_X86_32
18213 - /* 32 bit has nosave before _edata */
18217 PAGE_ALIGNED_DATA(PAGE_SIZE)
18219 @@ -176,12 +234,19 @@ SECTIONS
18220 #endif /* CONFIG_X86_64 */
18222 /* Init code and data - will be freed after init */
18223 - . = ALIGN(PAGE_SIZE);
18224 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18227 +#ifdef CONFIG_PAX_KERNEXEC
18228 + . = ALIGN(HPAGE_SIZE);
18230 + . = ALIGN(PAGE_SIZE);
18233 __init_begin = .; /* paired with __init_end */
18237 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18240 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18241 * output PHDR, so the next output section - .init.text - should
18242 @@ -190,12 +255,27 @@ SECTIONS
18243 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18246 - INIT_TEXT_SECTION(PAGE_SIZE)
18247 -#ifdef CONFIG_X86_64
18250 + . = ALIGN(PAGE_SIZE);
18252 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18253 + VMLINUX_SYMBOL(_sinittext) = .;
18255 + VMLINUX_SYMBOL(_einittext) = .;
18256 + . = ALIGN(PAGE_SIZE);
18259 - INIT_DATA_SECTION(16)
18261 + * .exit.text is discard at runtime, not link time, to deal with
18262 + * references from .altinstructions and .eh_frame
18264 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18268 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18270 + . = ALIGN(PAGE_SIZE);
18271 + INIT_DATA_SECTION(16) :init
18274 * Code and data for a variety of lowlevel trampolines, to be
18275 @@ -269,19 +349,12 @@ SECTIONS
18280 - * .exit.text is discard at runtime, not link time, to deal with
18281 - * references from .altinstructions and .eh_frame
18283 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18287 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18291 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18292 +#ifndef CONFIG_SMP
18293 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
18296 @@ -300,16 +373,10 @@ SECTIONS
18297 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18300 - . = ALIGN(PAGE_SIZE);
18301 __smp_locks_end = .;
18302 + . = ALIGN(PAGE_SIZE);
18305 -#ifdef CONFIG_X86_64
18306 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18312 . = ALIGN(PAGE_SIZE);
18313 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18314 @@ -325,6 +392,7 @@ SECTIONS
18316 . += 64 * 1024; /* 64k alignment slop space */
18317 *(.brk_reservation) /* areas brk users have reserved */
18318 + . = ALIGN(HPAGE_SIZE);
18322 @@ -351,13 +419,12 @@ SECTIONS
18323 * for the boot processor.
18325 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18326 -INIT_PER_CPU(gdt_page);
18327 INIT_PER_CPU(irq_stack_union);
18330 * Build-time check on the image size:
18332 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18333 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18334 "kernel image bigger than KERNEL_IMAGE_SIZE");
18337 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
18338 index e4d4a22..47ee71f 100644
18339 --- a/arch/x86/kernel/vsyscall_64.c
18340 +++ b/arch/x86/kernel/vsyscall_64.c
18341 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
18342 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
18345 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
18346 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
18348 static int __init vsyscall_setup(char *str)
18351 if (!strcmp("emulate", str))
18352 vsyscall_mode = EMULATE;
18353 - else if (!strcmp("native", str))
18354 - vsyscall_mode = NATIVE;
18355 else if (!strcmp("none", str))
18356 vsyscall_mode = NONE;
18358 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18361 if (seccomp_mode(&tsk->seccomp))
18362 - do_exit(SIGKILL);
18363 + do_group_exit(SIGKILL);
18365 switch (vsyscall_nr) {
18367 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18371 - force_sig(SIGSEGV, current);
18373 + do_group_exit(SIGKILL);
18377 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
18378 extern char __vvar_page;
18379 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
18381 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
18382 - vsyscall_mode == NATIVE
18383 - ? PAGE_KERNEL_VSYSCALL
18384 - : PAGE_KERNEL_VVAR);
18385 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
18386 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
18387 (unsigned long)VSYSCALL_START);
18389 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
18390 index 9796c2f..f686fbf 100644
18391 --- a/arch/x86/kernel/x8664_ksyms_64.c
18392 +++ b/arch/x86/kernel/x8664_ksyms_64.c
18393 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18394 EXPORT_SYMBOL(copy_user_generic_string);
18395 EXPORT_SYMBOL(copy_user_generic_unrolled);
18396 EXPORT_SYMBOL(__copy_user_nocache);
18397 -EXPORT_SYMBOL(_copy_from_user);
18398 -EXPORT_SYMBOL(_copy_to_user);
18400 EXPORT_SYMBOL(copy_page);
18401 EXPORT_SYMBOL(clear_page);
18402 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
18403 index 7110911..e8cdee5 100644
18404 --- a/arch/x86/kernel/xsave.c
18405 +++ b/arch/x86/kernel/xsave.c
18406 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
18407 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18410 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18411 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18412 fx_sw_user->extended_size -
18413 FP_XSTATE_MAGIC2_SIZE));
18415 @@ -266,7 +266,7 @@ fx_only:
18416 * the other extended state.
18418 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18419 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18420 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
18424 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
18426 err = restore_user_xstate(buf);
18428 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18429 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
18431 if (unlikely(err)) {
18433 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
18434 index f1e3be1..588efc8 100644
18435 --- a/arch/x86/kvm/emulate.c
18436 +++ b/arch/x86/kvm/emulate.c
18437 @@ -249,6 +249,7 @@ struct gprefix {
18439 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
18441 + unsigned long _tmp; \
18442 __asm__ __volatile__ ( \
18443 _PRE_EFLAGS("0", "4", "2") \
18444 _op _suffix " %"_x"3,%1; " \
18445 @@ -263,8 +264,6 @@ struct gprefix {
18446 /* Raw emulation: instruction has two explicit operands. */
18447 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
18449 - unsigned long _tmp; \
18451 switch ((ctxt)->dst.bytes) { \
18453 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
18454 @@ -280,7 +279,6 @@ struct gprefix {
18456 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18458 - unsigned long _tmp; \
18459 switch ((ctxt)->dst.bytes) { \
18461 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
18462 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
18463 index 54abb40..a192606 100644
18464 --- a/arch/x86/kvm/lapic.c
18465 +++ b/arch/x86/kvm/lapic.c
18467 #define APIC_BUS_CYCLE_NS 1
18469 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18470 -#define apic_debug(fmt, arg...)
18471 +#define apic_debug(fmt, arg...) do {} while (0)
18473 #define APIC_LVT_NUM 6
18474 /* 14 is the version for Xeon and Pentium 8.4.8*/
18475 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
18476 index f1b36cf..af8a124 100644
18477 --- a/arch/x86/kvm/mmu.c
18478 +++ b/arch/x86/kvm/mmu.c
18479 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18481 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18483 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18484 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18487 * Assume that the pte write on a page table of the same type
18488 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18491 spin_lock(&vcpu->kvm->mmu_lock);
18492 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18493 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18495 kvm_mmu_free_some_pages(vcpu);
18496 ++vcpu->kvm->stat.mmu_pte_write;
18497 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
18498 index 9299410..ade2f9b 100644
18499 --- a/arch/x86/kvm/paging_tmpl.h
18500 +++ b/arch/x86/kvm/paging_tmpl.h
18501 @@ -197,7 +197,7 @@ retry_walk:
18502 if (unlikely(kvm_is_error_hva(host_addr)))
18505 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
18506 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
18507 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
18510 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
18512 kvm_flush_remote_tlbs(vcpu->kvm);
18514 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18515 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18517 spin_unlock(&vcpu->kvm->mmu_lock);
18519 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
18520 index e32243e..a6e6172 100644
18521 --- a/arch/x86/kvm/svm.c
18522 +++ b/arch/x86/kvm/svm.c
18523 @@ -3400,7 +3400,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
18524 int cpu = raw_smp_processor_id();
18526 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18528 + pax_open_kernel();
18529 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18530 + pax_close_kernel();
18535 @@ -3778,6 +3782,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
18539 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18540 + __set_fs(current_thread_info()->addr_limit);
18545 local_irq_disable();
18546 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
18547 index 4ea7678..b3a7084 100644
18548 --- a/arch/x86/kvm/vmx.c
18549 +++ b/arch/x86/kvm/vmx.c
18550 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
18551 struct desc_struct *descs;
18553 descs = (void *)gdt->address;
18555 + pax_open_kernel();
18556 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18557 + pax_close_kernel();
18562 @@ -2633,8 +2637,11 @@ static __init int hardware_setup(void)
18563 if (!cpu_has_vmx_flexpriority())
18564 flexpriority_enabled = 0;
18566 - if (!cpu_has_vmx_tpr_shadow())
18567 - kvm_x86_ops->update_cr8_intercept = NULL;
18568 + if (!cpu_has_vmx_tpr_shadow()) {
18569 + pax_open_kernel();
18570 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18571 + pax_close_kernel();
18574 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18575 kvm_disable_largepages();
18576 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
18577 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18579 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
18580 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
18581 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
18583 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
18584 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
18585 @@ -6169,6 +6176,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18586 "jmp .Lkvm_vmx_return \n\t"
18587 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18588 ".Lkvm_vmx_return: "
18590 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18591 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18592 + ".Lkvm_vmx_return2: "
18595 /* Save guest registers, load host registers, keep flags */
18596 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18598 @@ -6217,6 +6230,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18600 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18601 [wordsize]"i"(sizeof(ulong))
18603 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18604 + ,[cs]"i"(__KERNEL_CS)
18608 , R"ax", R"bx", R"di", R"si"
18609 #ifdef CONFIG_X86_64
18610 @@ -6245,7 +6263,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18614 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18615 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18617 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18618 + loadsegment(fs, __KERNEL_PERCPU);
18621 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18622 + __set_fs(current_thread_info()->addr_limit);
18625 vmx->loaded_vmcs->launched = 1;
18627 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18628 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
18629 index 4c938da..4ddef65 100644
18630 --- a/arch/x86/kvm/x86.c
18631 +++ b/arch/x86/kvm/x86.c
18632 @@ -1345,8 +1345,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
18634 struct kvm *kvm = vcpu->kvm;
18635 int lm = is_long_mode(vcpu);
18636 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18637 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18638 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18639 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18640 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
18641 : kvm->arch.xen_hvm_config.blob_size_32;
18642 u32 page_num = data & ~PAGE_MASK;
18643 @@ -2165,6 +2165,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
18644 if (n < msr_list.nmsrs)
18647 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18649 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18650 num_msrs_to_save * sizeof(u32)))
18652 @@ -2340,15 +2342,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
18653 struct kvm_cpuid2 *cpuid,
18654 struct kvm_cpuid_entry2 __user *entries)
18660 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18663 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18664 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18665 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18667 + for (i = 0; i < cpuid->nent; ++i) {
18668 + struct kvm_cpuid_entry2 cpuid_entry;
18669 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18671 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18673 vcpu->arch.cpuid_nent = cpuid->nent;
18674 kvm_apic_set_version(vcpu);
18675 kvm_x86_ops->cpuid_update(vcpu);
18676 @@ -2363,15 +2370,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
18677 struct kvm_cpuid2 *cpuid,
18678 struct kvm_cpuid_entry2 __user *entries)
18684 if (cpuid->nent < vcpu->arch.cpuid_nent)
18687 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18688 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18689 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18691 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18692 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18693 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18699 @@ -2746,7 +2757,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
18700 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18701 struct kvm_interrupt *irq)
18703 - if (irq->irq < 0 || irq->irq >= 256)
18704 + if (irq->irq >= 256)
18706 if (irqchip_in_kernel(vcpu->kvm))
18708 @@ -5162,7 +5173,7 @@ static void kvm_set_mmio_spte_mask(void)
18709 kvm_mmu_set_mmio_spte_mask(mask);
18712 -int kvm_arch_init(void *opaque)
18713 +int kvm_arch_init(const void *opaque)
18716 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18717 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
18718 index cf4603b..7cdde38 100644
18719 --- a/arch/x86/lguest/boot.c
18720 +++ b/arch/x86/lguest/boot.c
18721 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
18722 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18723 * Launcher to reboot us.
18725 -static void lguest_restart(char *reason)
18726 +static __noreturn void lguest_restart(char *reason)
18728 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
18733 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
18734 index 042f682..c92afb6 100644
18735 --- a/arch/x86/lib/atomic64_32.c
18736 +++ b/arch/x86/lib/atomic64_32.c
18739 long long atomic64_read_cx8(long long, const atomic64_t *v);
18740 EXPORT_SYMBOL(atomic64_read_cx8);
18741 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18742 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18743 long long atomic64_set_cx8(long long, const atomic64_t *v);
18744 EXPORT_SYMBOL(atomic64_set_cx8);
18745 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18746 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18747 long long atomic64_xchg_cx8(long long, unsigned high);
18748 EXPORT_SYMBOL(atomic64_xchg_cx8);
18749 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18750 EXPORT_SYMBOL(atomic64_add_return_cx8);
18751 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18752 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18753 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18754 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18755 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18756 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18757 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18758 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18759 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18760 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18761 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18762 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18763 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18764 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18765 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18766 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18767 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18768 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18769 #ifndef CONFIG_X86_CMPXCHG64
18770 long long atomic64_read_386(long long, const atomic64_t *v);
18771 EXPORT_SYMBOL(atomic64_read_386);
18772 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18773 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18774 long long atomic64_set_386(long long, const atomic64_t *v);
18775 EXPORT_SYMBOL(atomic64_set_386);
18776 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18777 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18778 long long atomic64_xchg_386(long long, unsigned high);
18779 EXPORT_SYMBOL(atomic64_xchg_386);
18780 long long atomic64_add_return_386(long long a, atomic64_t *v);
18781 EXPORT_SYMBOL(atomic64_add_return_386);
18782 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18783 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18784 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18785 EXPORT_SYMBOL(atomic64_sub_return_386);
18786 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18787 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18788 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18789 EXPORT_SYMBOL(atomic64_inc_return_386);
18790 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18791 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18792 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18793 EXPORT_SYMBOL(atomic64_dec_return_386);
18794 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18795 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18796 long long atomic64_add_386(long long a, atomic64_t *v);
18797 EXPORT_SYMBOL(atomic64_add_386);
18798 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18799 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18800 long long atomic64_sub_386(long long a, atomic64_t *v);
18801 EXPORT_SYMBOL(atomic64_sub_386);
18802 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18803 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18804 long long atomic64_inc_386(long long a, atomic64_t *v);
18805 EXPORT_SYMBOL(atomic64_inc_386);
18806 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18807 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18808 long long atomic64_dec_386(long long a, atomic64_t *v);
18809 EXPORT_SYMBOL(atomic64_dec_386);
18810 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18811 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18812 long long atomic64_dec_if_positive_386(atomic64_t *v);
18813 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18814 int atomic64_inc_not_zero_386(atomic64_t *v);
18815 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
18816 index e8e7e0d..56fd1b0 100644
18817 --- a/arch/x86/lib/atomic64_386_32.S
18818 +++ b/arch/x86/lib/atomic64_386_32.S
18819 @@ -48,6 +48,10 @@ BEGIN(read)
18823 +BEGIN(read_unchecked)
18830 @@ -55,6 +59,10 @@ BEGIN(set)
18834 +BEGIN(set_unchecked)
18841 @@ -70,6 +78,20 @@ RET_ENDP
18846 +#ifdef CONFIG_PAX_REFCOUNT
18852 + _ASM_EXTABLE(0b, 0b)
18856 +BEGIN(add_unchecked)
18862 @@ -77,6 +99,24 @@ RET_ENDP
18867 +#ifdef CONFIG_PAX_REFCOUNT
18870 + _ASM_EXTABLE(1234b, 2f)
18876 +#ifdef CONFIG_PAX_REFCOUNT
18881 +BEGIN(add_return_unchecked)
18887 @@ -86,6 +126,20 @@ RET_ENDP
18892 +#ifdef CONFIG_PAX_REFCOUNT
18898 + _ASM_EXTABLE(0b, 0b)
18902 +BEGIN(sub_unchecked)
18908 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18913 +#ifdef CONFIG_PAX_REFCOUNT
18916 + _ASM_EXTABLE(1234b, 2f)
18922 +#ifdef CONFIG_PAX_REFCOUNT
18927 +BEGIN(sub_return_unchecked)
18936 @@ -105,6 +180,20 @@ RET_ENDP
18941 +#ifdef CONFIG_PAX_REFCOUNT
18947 + _ASM_EXTABLE(0b, 0b)
18951 +BEGIN(inc_unchecked)
18957 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18962 +#ifdef CONFIG_PAX_REFCOUNT
18965 + _ASM_EXTABLE(1234b, 2f)
18971 +#ifdef CONFIG_PAX_REFCOUNT
18976 +BEGIN(inc_return_unchecked)
18984 @@ -123,6 +232,20 @@ RET_ENDP
18989 +#ifdef CONFIG_PAX_REFCOUNT
18995 + _ASM_EXTABLE(0b, 0b)
18999 +BEGIN(dec_unchecked)
19005 @@ -132,6 +255,26 @@ BEGIN(dec_return)
19010 +#ifdef CONFIG_PAX_REFCOUNT
19013 + _ASM_EXTABLE(1234b, 2f)
19019 +#ifdef CONFIG_PAX_REFCOUNT
19024 +BEGIN(dec_return_unchecked)
19032 @@ -143,6 +286,13 @@ BEGIN(add_unless)
19037 +#ifdef CONFIG_PAX_REFCOUNT
19040 + _ASM_EXTABLE(1234b, 2f)
19046 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
19051 +#ifdef CONFIG_PAX_REFCOUNT
19054 + _ASM_EXTABLE(1234b, 2f)
19060 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
19065 +#ifdef CONFIG_PAX_REFCOUNT
19068 + _ASM_EXTABLE(1234b, 1f)
19074 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
19075 index 391a083..d658e9f 100644
19076 --- a/arch/x86/lib/atomic64_cx8_32.S
19077 +++ b/arch/x86/lib/atomic64_cx8_32.S
19078 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
19082 + pax_force_retaddr
19085 ENDPROC(atomic64_read_cx8)
19087 +ENTRY(atomic64_read_unchecked_cx8)
19091 + pax_force_retaddr
19094 +ENDPROC(atomic64_read_unchecked_cx8)
19096 ENTRY(atomic64_set_cx8)
19099 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
19103 + pax_force_retaddr
19106 ENDPROC(atomic64_set_cx8)
19108 +ENTRY(atomic64_set_unchecked_cx8)
19112 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
19113 + * are atomic on 586 and newer */
19117 + pax_force_retaddr
19120 +ENDPROC(atomic64_set_unchecked_cx8)
19122 ENTRY(atomic64_xchg_cx8)
19125 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
19129 + pax_force_retaddr
19132 ENDPROC(atomic64_xchg_cx8)
19134 -.macro addsub_return func ins insc
19135 -ENTRY(atomic64_\func\()_return_cx8)
19136 +.macro addsub_return func ins insc unchecked=""
19137 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19141 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
19143 \ins\()l %esi, %ebx
19144 \insc\()l %edi, %ecx
19147 +#ifdef CONFIG_PAX_REFCOUNT
19150 + _ASM_EXTABLE(2b, 3f)
19163 +#ifdef CONFIG_PAX_REFCOUNT
19172 + pax_force_retaddr
19175 -ENDPROC(atomic64_\func\()_return_cx8)
19176 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19179 addsub_return add add adc
19180 addsub_return sub sub sbb
19181 +addsub_return add add adc _unchecked
19182 +addsub_return sub sub sbb _unchecked
19184 -.macro incdec_return func ins insc
19185 -ENTRY(atomic64_\func\()_return_cx8)
19186 +.macro incdec_return func ins insc unchecked
19187 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19191 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
19197 +#ifdef CONFIG_PAX_REFCOUNT
19200 + _ASM_EXTABLE(2b, 3f)
19213 +#ifdef CONFIG_PAX_REFCOUNT
19219 + pax_force_retaddr
19222 -ENDPROC(atomic64_\func\()_return_cx8)
19223 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19226 incdec_return inc add adc
19227 incdec_return dec sub sbb
19228 +incdec_return inc add adc _unchecked
19229 +incdec_return dec sub sbb _unchecked
19231 ENTRY(atomic64_dec_if_positive_cx8)
19233 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19238 +#ifdef CONFIG_PAX_REFCOUNT
19241 + _ASM_EXTABLE(1234b, 2f)
19247 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
19251 + pax_force_retaddr
19254 ENDPROC(atomic64_dec_if_positive_cx8)
19255 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
19260 +#ifdef CONFIG_PAX_REFCOUNT
19263 + _ASM_EXTABLE(1234b, 3f)
19269 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
19270 CFI_ADJUST_CFA_OFFSET -8
19273 + pax_force_retaddr
19277 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19282 +#ifdef CONFIG_PAX_REFCOUNT
19285 + _ASM_EXTABLE(1234b, 3f)
19291 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
19295 + pax_force_retaddr
19299 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
19300 index 78d16a5..fbcf666 100644
19301 --- a/arch/x86/lib/checksum_32.S
19302 +++ b/arch/x86/lib/checksum_32.S
19304 #include <linux/linkage.h>
19305 #include <asm/dwarf2.h>
19306 #include <asm/errno.h>
19308 +#include <asm/segment.h>
19311 * computes a partial checksum, e.g. for TCP/UDP fragments
19313 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
19318 -ENTRY(csum_partial_copy_generic)
19320 +ENTRY(csum_partial_copy_generic_to_user)
19323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19326 + jmp csum_partial_copy_generic
19329 +ENTRY(csum_partial_copy_generic_from_user)
19331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19336 +ENTRY(csum_partial_copy_generic)
19338 CFI_ADJUST_CFA_OFFSET 4
19340 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19342 SRC(1: movw (%esi), %bx )
19344 -DST( movw %bx, (%edi) )
19345 +DST( movw %bx, %es:(%edi) )
19349 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19350 SRC(1: movl (%esi), %ebx )
19351 SRC( movl 4(%esi), %edx )
19353 -DST( movl %ebx, (%edi) )
19354 +DST( movl %ebx, %es:(%edi) )
19356 -DST( movl %edx, 4(%edi) )
19357 +DST( movl %edx, %es:4(%edi) )
19359 SRC( movl 8(%esi), %ebx )
19360 SRC( movl 12(%esi), %edx )
19362 -DST( movl %ebx, 8(%edi) )
19363 +DST( movl %ebx, %es:8(%edi) )
19365 -DST( movl %edx, 12(%edi) )
19366 +DST( movl %edx, %es:12(%edi) )
19368 SRC( movl 16(%esi), %ebx )
19369 SRC( movl 20(%esi), %edx )
19371 -DST( movl %ebx, 16(%edi) )
19372 +DST( movl %ebx, %es:16(%edi) )
19374 -DST( movl %edx, 20(%edi) )
19375 +DST( movl %edx, %es:20(%edi) )
19377 SRC( movl 24(%esi), %ebx )
19378 SRC( movl 28(%esi), %edx )
19380 -DST( movl %ebx, 24(%edi) )
19381 +DST( movl %ebx, %es:24(%edi) )
19383 -DST( movl %edx, 28(%edi) )
19384 +DST( movl %edx, %es:28(%edi) )
19388 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19389 shrl $2, %edx # This clears CF
19390 SRC(3: movl (%esi), %ebx )
19392 -DST( movl %ebx, (%edi) )
19393 +DST( movl %ebx, %es:(%edi) )
19397 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19399 SRC( movw (%esi), %cx )
19401 -DST( movw %cx, (%edi) )
19402 +DST( movw %cx, %es:(%edi) )
19406 SRC(5: movb (%esi), %cl )
19407 -DST( movb %cl, (%edi) )
19408 +DST( movb %cl, %es:(%edi) )
19412 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19415 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19416 - movl $-EFAULT, (%ebx)
19417 + movl $-EFAULT, %ss:(%ebx)
19419 # zero the complete destination - computing the rest
19421 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19424 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19425 - movl $-EFAULT,(%ebx)
19426 + movl $-EFAULT,%ss:(%ebx)
19438 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19439 popl_cfi %ecx # equivalent to addl $4,%esp
19442 -ENDPROC(csum_partial_copy_generic)
19443 +ENDPROC(csum_partial_copy_generic_to_user)
19447 /* Version for PentiumII/PPro */
19449 #define ROUND1(x) \
19451 SRC(movl x(%esi), %ebx ) ; \
19452 addl %ebx, %eax ; \
19453 - DST(movl %ebx, x(%edi) ) ;
19454 + DST(movl %ebx, %es:x(%edi)) ;
19458 SRC(movl x(%esi), %ebx ) ; \
19459 adcl %ebx, %eax ; \
19460 - DST(movl %ebx, x(%edi) ) ;
19461 + DST(movl %ebx, %es:x(%edi)) ;
19465 -ENTRY(csum_partial_copy_generic)
19467 +ENTRY(csum_partial_copy_generic_to_user)
19470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19473 + jmp csum_partial_copy_generic
19476 +ENTRY(csum_partial_copy_generic_from_user)
19478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19483 +ENTRY(csum_partial_copy_generic)
19485 CFI_REL_OFFSET ebx, 0
19487 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19491 - lea 3f(%ebx,%ebx), %ebx
19492 + lea 3f(%ebx,%ebx,2), %ebx
19496 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19498 SRC( movw (%esi), %dx )
19500 -DST( movw %dx, (%edi) )
19501 +DST( movw %dx, %es:(%edi) )
19506 SRC( movb (%esi), %dl )
19507 -DST( movb %dl, (%edi) )
19508 +DST( movb %dl, %es:(%edi) )
19512 .section .fixup, "ax"
19513 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19514 - movl $-EFAULT, (%ebx)
19515 + movl $-EFAULT, %ss:(%ebx)
19516 # zero the complete destination (computing the rest is too much work)
19517 movl ARGBASE+8(%esp),%edi # dst
19518 movl ARGBASE+12(%esp),%ecx # len
19519 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19522 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19523 - movl $-EFAULT, (%ebx)
19524 + movl $-EFAULT, %ss:(%ebx)
19528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19538 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19542 -ENDPROC(csum_partial_copy_generic)
19543 +ENDPROC(csum_partial_copy_generic_to_user)
19547 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
19548 index f2145cf..cea889d 100644
19549 --- a/arch/x86/lib/clear_page_64.S
19550 +++ b/arch/x86/lib/clear_page_64.S
19551 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
19555 + pax_force_retaddr
19558 ENDPROC(clear_page_c)
19559 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
19563 + pax_force_retaddr
19566 ENDPROC(clear_page_c_e)
19567 @@ -43,6 +45,7 @@ ENTRY(clear_page)
19571 + pax_force_retaddr
19575 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
19577 #include <asm/cpufeature.h>
19579 - .section .altinstr_replacement,"ax"
19580 + .section .altinstr_replacement,"a"
19581 1: .byte 0xeb /* jmp <disp8> */
19582 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19583 2: .byte 0xeb /* jmp <disp8> */
19584 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
19585 index 1e572c5..2a162cd 100644
19586 --- a/arch/x86/lib/cmpxchg16b_emu.S
19587 +++ b/arch/x86/lib/cmpxchg16b_emu.S
19588 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
19592 + pax_force_retaddr
19598 + pax_force_retaddr
19602 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
19603 index 01c805b..dccb07f 100644
19604 --- a/arch/x86/lib/copy_page_64.S
19605 +++ b/arch/x86/lib/copy_page_64.S
19606 @@ -9,6 +9,7 @@ copy_page_c:
19610 + pax_force_retaddr
19613 ENDPROC(copy_page_c)
19614 @@ -39,7 +40,7 @@ ENTRY(copy_page)
19615 movq 16 (%rsi), %rdx
19616 movq 24 (%rsi), %r8
19617 movq 32 (%rsi), %r9
19618 - movq 40 (%rsi), %r10
19619 + movq 40 (%rsi), %r13
19620 movq 48 (%rsi), %r11
19621 movq 56 (%rsi), %r12
19623 @@ -50,7 +51,7 @@ ENTRY(copy_page)
19624 movq %rdx, 16 (%rdi)
19625 movq %r8, 24 (%rdi)
19626 movq %r9, 32 (%rdi)
19627 - movq %r10, 40 (%rdi)
19628 + movq %r13, 40 (%rdi)
19629 movq %r11, 48 (%rdi)
19630 movq %r12, 56 (%rdi)
19632 @@ -69,7 +70,7 @@ ENTRY(copy_page)
19633 movq 16 (%rsi), %rdx
19634 movq 24 (%rsi), %r8
19635 movq 32 (%rsi), %r9
19636 - movq 40 (%rsi), %r10
19637 + movq 40 (%rsi), %r13
19638 movq 48 (%rsi), %r11
19639 movq 56 (%rsi), %r12
19641 @@ -78,7 +79,7 @@ ENTRY(copy_page)
19642 movq %rdx, 16 (%rdi)
19643 movq %r8, 24 (%rdi)
19644 movq %r9, 32 (%rdi)
19645 - movq %r10, 40 (%rdi)
19646 + movq %r13, 40 (%rdi)
19647 movq %r11, 48 (%rdi)
19648 movq %r12, 56 (%rdi)
19650 @@ -95,6 +96,7 @@ ENTRY(copy_page)
19653 CFI_ADJUST_CFA_OFFSET -3*8
19654 + pax_force_retaddr
19658 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
19660 #include <asm/cpufeature.h>
19662 - .section .altinstr_replacement,"ax"
19663 + .section .altinstr_replacement,"a"
19664 1: .byte 0xeb /* jmp <disp8> */
19665 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19667 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
19668 index 0248402..821c786 100644
19669 --- a/arch/x86/lib/copy_user_64.S
19670 +++ b/arch/x86/lib/copy_user_64.S
19672 #include <asm/thread_info.h>
19673 #include <asm/cpufeature.h>
19674 #include <asm/alternative-asm.h>
19675 +#include <asm/pgtable.h>
19678 * By placing feature2 after feature1 in altinstructions section, we logically
19680 .byte 0xe9 /* 32bit jump */
19681 .long \orig-1f /* by default jump to orig */
19683 - .section .altinstr_replacement,"ax"
19684 + .section .altinstr_replacement,"a"
19685 2: .byte 0xe9 /* near jump with 32bit immediate */
19686 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
19687 3: .byte 0xe9 /* near jump with 32bit immediate */
19688 @@ -71,47 +72,20 @@
19692 -/* Standard copy_to_user with segment limit checking */
19693 -ENTRY(_copy_to_user)
19695 - GET_THREAD_INFO(%rax)
19699 - cmpq TI_addr_limit(%rax),%rcx
19701 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19702 - copy_user_generic_unrolled,copy_user_generic_string, \
19703 - copy_user_enhanced_fast_string
19705 -ENDPROC(_copy_to_user)
19707 -/* Standard copy_from_user with segment limit checking */
19708 -ENTRY(_copy_from_user)
19710 - GET_THREAD_INFO(%rax)
19714 - cmpq TI_addr_limit(%rax),%rcx
19716 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19717 - copy_user_generic_unrolled,copy_user_generic_string, \
19718 - copy_user_enhanced_fast_string
19720 -ENDPROC(_copy_from_user)
19722 .section .fixup,"ax"
19723 /* must zero dest */
19724 ENTRY(bad_from_user)
19735 + pax_force_retaddr
19738 ENDPROC(bad_from_user)
19739 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
19742 2: movq 1*8(%rsi),%r9
19743 -3: movq 2*8(%rsi),%r10
19744 +3: movq 2*8(%rsi),%rax
19745 4: movq 3*8(%rsi),%r11
19747 6: movq %r9,1*8(%rdi)
19748 -7: movq %r10,2*8(%rdi)
19749 +7: movq %rax,2*8(%rdi)
19750 8: movq %r11,3*8(%rdi)
19751 9: movq 4*8(%rsi),%r8
19752 10: movq 5*8(%rsi),%r9
19753 -11: movq 6*8(%rsi),%r10
19754 +11: movq 6*8(%rsi),%rax
19755 12: movq 7*8(%rsi),%r11
19756 13: movq %r8,4*8(%rdi)
19757 14: movq %r9,5*8(%rdi)
19758 -15: movq %r10,6*8(%rdi)
19759 +15: movq %rax,6*8(%rdi)
19760 16: movq %r11,7*8(%rdi)
19763 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
19767 + pax_force_retaddr
19770 .section .fixup,"ax"
19771 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
19775 + pax_force_retaddr
19778 .section .fixup,"ax"
19779 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
19783 + pax_force_retaddr
19786 .section .fixup,"ax"
19787 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
19788 index cb0c112..e3a6895 100644
19789 --- a/arch/x86/lib/copy_user_nocache_64.S
19790 +++ b/arch/x86/lib/copy_user_nocache_64.S
19793 #include <linux/linkage.h>
19794 #include <asm/dwarf2.h>
19795 +#include <asm/alternative-asm.h>
19797 #define FIX_ALIGNMENT 1
19799 #include <asm/current.h>
19800 #include <asm/asm-offsets.h>
19801 #include <asm/thread_info.h>
19802 +#include <asm/pgtable.h>
19804 .macro ALIGN_DESTINATION
19805 #ifdef FIX_ALIGNMENT
19808 ENTRY(__copy_user_nocache)
19811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19812 + mov $PAX_USER_SHADOW_BASE,%rcx
19820 jb 20f /* less then 8 bytes, go to byte copy loop */
19822 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
19825 2: movq 1*8(%rsi),%r9
19826 -3: movq 2*8(%rsi),%r10
19827 +3: movq 2*8(%rsi),%rax
19828 4: movq 3*8(%rsi),%r11
19829 5: movnti %r8,(%rdi)
19830 6: movnti %r9,1*8(%rdi)
19831 -7: movnti %r10,2*8(%rdi)
19832 +7: movnti %rax,2*8(%rdi)
19833 8: movnti %r11,3*8(%rdi)
19834 9: movq 4*8(%rsi),%r8
19835 10: movq 5*8(%rsi),%r9
19836 -11: movq 6*8(%rsi),%r10
19837 +11: movq 6*8(%rsi),%rax
19838 12: movq 7*8(%rsi),%r11
19839 13: movnti %r8,4*8(%rdi)
19840 14: movnti %r9,5*8(%rdi)
19841 -15: movnti %r10,6*8(%rdi)
19842 +15: movnti %rax,6*8(%rdi)
19843 16: movnti %r11,7*8(%rdi)
19846 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
19850 + pax_force_retaddr
19853 .section .fixup,"ax"
19854 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
19855 index fb903b7..c92b7f7 100644
19856 --- a/arch/x86/lib/csum-copy_64.S
19857 +++ b/arch/x86/lib/csum-copy_64.S
19859 #include <linux/linkage.h>
19860 #include <asm/dwarf2.h>
19861 #include <asm/errno.h>
19862 +#include <asm/alternative-asm.h>
19865 * Checksum copy with exception handling.
19866 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
19869 CFI_ADJUST_CFA_OFFSET -7*8
19870 + pax_force_retaddr 0, 1
19874 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
19875 index 459b58a..9570bc7 100644
19876 --- a/arch/x86/lib/csum-wrappers_64.c
19877 +++ b/arch/x86/lib/csum-wrappers_64.c
19878 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
19882 - isum = csum_partial_copy_generic((__force const void *)src,
19884 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19885 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19886 + src += PAX_USER_SHADOW_BASE;
19889 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
19890 dst, len, isum, errp, NULL);
19891 if (unlikely(*errp))
19893 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
19897 - return csum_partial_copy_generic(src, (void __force *)dst,
19899 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19900 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19901 + dst += PAX_USER_SHADOW_BASE;
19904 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
19905 len, isum, NULL, errp);
19907 EXPORT_SYMBOL(csum_partial_copy_to_user);
19908 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
19909 index 51f1504..ddac4c1 100644
19910 --- a/arch/x86/lib/getuser.S
19911 +++ b/arch/x86/lib/getuser.S
19912 @@ -33,15 +33,38 @@
19913 #include <asm/asm-offsets.h>
19914 #include <asm/thread_info.h>
19915 #include <asm/asm.h>
19916 +#include <asm/segment.h>
19917 +#include <asm/pgtable.h>
19918 +#include <asm/alternative-asm.h>
19920 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19921 +#define __copyuser_seg gs;
19923 +#define __copyuser_seg
19927 ENTRY(__get_user_1)
19930 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19931 GET_THREAD_INFO(%_ASM_DX)
19932 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19934 -1: movzb (%_ASM_AX),%edx
19936 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19937 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19938 + cmp %_ASM_DX,%_ASM_AX
19940 + add %_ASM_DX,%_ASM_AX
19946 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19948 + pax_force_retaddr
19951 ENDPROC(__get_user_1)
19952 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
19953 ENTRY(__get_user_2)
19957 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19959 GET_THREAD_INFO(%_ASM_DX)
19960 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19962 -2: movzwl -1(%_ASM_AX),%edx
19964 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19965 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19966 + cmp %_ASM_DX,%_ASM_AX
19968 + add %_ASM_DX,%_ASM_AX
19974 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19976 + pax_force_retaddr
19979 ENDPROC(__get_user_2)
19980 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
19981 ENTRY(__get_user_4)
19985 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19987 GET_THREAD_INFO(%_ASM_DX)
19988 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19990 -3: mov -3(%_ASM_AX),%edx
19992 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19993 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19994 + cmp %_ASM_DX,%_ASM_AX
19996 + add %_ASM_DX,%_ASM_AX
20002 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
20004 + pax_force_retaddr
20007 ENDPROC(__get_user_4)
20008 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
20009 GET_THREAD_INFO(%_ASM_DX)
20010 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
20013 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20014 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
20015 + cmp %_ASM_DX,%_ASM_AX
20017 + add %_ASM_DX,%_ASM_AX
20021 4: movq -7(%_ASM_AX),%_ASM_DX
20023 + pax_force_retaddr
20026 ENDPROC(__get_user_8)
20027 @@ -91,6 +152,7 @@ bad_get_user:
20030 mov $(-EFAULT),%_ASM_AX
20031 + pax_force_retaddr
20035 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
20036 index 374562e..a75830b 100644
20037 --- a/arch/x86/lib/insn.c
20038 +++ b/arch/x86/lib/insn.c
20040 #include <linux/string.h>
20041 #include <asm/inat.h>
20042 #include <asm/insn.h>
20044 +#include <asm/pgtable_types.h>
20046 +#define ktla_ktva(addr) addr
20049 /* Verify next sizeof(t) bytes can be on the same instruction */
20050 #define validate_next(t, insn, n) \
20052 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
20054 memset(insn, 0, sizeof(*insn));
20055 - insn->kaddr = kaddr;
20056 - insn->next_byte = kaddr;
20057 + insn->kaddr = ktla_ktva(kaddr);
20058 + insn->next_byte = ktla_ktva(kaddr);
20059 insn->x86_64 = x86_64 ? 1 : 0;
20060 insn->opnd_bytes = 4;
20062 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
20063 index 05a95e7..326f2fa 100644
20064 --- a/arch/x86/lib/iomap_copy_64.S
20065 +++ b/arch/x86/lib/iomap_copy_64.S
20068 #include <linux/linkage.h>
20069 #include <asm/dwarf2.h>
20070 +#include <asm/alternative-asm.h>
20073 * override generic version in lib/iomap_copy.c
20074 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
20078 + pax_force_retaddr
20081 ENDPROC(__iowrite32_copy)
20082 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
20083 index efbf2a0..8893637 100644
20084 --- a/arch/x86/lib/memcpy_64.S
20085 +++ b/arch/x86/lib/memcpy_64.S
20090 + pax_force_retaddr
20098 + pax_force_retaddr
20102 @@ -81,13 +83,13 @@ ENTRY(memcpy)
20104 movq 0*8(%rsi), %r8
20105 movq 1*8(%rsi), %r9
20106 - movq 2*8(%rsi), %r10
20107 + movq 2*8(%rsi), %rcx
20108 movq 3*8(%rsi), %r11
20109 leaq 4*8(%rsi), %rsi
20111 movq %r8, 0*8(%rdi)
20112 movq %r9, 1*8(%rdi)
20113 - movq %r10, 2*8(%rdi)
20114 + movq %rcx, 2*8(%rdi)
20115 movq %r11, 3*8(%rdi)
20116 leaq 4*8(%rdi), %rdi
20117 jae .Lcopy_forward_loop
20118 @@ -110,12 +112,12 @@ ENTRY(memcpy)
20120 movq -1*8(%rsi), %r8
20121 movq -2*8(%rsi), %r9
20122 - movq -3*8(%rsi), %r10
20123 + movq -3*8(%rsi), %rcx
20124 movq -4*8(%rsi), %r11
20125 leaq -4*8(%rsi), %rsi
20126 movq %r8, -1*8(%rdi)
20127 movq %r9, -2*8(%rdi)
20128 - movq %r10, -3*8(%rdi)
20129 + movq %rcx, -3*8(%rdi)
20130 movq %r11, -4*8(%rdi)
20131 leaq -4*8(%rdi), %rdi
20132 jae .Lcopy_backward_loop
20133 @@ -135,12 +137,13 @@ ENTRY(memcpy)
20135 movq 0*8(%rsi), %r8
20136 movq 1*8(%rsi), %r9
20137 - movq -2*8(%rsi, %rdx), %r10
20138 + movq -2*8(%rsi, %rdx), %rcx
20139 movq -1*8(%rsi, %rdx), %r11
20140 movq %r8, 0*8(%rdi)
20141 movq %r9, 1*8(%rdi)
20142 - movq %r10, -2*8(%rdi, %rdx)
20143 + movq %rcx, -2*8(%rdi, %rdx)
20144 movq %r11, -1*8(%rdi, %rdx)
20145 + pax_force_retaddr
20149 @@ -153,6 +156,7 @@ ENTRY(memcpy)
20150 movq -1*8(%rsi, %rdx), %r9
20151 movq %r8, 0*8(%rdi)
20152 movq %r9, -1*8(%rdi, %rdx)
20153 + pax_force_retaddr
20157 @@ -166,6 +170,7 @@ ENTRY(memcpy)
20158 movl -4(%rsi, %rdx), %r8d
20160 movl %r8d, -4(%rdi, %rdx)
20161 + pax_force_retaddr
20165 @@ -183,6 +188,7 @@ ENTRY(memcpy)
20169 + pax_force_retaddr
20173 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
20174 index ee16461..c39c199 100644
20175 --- a/arch/x86/lib/memmove_64.S
20176 +++ b/arch/x86/lib/memmove_64.S
20177 @@ -61,13 +61,13 @@ ENTRY(memmove)
20180 movq 0*8(%rsi), %r11
20181 - movq 1*8(%rsi), %r10
20182 + movq 1*8(%rsi), %rcx
20183 movq 2*8(%rsi), %r9
20184 movq 3*8(%rsi), %r8
20185 leaq 4*8(%rsi), %rsi
20187 movq %r11, 0*8(%rdi)
20188 - movq %r10, 1*8(%rdi)
20189 + movq %rcx, 1*8(%rdi)
20190 movq %r9, 2*8(%rdi)
20191 movq %r8, 3*8(%rdi)
20192 leaq 4*8(%rdi), %rdi
20193 @@ -81,10 +81,10 @@ ENTRY(memmove)
20196 movq -8(%rsi, %rdx), %r11
20197 - lea -8(%rdi, %rdx), %r10
20198 + lea -8(%rdi, %rdx), %r9
20201 - movq %r11, (%r10)
20204 .Lmemmove_end_forward:
20206 @@ -95,14 +95,14 @@ ENTRY(memmove)
20212 leaq -8(%rsi, %rdx), %rsi
20213 leaq -8(%rdi, %rdx), %rdi
20218 - movq %r11, (%r10)
20223 @@ -127,13 +127,13 @@ ENTRY(memmove)
20226 movq -1*8(%rsi), %r11
20227 - movq -2*8(%rsi), %r10
20228 + movq -2*8(%rsi), %rcx
20229 movq -3*8(%rsi), %r9
20230 movq -4*8(%rsi), %r8
20231 leaq -4*8(%rsi), %rsi
20233 movq %r11, -1*8(%rdi)
20234 - movq %r10, -2*8(%rdi)
20235 + movq %rcx, -2*8(%rdi)
20236 movq %r9, -3*8(%rdi)
20237 movq %r8, -4*8(%rdi)
20238 leaq -4*8(%rdi), %rdi
20239 @@ -151,11 +151,11 @@ ENTRY(memmove)
20240 * Move data from 16 bytes to 31 bytes.
20242 movq 0*8(%rsi), %r11
20243 - movq 1*8(%rsi), %r10
20244 + movq 1*8(%rsi), %rcx
20245 movq -2*8(%rsi, %rdx), %r9
20246 movq -1*8(%rsi, %rdx), %r8
20247 movq %r11, 0*8(%rdi)
20248 - movq %r10, 1*8(%rdi)
20249 + movq %rcx, 1*8(%rdi)
20250 movq %r9, -2*8(%rdi, %rdx)
20251 movq %r8, -1*8(%rdi, %rdx)
20253 @@ -167,9 +167,9 @@ ENTRY(memmove)
20254 * Move data from 8 bytes to 15 bytes.
20256 movq 0*8(%rsi), %r11
20257 - movq -1*8(%rsi, %rdx), %r10
20258 + movq -1*8(%rsi, %rdx), %r9
20259 movq %r11, 0*8(%rdi)
20260 - movq %r10, -1*8(%rdi, %rdx)
20261 + movq %r9, -1*8(%rdi, %rdx)
20265 @@ -178,9 +178,9 @@ ENTRY(memmove)
20266 * Move data from 4 bytes to 7 bytes.
20269 - movl -4(%rsi, %rdx), %r10d
20270 + movl -4(%rsi, %rdx), %r9d
20272 - movl %r10d, -4(%rdi, %rdx)
20273 + movl %r9d, -4(%rdi, %rdx)
20277 @@ -189,9 +189,9 @@ ENTRY(memmove)
20278 * Move data from 2 bytes to 3 bytes.
20281 - movw -2(%rsi, %rdx), %r10w
20282 + movw -2(%rsi, %rdx), %r9w
20284 - movw %r10w, -2(%rdi, %rdx)
20285 + movw %r9w, -2(%rdi, %rdx)
20289 @@ -202,6 +202,7 @@ ENTRY(memmove)
20293 + pax_force_retaddr
20297 @@ -210,6 +211,7 @@ ENTRY(memmove)
20298 /* Forward moving data. */
20301 + pax_force_retaddr
20303 .Lmemmove_end_forward_efs:
20305 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
20306 index 79bd454..dff325a 100644
20307 --- a/arch/x86/lib/memset_64.S
20308 +++ b/arch/x86/lib/memset_64.S
20313 + pax_force_retaddr
20321 + pax_force_retaddr
20325 @@ -60,13 +62,13 @@
20332 /* expand byte value */
20334 movabs $0x0101010101010101,%rax
20335 mul %rcx /* with rax, clobbers rdx */
20340 @@ -120,7 +122,8 @@ ENTRY(__memset)
20346 + pax_force_retaddr
20350 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
20351 index c9f2d9b..e7fd2c0 100644
20352 --- a/arch/x86/lib/mmx_32.c
20353 +++ b/arch/x86/lib/mmx_32.c
20354 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20358 + unsigned long cr0;
20360 if (unlikely(in_interrupt()))
20361 return __memcpy(to, from, len);
20362 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20363 kernel_fpu_begin();
20365 __asm__ __volatile__ (
20366 - "1: prefetch (%0)\n" /* This set is 28 bytes */
20367 - " prefetch 64(%0)\n"
20368 - " prefetch 128(%0)\n"
20369 - " prefetch 192(%0)\n"
20370 - " prefetch 256(%0)\n"
20371 + "1: prefetch (%1)\n" /* This set is 28 bytes */
20372 + " prefetch 64(%1)\n"
20373 + " prefetch 128(%1)\n"
20374 + " prefetch 192(%1)\n"
20375 + " prefetch 256(%1)\n"
20377 ".section .fixup, \"ax\"\n"
20378 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20381 +#ifdef CONFIG_PAX_KERNEXEC
20382 + " movl %%cr0, %0\n"
20383 + " movl %0, %%eax\n"
20384 + " andl $0xFFFEFFFF, %%eax\n"
20385 + " movl %%eax, %%cr0\n"
20388 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20390 +#ifdef CONFIG_PAX_KERNEXEC
20391 + " movl %0, %%cr0\n"
20396 _ASM_EXTABLE(1b, 3b)
20398 + : "=&r" (cr0) : "r" (from) : "ax");
20400 for ( ; i > 5; i--) {
20401 __asm__ __volatile__ (
20402 - "1: prefetch 320(%0)\n"
20403 - "2: movq (%0), %%mm0\n"
20404 - " movq 8(%0), %%mm1\n"
20405 - " movq 16(%0), %%mm2\n"
20406 - " movq 24(%0), %%mm3\n"
20407 - " movq %%mm0, (%1)\n"
20408 - " movq %%mm1, 8(%1)\n"
20409 - " movq %%mm2, 16(%1)\n"
20410 - " movq %%mm3, 24(%1)\n"
20411 - " movq 32(%0), %%mm0\n"
20412 - " movq 40(%0), %%mm1\n"
20413 - " movq 48(%0), %%mm2\n"
20414 - " movq 56(%0), %%mm3\n"
20415 - " movq %%mm0, 32(%1)\n"
20416 - " movq %%mm1, 40(%1)\n"
20417 - " movq %%mm2, 48(%1)\n"
20418 - " movq %%mm3, 56(%1)\n"
20419 + "1: prefetch 320(%1)\n"
20420 + "2: movq (%1), %%mm0\n"
20421 + " movq 8(%1), %%mm1\n"
20422 + " movq 16(%1), %%mm2\n"
20423 + " movq 24(%1), %%mm3\n"
20424 + " movq %%mm0, (%2)\n"
20425 + " movq %%mm1, 8(%2)\n"
20426 + " movq %%mm2, 16(%2)\n"
20427 + " movq %%mm3, 24(%2)\n"
20428 + " movq 32(%1), %%mm0\n"
20429 + " movq 40(%1), %%mm1\n"
20430 + " movq 48(%1), %%mm2\n"
20431 + " movq 56(%1), %%mm3\n"
20432 + " movq %%mm0, 32(%2)\n"
20433 + " movq %%mm1, 40(%2)\n"
20434 + " movq %%mm2, 48(%2)\n"
20435 + " movq %%mm3, 56(%2)\n"
20436 ".section .fixup, \"ax\"\n"
20437 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20440 +#ifdef CONFIG_PAX_KERNEXEC
20441 + " movl %%cr0, %0\n"
20442 + " movl %0, %%eax\n"
20443 + " andl $0xFFFEFFFF, %%eax\n"
20444 + " movl %%eax, %%cr0\n"
20447 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20449 +#ifdef CONFIG_PAX_KERNEXEC
20450 + " movl %0, %%cr0\n"
20455 _ASM_EXTABLE(1b, 3b)
20456 - : : "r" (from), "r" (to) : "memory");
20457 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20461 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
20462 static void fast_copy_page(void *to, void *from)
20465 + unsigned long cr0;
20467 kernel_fpu_begin();
20469 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
20470 * but that is for later. -AV
20472 __asm__ __volatile__(
20473 - "1: prefetch (%0)\n"
20474 - " prefetch 64(%0)\n"
20475 - " prefetch 128(%0)\n"
20476 - " prefetch 192(%0)\n"
20477 - " prefetch 256(%0)\n"
20478 + "1: prefetch (%1)\n"
20479 + " prefetch 64(%1)\n"
20480 + " prefetch 128(%1)\n"
20481 + " prefetch 192(%1)\n"
20482 + " prefetch 256(%1)\n"
20484 ".section .fixup, \"ax\"\n"
20485 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20488 +#ifdef CONFIG_PAX_KERNEXEC
20489 + " movl %%cr0, %0\n"
20490 + " movl %0, %%eax\n"
20491 + " andl $0xFFFEFFFF, %%eax\n"
20492 + " movl %%eax, %%cr0\n"
20495 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20497 +#ifdef CONFIG_PAX_KERNEXEC
20498 + " movl %0, %%cr0\n"
20503 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20504 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20506 for (i = 0; i < (4096-320)/64; i++) {
20507 __asm__ __volatile__ (
20508 - "1: prefetch 320(%0)\n"
20509 - "2: movq (%0), %%mm0\n"
20510 - " movntq %%mm0, (%1)\n"
20511 - " movq 8(%0), %%mm1\n"
20512 - " movntq %%mm1, 8(%1)\n"
20513 - " movq 16(%0), %%mm2\n"
20514 - " movntq %%mm2, 16(%1)\n"
20515 - " movq 24(%0), %%mm3\n"
20516 - " movntq %%mm3, 24(%1)\n"
20517 - " movq 32(%0), %%mm4\n"
20518 - " movntq %%mm4, 32(%1)\n"
20519 - " movq 40(%0), %%mm5\n"
20520 - " movntq %%mm5, 40(%1)\n"
20521 - " movq 48(%0), %%mm6\n"
20522 - " movntq %%mm6, 48(%1)\n"
20523 - " movq 56(%0), %%mm7\n"
20524 - " movntq %%mm7, 56(%1)\n"
20525 + "1: prefetch 320(%1)\n"
20526 + "2: movq (%1), %%mm0\n"
20527 + " movntq %%mm0, (%2)\n"
20528 + " movq 8(%1), %%mm1\n"
20529 + " movntq %%mm1, 8(%2)\n"
20530 + " movq 16(%1), %%mm2\n"
20531 + " movntq %%mm2, 16(%2)\n"
20532 + " movq 24(%1), %%mm3\n"
20533 + " movntq %%mm3, 24(%2)\n"
20534 + " movq 32(%1), %%mm4\n"
20535 + " movntq %%mm4, 32(%2)\n"
20536 + " movq 40(%1), %%mm5\n"
20537 + " movntq %%mm5, 40(%2)\n"
20538 + " movq 48(%1), %%mm6\n"
20539 + " movntq %%mm6, 48(%2)\n"
20540 + " movq 56(%1), %%mm7\n"
20541 + " movntq %%mm7, 56(%2)\n"
20542 ".section .fixup, \"ax\"\n"
20543 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20546 +#ifdef CONFIG_PAX_KERNEXEC
20547 + " movl %%cr0, %0\n"
20548 + " movl %0, %%eax\n"
20549 + " andl $0xFFFEFFFF, %%eax\n"
20550 + " movl %%eax, %%cr0\n"
20553 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20555 +#ifdef CONFIG_PAX_KERNEXEC
20556 + " movl %0, %%cr0\n"
20561 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20562 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20566 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20567 static void fast_copy_page(void *to, void *from)
20570 + unsigned long cr0;
20572 kernel_fpu_begin();
20574 __asm__ __volatile__ (
20575 - "1: prefetch (%0)\n"
20576 - " prefetch 64(%0)\n"
20577 - " prefetch 128(%0)\n"
20578 - " prefetch 192(%0)\n"
20579 - " prefetch 256(%0)\n"
20580 + "1: prefetch (%1)\n"
20581 + " prefetch 64(%1)\n"
20582 + " prefetch 128(%1)\n"
20583 + " prefetch 192(%1)\n"
20584 + " prefetch 256(%1)\n"
20586 ".section .fixup, \"ax\"\n"
20587 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20590 +#ifdef CONFIG_PAX_KERNEXEC
20591 + " movl %%cr0, %0\n"
20592 + " movl %0, %%eax\n"
20593 + " andl $0xFFFEFFFF, %%eax\n"
20594 + " movl %%eax, %%cr0\n"
20597 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20599 +#ifdef CONFIG_PAX_KERNEXEC
20600 + " movl %0, %%cr0\n"
20605 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20606 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20608 for (i = 0; i < 4096/64; i++) {
20609 __asm__ __volatile__ (
20610 - "1: prefetch 320(%0)\n"
20611 - "2: movq (%0), %%mm0\n"
20612 - " movq 8(%0), %%mm1\n"
20613 - " movq 16(%0), %%mm2\n"
20614 - " movq 24(%0), %%mm3\n"
20615 - " movq %%mm0, (%1)\n"
20616 - " movq %%mm1, 8(%1)\n"
20617 - " movq %%mm2, 16(%1)\n"
20618 - " movq %%mm3, 24(%1)\n"
20619 - " movq 32(%0), %%mm0\n"
20620 - " movq 40(%0), %%mm1\n"
20621 - " movq 48(%0), %%mm2\n"
20622 - " movq 56(%0), %%mm3\n"
20623 - " movq %%mm0, 32(%1)\n"
20624 - " movq %%mm1, 40(%1)\n"
20625 - " movq %%mm2, 48(%1)\n"
20626 - " movq %%mm3, 56(%1)\n"
20627 + "1: prefetch 320(%1)\n"
20628 + "2: movq (%1), %%mm0\n"
20629 + " movq 8(%1), %%mm1\n"
20630 + " movq 16(%1), %%mm2\n"
20631 + " movq 24(%1), %%mm3\n"
20632 + " movq %%mm0, (%2)\n"
20633 + " movq %%mm1, 8(%2)\n"
20634 + " movq %%mm2, 16(%2)\n"
20635 + " movq %%mm3, 24(%2)\n"
20636 + " movq 32(%1), %%mm0\n"
20637 + " movq 40(%1), %%mm1\n"
20638 + " movq 48(%1), %%mm2\n"
20639 + " movq 56(%1), %%mm3\n"
20640 + " movq %%mm0, 32(%2)\n"
20641 + " movq %%mm1, 40(%2)\n"
20642 + " movq %%mm2, 48(%2)\n"
20643 + " movq %%mm3, 56(%2)\n"
20644 ".section .fixup, \"ax\"\n"
20645 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20648 +#ifdef CONFIG_PAX_KERNEXEC
20649 + " movl %%cr0, %0\n"
20650 + " movl %0, %%eax\n"
20651 + " andl $0xFFFEFFFF, %%eax\n"
20652 + " movl %%eax, %%cr0\n"
20655 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20657 +#ifdef CONFIG_PAX_KERNEXEC
20658 + " movl %0, %%cr0\n"
20663 _ASM_EXTABLE(1b, 3b)
20664 - : : "r" (from), "r" (to) : "memory");
20665 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20669 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
20670 index 69fa106..adda88b 100644
20671 --- a/arch/x86/lib/msr-reg.S
20672 +++ b/arch/x86/lib/msr-reg.S
20674 #include <asm/dwarf2.h>
20675 #include <asm/asm.h>
20676 #include <asm/msr.h>
20677 +#include <asm/alternative-asm.h>
20679 #ifdef CONFIG_X86_64
20681 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
20685 - movq %rdi, %r10 /* Save pointer */
20686 + movq %rdi, %r9 /* Save pointer */
20687 xorl %r11d, %r11d /* Return value */
20690 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
20691 movl 28(%rdi), %edi
20694 -2: movl %eax, (%r10)
20695 +2: movl %eax, (%r9)
20696 movl %r11d, %eax /* Return value */
20697 - movl %ecx, 4(%r10)
20698 - movl %edx, 8(%r10)
20699 - movl %ebx, 12(%r10)
20700 - movl %ebp, 20(%r10)
20701 - movl %esi, 24(%r10)
20702 - movl %edi, 28(%r10)
20703 + movl %ecx, 4(%r9)
20704 + movl %edx, 8(%r9)
20705 + movl %ebx, 12(%r9)
20706 + movl %ebp, 20(%r9)
20707 + movl %esi, 24(%r9)
20708 + movl %edi, 28(%r9)
20711 + pax_force_retaddr
20715 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
20716 index 36b0d15..d381858 100644
20717 --- a/arch/x86/lib/putuser.S
20718 +++ b/arch/x86/lib/putuser.S
20720 #include <asm/thread_info.h>
20721 #include <asm/errno.h>
20722 #include <asm/asm.h>
20724 +#include <asm/segment.h>
20725 +#include <asm/pgtable.h>
20726 +#include <asm/alternative-asm.h>
20730 @@ -29,52 +31,119 @@
20731 * as they get called from within inline assembly.
20734 -#define ENTER CFI_STARTPROC ; \
20735 - GET_THREAD_INFO(%_ASM_BX)
20736 -#define EXIT ret ; \
20737 +#define ENTER CFI_STARTPROC
20738 +#define EXIT pax_force_retaddr; ret ; \
20741 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20742 +#define _DEST %_ASM_CX,%_ASM_BX
20744 +#define _DEST %_ASM_CX
20747 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20748 +#define __copyuser_seg gs;
20750 +#define __copyuser_seg
20754 ENTRY(__put_user_1)
20757 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20758 + GET_THREAD_INFO(%_ASM_BX)
20759 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20761 -1: movb %al,(%_ASM_CX)
20763 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20764 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20765 + cmp %_ASM_BX,%_ASM_CX
20773 +1: __copyuser_seg movb %al,(_DEST)
20776 ENDPROC(__put_user_1)
20778 ENTRY(__put_user_2)
20781 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20782 + GET_THREAD_INFO(%_ASM_BX)
20783 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20785 cmp %_ASM_BX,%_ASM_CX
20787 -2: movw %ax,(%_ASM_CX)
20789 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20790 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20791 + cmp %_ASM_BX,%_ASM_CX
20799 +2: __copyuser_seg movw %ax,(_DEST)
20802 ENDPROC(__put_user_2)
20804 ENTRY(__put_user_4)
20807 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20808 + GET_THREAD_INFO(%_ASM_BX)
20809 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20811 cmp %_ASM_BX,%_ASM_CX
20813 -3: movl %eax,(%_ASM_CX)
20815 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20816 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20817 + cmp %_ASM_BX,%_ASM_CX
20825 +3: __copyuser_seg movl %eax,(_DEST)
20828 ENDPROC(__put_user_4)
20830 ENTRY(__put_user_8)
20833 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20834 + GET_THREAD_INFO(%_ASM_BX)
20835 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20837 cmp %_ASM_BX,%_ASM_CX
20839 -4: mov %_ASM_AX,(%_ASM_CX)
20841 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20842 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20843 + cmp %_ASM_BX,%_ASM_CX
20851 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20852 #ifdef CONFIG_X86_32
20853 -5: movl %edx,4(%_ASM_CX)
20854 +5: __copyuser_seg movl %edx,4(_DEST)
20858 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
20859 index 1cad221..de671ee 100644
20860 --- a/arch/x86/lib/rwlock.S
20861 +++ b/arch/x86/lib/rwlock.S
20862 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
20865 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20867 +#ifdef CONFIG_PAX_REFCOUNT
20870 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20873 + _ASM_EXTABLE(1234b, 1234b)
20877 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
20880 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20882 +#ifdef CONFIG_PAX_REFCOUNT
20885 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20888 + _ASM_EXTABLE(1234b, 1234b)
20893 + pax_force_retaddr
20896 END(__write_lock_failed)
20897 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
20900 READ_LOCK_SIZE(inc) (%__lock_ptr)
20902 +#ifdef CONFIG_PAX_REFCOUNT
20905 + READ_LOCK_SIZE(dec) (%__lock_ptr)
20908 + _ASM_EXTABLE(1234b, 1234b)
20912 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
20915 READ_LOCK_SIZE(dec) (%__lock_ptr)
20917 +#ifdef CONFIG_PAX_REFCOUNT
20920 + READ_LOCK_SIZE(inc) (%__lock_ptr)
20923 + _ASM_EXTABLE(1234b, 1234b)
20928 + pax_force_retaddr
20931 END(__read_lock_failed)
20932 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
20933 index 5dff5f0..cadebf4 100644
20934 --- a/arch/x86/lib/rwsem.S
20935 +++ b/arch/x86/lib/rwsem.S
20936 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
20937 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20938 CFI_RESTORE __ASM_REG(dx)
20939 restore_common_regs
20940 + pax_force_retaddr
20943 ENDPROC(call_rwsem_down_read_failed)
20944 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
20946 call rwsem_down_write_failed
20947 restore_common_regs
20948 + pax_force_retaddr
20951 ENDPROC(call_rwsem_down_write_failed)
20952 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
20955 restore_common_regs
20957 +1: pax_force_retaddr
20960 ENDPROC(call_rwsem_wake)
20962 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
20963 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20964 CFI_RESTORE __ASM_REG(dx)
20965 restore_common_regs
20966 + pax_force_retaddr
20969 ENDPROC(call_rwsem_downgrade_wake)
20970 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
20971 index a63efd6..ccecad8 100644
20972 --- a/arch/x86/lib/thunk_64.S
20973 +++ b/arch/x86/lib/thunk_64.S
20975 #include <linux/linkage.h>
20976 #include <asm/dwarf2.h>
20977 #include <asm/calling.h>
20978 +#include <asm/alternative-asm.h>
20980 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
20981 .macro THUNK name, func, put_ret_addr_in_rdi=0
20986 + pax_force_retaddr
20989 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
20990 index e218d5d..35679b4 100644
20991 --- a/arch/x86/lib/usercopy_32.c
20992 +++ b/arch/x86/lib/usercopy_32.c
20993 @@ -43,7 +43,7 @@ do { \
20994 __asm__ __volatile__( \
20998 + "0: "__copyuser_seg"lodsb\n" \
21000 " testb %%al,%%al\n" \
21002 @@ -128,10 +128,12 @@ do { \
21005 __asm__ __volatile__( \
21006 + __COPYUSER_SET_ES \
21007 "0: rep; stosl\n" \
21009 "1: rep; stosb\n" \
21011 + __COPYUSER_RESTORE_ES \
21012 ".section .fixup,\"ax\"\n" \
21013 "3: lea 0(%2,%0,4),%0\n" \
21015 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
21018 __asm__ __volatile__(
21019 + __COPYUSER_SET_ES
21023 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
21027 + __COPYUSER_RESTORE_ES
21028 ".section .fixup,\"ax\"\n"
21029 "2: xorl %%eax,%%eax\n"
21031 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
21033 #ifdef CONFIG_X86_INTEL_USERCOPY
21034 static unsigned long
21035 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
21036 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
21039 __asm__ __volatile__(
21040 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
21042 "3: movl 0(%4), %%eax\n"
21043 "4: movl 4(%4), %%edx\n"
21044 - "5: movl %%eax, 0(%3)\n"
21045 - "6: movl %%edx, 4(%3)\n"
21046 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
21047 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
21048 "7: movl 8(%4), %%eax\n"
21049 "8: movl 12(%4),%%edx\n"
21050 - "9: movl %%eax, 8(%3)\n"
21051 - "10: movl %%edx, 12(%3)\n"
21052 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
21053 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
21054 "11: movl 16(%4), %%eax\n"
21055 "12: movl 20(%4), %%edx\n"
21056 - "13: movl %%eax, 16(%3)\n"
21057 - "14: movl %%edx, 20(%3)\n"
21058 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
21059 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
21060 "15: movl 24(%4), %%eax\n"
21061 "16: movl 28(%4), %%edx\n"
21062 - "17: movl %%eax, 24(%3)\n"
21063 - "18: movl %%edx, 28(%3)\n"
21064 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
21065 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
21066 "19: movl 32(%4), %%eax\n"
21067 "20: movl 36(%4), %%edx\n"
21068 - "21: movl %%eax, 32(%3)\n"
21069 - "22: movl %%edx, 36(%3)\n"
21070 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
21071 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
21072 "23: movl 40(%4), %%eax\n"
21073 "24: movl 44(%4), %%edx\n"
21074 - "25: movl %%eax, 40(%3)\n"
21075 - "26: movl %%edx, 44(%3)\n"
21076 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
21077 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
21078 "27: movl 48(%4), %%eax\n"
21079 "28: movl 52(%4), %%edx\n"
21080 - "29: movl %%eax, 48(%3)\n"
21081 - "30: movl %%edx, 52(%3)\n"
21082 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
21083 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
21084 "31: movl 56(%4), %%eax\n"
21085 "32: movl 60(%4), %%edx\n"
21086 - "33: movl %%eax, 56(%3)\n"
21087 - "34: movl %%edx, 60(%3)\n"
21088 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
21089 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
21093 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
21095 " andl $3, %%eax\n"
21097 + __COPYUSER_SET_ES
21099 "36: movl %%eax, %0\n"
21102 + __COPYUSER_RESTORE_ES
21103 + ".section .fixup,\"ax\"\n"
21104 + "101: lea 0(%%eax,%0,4),%0\n"
21107 + ".section __ex_table,\"a\"\n"
21109 + " .long 1b,100b\n"
21110 + " .long 2b,100b\n"
21111 + " .long 3b,100b\n"
21112 + " .long 4b,100b\n"
21113 + " .long 5b,100b\n"
21114 + " .long 6b,100b\n"
21115 + " .long 7b,100b\n"
21116 + " .long 8b,100b\n"
21117 + " .long 9b,100b\n"
21118 + " .long 10b,100b\n"
21119 + " .long 11b,100b\n"
21120 + " .long 12b,100b\n"
21121 + " .long 13b,100b\n"
21122 + " .long 14b,100b\n"
21123 + " .long 15b,100b\n"
21124 + " .long 16b,100b\n"
21125 + " .long 17b,100b\n"
21126 + " .long 18b,100b\n"
21127 + " .long 19b,100b\n"
21128 + " .long 20b,100b\n"
21129 + " .long 21b,100b\n"
21130 + " .long 22b,100b\n"
21131 + " .long 23b,100b\n"
21132 + " .long 24b,100b\n"
21133 + " .long 25b,100b\n"
21134 + " .long 26b,100b\n"
21135 + " .long 27b,100b\n"
21136 + " .long 28b,100b\n"
21137 + " .long 29b,100b\n"
21138 + " .long 30b,100b\n"
21139 + " .long 31b,100b\n"
21140 + " .long 32b,100b\n"
21141 + " .long 33b,100b\n"
21142 + " .long 34b,100b\n"
21143 + " .long 35b,100b\n"
21144 + " .long 36b,100b\n"
21145 + " .long 37b,100b\n"
21146 + " .long 99b,101b\n"
21148 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
21149 + : "1"(to), "2"(from), "0"(size)
21150 + : "eax", "edx", "memory");
21154 +static unsigned long
21155 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
21158 + __asm__ __volatile__(
21159 + " .align 2,0x90\n"
21160 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
21161 + " cmpl $67, %0\n"
21163 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
21164 + " .align 2,0x90\n"
21165 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
21166 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
21167 + "5: movl %%eax, 0(%3)\n"
21168 + "6: movl %%edx, 4(%3)\n"
21169 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
21170 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
21171 + "9: movl %%eax, 8(%3)\n"
21172 + "10: movl %%edx, 12(%3)\n"
21173 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
21174 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
21175 + "13: movl %%eax, 16(%3)\n"
21176 + "14: movl %%edx, 20(%3)\n"
21177 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
21178 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
21179 + "17: movl %%eax, 24(%3)\n"
21180 + "18: movl %%edx, 28(%3)\n"
21181 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
21182 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
21183 + "21: movl %%eax, 32(%3)\n"
21184 + "22: movl %%edx, 36(%3)\n"
21185 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
21186 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
21187 + "25: movl %%eax, 40(%3)\n"
21188 + "26: movl %%edx, 44(%3)\n"
21189 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
21190 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
21191 + "29: movl %%eax, 48(%3)\n"
21192 + "30: movl %%edx, 52(%3)\n"
21193 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
21194 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
21195 + "33: movl %%eax, 56(%3)\n"
21196 + "34: movl %%edx, 60(%3)\n"
21197 + " addl $-64, %0\n"
21198 + " addl $64, %4\n"
21199 + " addl $64, %3\n"
21200 + " cmpl $63, %0\n"
21202 + "35: movl %0, %%eax\n"
21204 + " andl $3, %%eax\n"
21206 + "99: rep; "__copyuser_seg" movsl\n"
21207 + "36: movl %%eax, %0\n"
21208 + "37: rep; "__copyuser_seg" movsb\n"
21210 ".section .fixup,\"ax\"\n"
21211 "101: lea 0(%%eax,%0,4),%0\n"
21213 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
21215 __asm__ __volatile__(
21217 - "0: movl 32(%4), %%eax\n"
21218 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21221 - "1: movl 64(%4), %%eax\n"
21222 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21224 - "2: movl 0(%4), %%eax\n"
21225 - "21: movl 4(%4), %%edx\n"
21226 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21227 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21228 " movl %%eax, 0(%3)\n"
21229 " movl %%edx, 4(%3)\n"
21230 - "3: movl 8(%4), %%eax\n"
21231 - "31: movl 12(%4),%%edx\n"
21232 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21233 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21234 " movl %%eax, 8(%3)\n"
21235 " movl %%edx, 12(%3)\n"
21236 - "4: movl 16(%4), %%eax\n"
21237 - "41: movl 20(%4), %%edx\n"
21238 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21239 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21240 " movl %%eax, 16(%3)\n"
21241 " movl %%edx, 20(%3)\n"
21242 - "10: movl 24(%4), %%eax\n"
21243 - "51: movl 28(%4), %%edx\n"
21244 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21245 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21246 " movl %%eax, 24(%3)\n"
21247 " movl %%edx, 28(%3)\n"
21248 - "11: movl 32(%4), %%eax\n"
21249 - "61: movl 36(%4), %%edx\n"
21250 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21251 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21252 " movl %%eax, 32(%3)\n"
21253 " movl %%edx, 36(%3)\n"
21254 - "12: movl 40(%4), %%eax\n"
21255 - "71: movl 44(%4), %%edx\n"
21256 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21257 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21258 " movl %%eax, 40(%3)\n"
21259 " movl %%edx, 44(%3)\n"
21260 - "13: movl 48(%4), %%eax\n"
21261 - "81: movl 52(%4), %%edx\n"
21262 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21263 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21264 " movl %%eax, 48(%3)\n"
21265 " movl %%edx, 52(%3)\n"
21266 - "14: movl 56(%4), %%eax\n"
21267 - "91: movl 60(%4), %%edx\n"
21268 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21269 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21270 " movl %%eax, 56(%3)\n"
21271 " movl %%edx, 60(%3)\n"
21273 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
21275 " andl $3, %%eax\n"
21277 - "6: rep; movsl\n"
21278 + "6: rep; "__copyuser_seg" movsl\n"
21280 - "7: rep; movsb\n"
21281 + "7: rep; "__copyuser_seg" movsb\n"
21283 ".section .fixup,\"ax\"\n"
21284 "9: lea 0(%%eax,%0,4),%0\n"
21285 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21287 __asm__ __volatile__(
21289 - "0: movl 32(%4), %%eax\n"
21290 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21293 - "1: movl 64(%4), %%eax\n"
21294 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21296 - "2: movl 0(%4), %%eax\n"
21297 - "21: movl 4(%4), %%edx\n"
21298 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21299 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21300 " movnti %%eax, 0(%3)\n"
21301 " movnti %%edx, 4(%3)\n"
21302 - "3: movl 8(%4), %%eax\n"
21303 - "31: movl 12(%4),%%edx\n"
21304 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21305 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21306 " movnti %%eax, 8(%3)\n"
21307 " movnti %%edx, 12(%3)\n"
21308 - "4: movl 16(%4), %%eax\n"
21309 - "41: movl 20(%4), %%edx\n"
21310 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21311 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21312 " movnti %%eax, 16(%3)\n"
21313 " movnti %%edx, 20(%3)\n"
21314 - "10: movl 24(%4), %%eax\n"
21315 - "51: movl 28(%4), %%edx\n"
21316 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21317 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21318 " movnti %%eax, 24(%3)\n"
21319 " movnti %%edx, 28(%3)\n"
21320 - "11: movl 32(%4), %%eax\n"
21321 - "61: movl 36(%4), %%edx\n"
21322 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21323 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21324 " movnti %%eax, 32(%3)\n"
21325 " movnti %%edx, 36(%3)\n"
21326 - "12: movl 40(%4), %%eax\n"
21327 - "71: movl 44(%4), %%edx\n"
21328 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21329 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21330 " movnti %%eax, 40(%3)\n"
21331 " movnti %%edx, 44(%3)\n"
21332 - "13: movl 48(%4), %%eax\n"
21333 - "81: movl 52(%4), %%edx\n"
21334 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21335 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21336 " movnti %%eax, 48(%3)\n"
21337 " movnti %%edx, 52(%3)\n"
21338 - "14: movl 56(%4), %%eax\n"
21339 - "91: movl 60(%4), %%edx\n"
21340 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21341 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21342 " movnti %%eax, 56(%3)\n"
21343 " movnti %%edx, 60(%3)\n"
21345 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21347 " andl $3, %%eax\n"
21349 - "6: rep; movsl\n"
21350 + "6: rep; "__copyuser_seg" movsl\n"
21352 - "7: rep; movsb\n"
21353 + "7: rep; "__copyuser_seg" movsb\n"
21355 ".section .fixup,\"ax\"\n"
21356 "9: lea 0(%%eax,%0,4),%0\n"
21357 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
21359 __asm__ __volatile__(
21361 - "0: movl 32(%4), %%eax\n"
21362 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21365 - "1: movl 64(%4), %%eax\n"
21366 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21368 - "2: movl 0(%4), %%eax\n"
21369 - "21: movl 4(%4), %%edx\n"
21370 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21371 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21372 " movnti %%eax, 0(%3)\n"
21373 " movnti %%edx, 4(%3)\n"
21374 - "3: movl 8(%4), %%eax\n"
21375 - "31: movl 12(%4),%%edx\n"
21376 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21377 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21378 " movnti %%eax, 8(%3)\n"
21379 " movnti %%edx, 12(%3)\n"
21380 - "4: movl 16(%4), %%eax\n"
21381 - "41: movl 20(%4), %%edx\n"
21382 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21383 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21384 " movnti %%eax, 16(%3)\n"
21385 " movnti %%edx, 20(%3)\n"
21386 - "10: movl 24(%4), %%eax\n"
21387 - "51: movl 28(%4), %%edx\n"
21388 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21389 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21390 " movnti %%eax, 24(%3)\n"
21391 " movnti %%edx, 28(%3)\n"
21392 - "11: movl 32(%4), %%eax\n"
21393 - "61: movl 36(%4), %%edx\n"
21394 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21395 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21396 " movnti %%eax, 32(%3)\n"
21397 " movnti %%edx, 36(%3)\n"
21398 - "12: movl 40(%4), %%eax\n"
21399 - "71: movl 44(%4), %%edx\n"
21400 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21401 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21402 " movnti %%eax, 40(%3)\n"
21403 " movnti %%edx, 44(%3)\n"
21404 - "13: movl 48(%4), %%eax\n"
21405 - "81: movl 52(%4), %%edx\n"
21406 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21407 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21408 " movnti %%eax, 48(%3)\n"
21409 " movnti %%edx, 52(%3)\n"
21410 - "14: movl 56(%4), %%eax\n"
21411 - "91: movl 60(%4), %%edx\n"
21412 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21413 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21414 " movnti %%eax, 56(%3)\n"
21415 " movnti %%edx, 60(%3)\n"
21417 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
21419 " andl $3, %%eax\n"
21421 - "6: rep; movsl\n"
21422 + "6: rep; "__copyuser_seg" movsl\n"
21424 - "7: rep; movsb\n"
21425 + "7: rep; "__copyuser_seg" movsb\n"
21427 ".section .fixup,\"ax\"\n"
21428 "9: lea 0(%%eax,%0,4),%0\n"
21429 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
21431 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
21432 unsigned long size);
21433 -unsigned long __copy_user_intel(void __user *to, const void *from,
21434 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
21435 + unsigned long size);
21436 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
21437 unsigned long size);
21438 unsigned long __copy_user_zeroing_intel_nocache(void *to,
21439 const void __user *from, unsigned long size);
21440 #endif /* CONFIG_X86_INTEL_USERCOPY */
21442 /* Generic arbitrary sized copy. */
21443 -#define __copy_user(to, from, size) \
21444 +#define __copy_user(to, from, size, prefix, set, restore) \
21446 int __d0, __d1, __d2; \
21447 __asm__ __volatile__( \
21455 - "4: rep; movsb\n" \
21456 + "4: rep; "prefix"movsb\n" \
21460 " .align 2,0x90\n" \
21461 - "0: rep; movsl\n" \
21462 + "0: rep; "prefix"movsl\n" \
21464 - "1: rep; movsb\n" \
21465 + "1: rep; "prefix"movsb\n" \
21468 ".section .fixup,\"ax\"\n" \
21469 "5: addl %3,%0\n" \
21471 @@ -682,14 +799,14 @@ do { \
21475 - "4: rep; movsb\n" \
21476 + "4: rep; "__copyuser_seg"movsb\n" \
21480 " .align 2,0x90\n" \
21481 - "0: rep; movsl\n" \
21482 + "0: rep; "__copyuser_seg"movsl\n" \
21484 - "1: rep; movsb\n" \
21485 + "1: rep; "__copyuser_seg"movsb\n" \
21487 ".section .fixup,\"ax\"\n" \
21488 "5: addl %3,%0\n" \
21489 @@ -775,9 +892,9 @@ survive:
21492 if (movsl_is_ok(to, from, n))
21493 - __copy_user(to, from, n);
21494 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
21496 - n = __copy_user_intel(to, from, n);
21497 + n = __generic_copy_to_user_intel(to, from, n);
21500 EXPORT_SYMBOL(__copy_to_user_ll);
21501 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
21504 if (movsl_is_ok(to, from, n))
21505 - __copy_user(to, from, n);
21506 + __copy_user(to, from, n, __copyuser_seg, "", "");
21508 - n = __copy_user_intel((void __user *)to,
21509 - (const void *)from, n);
21510 + n = __generic_copy_from_user_intel(to, from, n);
21513 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
21514 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
21515 if (n > 64 && cpu_has_xmm2)
21516 n = __copy_user_intel_nocache(to, from, n);
21518 - __copy_user(to, from, n);
21519 + __copy_user(to, from, n, __copyuser_seg, "", "");
21521 - __copy_user(to, from, n);
21522 + __copy_user(to, from, n, __copyuser_seg, "", "");
21526 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
21529 - * copy_to_user: - Copy a block of data into user space.
21530 - * @to: Destination address, in user space.
21531 - * @from: Source address, in kernel space.
21532 - * @n: Number of bytes to copy.
21534 - * Context: User context only. This function may sleep.
21536 - * Copy data from kernel space to user space.
21538 - * Returns number of bytes that could not be copied.
21539 - * On success, this will be zero.
21542 -copy_to_user(void __user *to, const void *from, unsigned long n)
21544 - if (access_ok(VERIFY_WRITE, to, n))
21545 - n = __copy_to_user(to, from, n);
21548 -EXPORT_SYMBOL(copy_to_user);
21551 - * copy_from_user: - Copy a block of data from user space.
21552 - * @to: Destination address, in kernel space.
21553 - * @from: Source address, in user space.
21554 - * @n: Number of bytes to copy.
21556 - * Context: User context only. This function may sleep.
21558 - * Copy data from user space to kernel space.
21560 - * Returns number of bytes that could not be copied.
21561 - * On success, this will be zero.
21563 - * If some data could not be copied, this function will pad the copied
21564 - * data to the requested size using zero bytes.
21567 -_copy_from_user(void *to, const void __user *from, unsigned long n)
21569 - if (access_ok(VERIFY_READ, from, n))
21570 - n = __copy_from_user(to, from, n);
21572 - memset(to, 0, n);
21575 -EXPORT_SYMBOL(_copy_from_user);
21577 void copy_from_user_overflow(void)
21579 WARN(1, "Buffer overflow detected!\n");
21581 EXPORT_SYMBOL(copy_from_user_overflow);
21583 +void copy_to_user_overflow(void)
21585 + WARN(1, "Buffer overflow detected!\n");
21587 +EXPORT_SYMBOL(copy_to_user_overflow);
21589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21590 +void __set_fs(mm_segment_t x)
21594 + loadsegment(gs, 0);
21596 + case TASK_SIZE_MAX:
21597 + loadsegment(gs, __USER_DS);
21600 + loadsegment(gs, __KERNEL_DS);
21607 +EXPORT_SYMBOL(__set_fs);
21609 +void set_fs(mm_segment_t x)
21611 + current_thread_info()->addr_limit = x;
21614 +EXPORT_SYMBOL(set_fs);
21616 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
21617 index b7c2849..8633ad8 100644
21618 --- a/arch/x86/lib/usercopy_64.c
21619 +++ b/arch/x86/lib/usercopy_64.c
21620 @@ -42,6 +42,12 @@ long
21621 __strncpy_from_user(char *dst, const char __user *src, long count)
21625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21626 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21627 + src += PAX_USER_SHADOW_BASE;
21630 __do_strncpy_from_user(dst, src, count, res);
21633 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
21638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21639 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
21640 + addr += PAX_USER_SHADOW_BASE;
21643 /* no memory constraint because it doesn't change any memory gcc knows
21646 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
21648 EXPORT_SYMBOL(strlen_user);
21650 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
21651 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
21653 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21654 - return copy_user_generic((__force void *)to, (__force void *)from, len);
21657 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21660 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
21661 + to += PAX_USER_SHADOW_BASE;
21662 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
21663 + from += PAX_USER_SHADOW_BASE;
21666 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
21670 EXPORT_SYMBOL(copy_in_user);
21672 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
21673 * it is not necessary to optimize tail handling.
21676 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
21677 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
21681 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
21682 index d0474ad..36e9257 100644
21683 --- a/arch/x86/mm/extable.c
21684 +++ b/arch/x86/mm/extable.c
21685 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
21686 const struct exception_table_entry *fixup;
21688 #ifdef CONFIG_PNPBIOS
21689 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21690 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21691 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21692 extern u32 pnp_bios_is_utter_crap;
21693 pnp_bios_is_utter_crap = 1;
21694 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
21695 index 5db0490..2ddce45 100644
21696 --- a/arch/x86/mm/fault.c
21697 +++ b/arch/x86/mm/fault.c
21698 @@ -13,11 +13,18 @@
21699 #include <linux/perf_event.h> /* perf_sw_event */
21700 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21701 #include <linux/prefetch.h> /* prefetchw */
21702 +#include <linux/unistd.h>
21703 +#include <linux/compiler.h>
21705 #include <asm/traps.h> /* dotraplinkage, ... */
21706 #include <asm/pgalloc.h> /* pgd_*(), ... */
21707 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21708 #include <asm/fixmap.h> /* VSYSCALL_START */
21709 +#include <asm/tlbflush.h>
21711 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21712 +#include <asm/stacktrace.h>
21716 * Page fault error code bits:
21717 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
21720 /* kprobe_running() needs smp_processor_id() */
21721 - if (kprobes_built_in() && !user_mode_vm(regs)) {
21722 + if (kprobes_built_in() && !user_mode(regs)) {
21724 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21726 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
21727 return !instr_lo || (instr_lo>>1) == 1;
21729 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21730 - if (probe_kernel_address(instr, opcode))
21731 + if (user_mode(regs)) {
21732 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21734 + } else if (probe_kernel_address(instr, opcode))
21737 *prefetch = (instr_lo == 0xF) &&
21738 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
21739 while (instr < max_instr) {
21740 unsigned char opcode;
21742 - if (probe_kernel_address(instr, opcode))
21743 + if (user_mode(regs)) {
21744 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21746 + } else if (probe_kernel_address(instr, opcode))
21750 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
21751 force_sig_info(si_signo, &info, tsk);
21754 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21755 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
21758 +#ifdef CONFIG_PAX_EMUTRAMP
21759 +static int pax_handle_fetch_fault(struct pt_regs *regs);
21762 +#ifdef CONFIG_PAX_PAGEEXEC
21763 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21769 + pgd = pgd_offset(mm, address);
21770 + if (!pgd_present(*pgd))
21772 + pud = pud_offset(pgd, address);
21773 + if (!pud_present(*pud))
21775 + pmd = pmd_offset(pud, address);
21776 + if (!pmd_present(*pmd))
21782 DEFINE_SPINLOCK(pgd_lock);
21783 LIST_HEAD(pgd_list);
21785 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
21786 for (address = VMALLOC_START & PMD_MASK;
21787 address >= TASK_SIZE && address < FIXADDR_TOP;
21788 address += PMD_SIZE) {
21790 +#ifdef CONFIG_PAX_PER_CPU_PGD
21791 + unsigned long cpu;
21796 spin_lock(&pgd_lock);
21798 +#ifdef CONFIG_PAX_PER_CPU_PGD
21799 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
21800 + pgd_t *pgd = get_cpu_pgd(cpu);
21803 list_for_each_entry(page, &pgd_list, lru) {
21804 + pgd_t *pgd = page_address(page);
21805 spinlock_t *pgt_lock;
21808 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
21809 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21811 spin_lock(pgt_lock);
21812 - ret = vmalloc_sync_one(page_address(page), address);
21815 + ret = vmalloc_sync_one(pgd, address);
21817 +#ifndef CONFIG_PAX_PER_CPU_PGD
21818 spin_unlock(pgt_lock);
21823 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21824 * an interrupt in the middle of a task switch..
21826 pgd_paddr = read_cr3();
21828 +#ifdef CONFIG_PAX_PER_CPU_PGD
21829 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21832 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21835 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21836 * happen within a race in page table update. In the later
21840 +#ifdef CONFIG_PAX_PER_CPU_PGD
21841 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21842 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21844 pgd = pgd_offset(current->active_mm, address);
21847 pgd_ref = pgd_offset_k(address);
21848 if (pgd_none(*pgd_ref))
21850 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
21851 static int is_errata100(struct pt_regs *regs, unsigned long address)
21853 #ifdef CONFIG_X86_64
21854 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21855 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21859 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
21862 static const char nx_warning[] = KERN_CRIT
21863 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21864 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21867 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21868 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21869 if (!oops_may_print())
21872 - if (error_code & PF_INSTR) {
21873 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21874 unsigned int level;
21876 pte_t *pte = lookup_address(address, &level);
21878 if (pte && pte_present(*pte) && !pte_exec(*pte))
21879 - printk(nx_warning, current_uid());
21880 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21883 +#ifdef CONFIG_PAX_KERNEXEC
21884 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21885 + if (current->signal->curr_ip)
21886 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21887 + ¤t->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21889 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21890 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21894 printk(KERN_ALERT "BUG: unable to handle kernel ");
21895 if (address < PAGE_SIZE)
21896 printk(KERN_CONT "NULL pointer dereference");
21897 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
21901 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21902 + if (pax_is_fetch_fault(regs, error_code, address)) {
21904 +#ifdef CONFIG_PAX_EMUTRAMP
21905 + switch (pax_handle_fetch_fault(regs)) {
21911 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21912 + do_group_exit(SIGKILL);
21916 if (unlikely(show_unhandled_signals))
21917 show_signal_msg(regs, error_code, address, tsk);
21919 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
21920 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
21922 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
21923 - tsk->comm, tsk->pid, address);
21924 + tsk->comm, task_pid_nr(tsk), address);
21925 code = BUS_MCEERR_AR;
21928 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
21932 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21933 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21938 + unsigned char pte_mask;
21940 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21941 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21944 + /* PaX: it's our fault, let's handle it if we can */
21946 + /* PaX: take a look at read faults before acquiring any locks */
21947 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21948 + /* instruction fetch attempt from a protected page in user mode */
21949 + up_read(&mm->mmap_sem);
21951 +#ifdef CONFIG_PAX_EMUTRAMP
21952 + switch (pax_handle_fetch_fault(regs)) {
21958 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21959 + do_group_exit(SIGKILL);
21962 + pmd = pax_get_pmd(mm, address);
21963 + if (unlikely(!pmd))
21966 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21967 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21968 + pte_unmap_unlock(pte, ptl);
21972 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21973 + /* write attempt to a protected page in user mode */
21974 + pte_unmap_unlock(pte, ptl);
21979 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21981 + if (likely(address > get_limit(regs->cs)))
21984 + set_pte(pte, pte_mkread(*pte));
21985 + __flush_tlb_one(address);
21986 + pte_unmap_unlock(pte, ptl);
21987 + up_read(&mm->mmap_sem);
21991 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21994 + * PaX: fill DTLB with user rights and retry
21996 + __asm__ __volatile__ (
21998 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
22000 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
22001 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
22002 + * page fault when examined during a TLB load attempt. this is true not only
22003 + * for PTEs holding a non-present entry but also present entries that will
22004 + * raise a page fault (such as those set up by PaX, or the copy-on-write
22005 + * mechanism). in effect it means that we do *not* need to flush the TLBs
22006 + * for our target pages since their PTEs are simply not in the TLBs at all.
22008 + * the best thing in omitting it is that we gain around 15-20% speed in the
22009 + * fast path of the page fault handler and can get rid of tracing since we
22010 + * can no longer flush unintended entries.
22014 + __copyuser_seg"testb $0,(%0)\n"
22017 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
22018 + : "memory", "cc");
22019 + pte_unmap_unlock(pte, ptl);
22020 + up_read(&mm->mmap_sem);
22026 * Handle a spurious fault caused by a stale TLB entry.
22028 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
22030 access_error(unsigned long error_code, struct vm_area_struct *vma)
22032 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
22035 if (error_code & PF_WRITE) {
22036 /* write, present and write, not present: */
22037 if (unlikely(!(vma->vm_flags & VM_WRITE)))
22038 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
22040 struct vm_area_struct *vma;
22041 struct task_struct *tsk;
22042 - unsigned long address;
22043 struct mm_struct *mm;
22045 int write = error_code & PF_WRITE;
22046 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
22047 (write ? FAULT_FLAG_WRITE : 0);
22052 /* Get the faulting address: */
22053 - address = read_cr2();
22054 + unsigned long address = read_cr2();
22056 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22057 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
22058 + if (!search_exception_tables(regs->ip)) {
22059 + bad_area_nosemaphore(regs, error_code, address);
22062 + if (address < PAX_USER_SHADOW_BASE) {
22063 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
22064 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
22065 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
22067 + address -= PAX_USER_SHADOW_BASE;
22075 * Detect and handle instructions that would cause a page fault for
22076 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
22077 * User-mode registers count as a user access even for any
22078 * potential system fault or CPU buglet:
22080 - if (user_mode_vm(regs)) {
22081 + if (user_mode(regs)) {
22082 local_irq_enable();
22083 error_code |= PF_USER;
22085 @@ -1122,6 +1328,11 @@ retry:
22089 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22090 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
22094 vma = find_vma(mm, address);
22095 if (unlikely(!vma)) {
22096 bad_area(regs, error_code, address);
22097 @@ -1133,18 +1344,24 @@ retry:
22098 bad_area(regs, error_code, address);
22101 - if (error_code & PF_USER) {
22103 - * Accessing the stack below %sp is always a bug.
22104 - * The large cushion allows instructions like enter
22105 - * and pusha to work. ("enter $65535, $31" pushes
22106 - * 32 pointers and then decrements %sp by 65535.)
22108 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
22109 - bad_area(regs, error_code, address);
22113 + * Accessing the stack below %sp is always a bug.
22114 + * The large cushion allows instructions like enter
22115 + * and pusha to work. ("enter $65535, $31" pushes
22116 + * 32 pointers and then decrements %sp by 65535.)
22118 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
22119 + bad_area(regs, error_code, address);
22123 +#ifdef CONFIG_PAX_SEGMEXEC
22124 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
22125 + bad_area(regs, error_code, address);
22130 if (unlikely(expand_stack(vma, address))) {
22131 bad_area(regs, error_code, address);
22133 @@ -1199,3 +1416,292 @@ good_area:
22135 up_read(&mm->mmap_sem);
22138 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22139 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
22141 + struct mm_struct *mm = current->mm;
22142 + unsigned long ip = regs->ip;
22144 + if (v8086_mode(regs))
22145 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
22147 +#ifdef CONFIG_PAX_PAGEEXEC
22148 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
22149 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
22151 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
22157 +#ifdef CONFIG_PAX_SEGMEXEC
22158 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
22159 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
22169 +#ifdef CONFIG_PAX_EMUTRAMP
22170 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
22174 + do { /* PaX: libffi trampoline emulation */
22175 + unsigned char mov, jmp;
22176 + unsigned int addr1, addr2;
22178 +#ifdef CONFIG_X86_64
22179 + if ((regs->ip + 9) >> 32)
22183 + err = get_user(mov, (unsigned char __user *)regs->ip);
22184 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22185 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
22186 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22191 + if (mov == 0xB8 && jmp == 0xE9) {
22192 + regs->ax = addr1;
22193 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
22198 + do { /* PaX: gcc trampoline emulation #1 */
22199 + unsigned char mov1, mov2;
22200 + unsigned short jmp;
22201 + unsigned int addr1, addr2;
22203 +#ifdef CONFIG_X86_64
22204 + if ((regs->ip + 11) >> 32)
22208 + err = get_user(mov1, (unsigned char __user *)regs->ip);
22209 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22210 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
22211 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22212 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
22217 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
22218 + regs->cx = addr1;
22219 + regs->ax = addr2;
22220 + regs->ip = addr2;
22225 + do { /* PaX: gcc trampoline emulation #2 */
22226 + unsigned char mov, jmp;
22227 + unsigned int addr1, addr2;
22229 +#ifdef CONFIG_X86_64
22230 + if ((regs->ip + 9) >> 32)
22234 + err = get_user(mov, (unsigned char __user *)regs->ip);
22235 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22236 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
22237 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22242 + if (mov == 0xB9 && jmp == 0xE9) {
22243 + regs->cx = addr1;
22244 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
22249 + return 1; /* PaX in action */
22252 +#ifdef CONFIG_X86_64
22253 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
22257 + do { /* PaX: libffi trampoline emulation */
22258 + unsigned short mov1, mov2, jmp1;
22259 + unsigned char stcclc, jmp2;
22260 + unsigned long addr1, addr2;
22262 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22263 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22264 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22265 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22266 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
22267 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
22268 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
22273 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22274 + regs->r11 = addr1;
22275 + regs->r10 = addr2;
22276 + if (stcclc == 0xF8)
22277 + regs->flags &= ~X86_EFLAGS_CF;
22279 + regs->flags |= X86_EFLAGS_CF;
22280 + regs->ip = addr1;
22285 + do { /* PaX: gcc trampoline emulation #1 */
22286 + unsigned short mov1, mov2, jmp1;
22287 + unsigned char jmp2;
22288 + unsigned int addr1;
22289 + unsigned long addr2;
22291 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22292 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
22293 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
22294 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
22295 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
22296 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
22301 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22302 + regs->r11 = addr1;
22303 + regs->r10 = addr2;
22304 + regs->ip = addr1;
22309 + do { /* PaX: gcc trampoline emulation #2 */
22310 + unsigned short mov1, mov2, jmp1;
22311 + unsigned char jmp2;
22312 + unsigned long addr1, addr2;
22314 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22315 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22316 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22317 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22318 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
22319 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
22324 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22325 + regs->r11 = addr1;
22326 + regs->r10 = addr2;
22327 + regs->ip = addr1;
22332 + return 1; /* PaX in action */
22337 + * PaX: decide what to do with offenders (regs->ip = fault address)
22339 + * returns 1 when task should be killed
22340 + * 2 when gcc trampoline was detected
22342 +static int pax_handle_fetch_fault(struct pt_regs *regs)
22344 + if (v8086_mode(regs))
22347 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
22350 +#ifdef CONFIG_X86_32
22351 + return pax_handle_fetch_fault_32(regs);
22353 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
22354 + return pax_handle_fetch_fault_32(regs);
22356 + return pax_handle_fetch_fault_64(regs);
22361 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22362 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
22366 + printk(KERN_ERR "PAX: bytes at PC: ");
22367 + for (i = 0; i < 20; i++) {
22369 + if (get_user(c, (unsigned char __force_user *)pc+i))
22370 + printk(KERN_CONT "?? ");
22372 + printk(KERN_CONT "%02x ", c);
22376 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
22377 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
22379 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
22380 +#ifdef CONFIG_X86_32
22381 + printk(KERN_CONT "???????? ");
22383 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
22384 + printk(KERN_CONT "???????? ???????? ");
22386 + printk(KERN_CONT "???????????????? ");
22389 +#ifdef CONFIG_X86_64
22390 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
22391 + printk(KERN_CONT "%08x ", (unsigned int)c);
22392 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
22395 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
22403 + * probe_kernel_write(): safely attempt to write to a location
22404 + * @dst: address to write to
22405 + * @src: pointer to the data that shall be written
22406 + * @size: size of the data chunk
22408 + * Safely write to address @dst from the buffer at @src. If a kernel fault
22409 + * happens, handle that and return -EFAULT.
22411 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
22414 + mm_segment_t old_fs = get_fs();
22416 + set_fs(KERNEL_DS);
22417 + pagefault_disable();
22418 + pax_open_kernel();
22419 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
22420 + pax_close_kernel();
22421 + pagefault_enable();
22424 + return ret ? -EFAULT : 0;
22426 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
22427 index dd74e46..7d26398 100644
22428 --- a/arch/x86/mm/gup.c
22429 +++ b/arch/x86/mm/gup.c
22430 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
22432 len = (unsigned long) nr_pages << PAGE_SHIFT;
22434 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22435 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22436 (void __user *)start, len)))
22439 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
22440 index f4f29b1..5cac4fb 100644
22441 --- a/arch/x86/mm/highmem_32.c
22442 +++ b/arch/x86/mm/highmem_32.c
22443 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
22444 idx = type + KM_TYPE_NR*smp_processor_id();
22445 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22446 BUG_ON(!pte_none(*(kmap_pte-idx)));
22448 + pax_open_kernel();
22449 set_pte(kmap_pte-idx, mk_pte(page, prot));
22450 + pax_close_kernel();
22452 arch_flush_lazy_mmu_mode();
22454 return (void *)vaddr;
22455 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
22456 index f581a18..29efd37 100644
22457 --- a/arch/x86/mm/hugetlbpage.c
22458 +++ b/arch/x86/mm/hugetlbpage.c
22459 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
22460 struct hstate *h = hstate_file(file);
22461 struct mm_struct *mm = current->mm;
22462 struct vm_area_struct *vma;
22463 - unsigned long start_addr;
22464 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22466 +#ifdef CONFIG_PAX_SEGMEXEC
22467 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22468 + pax_task_size = SEGMEXEC_TASK_SIZE;
22471 + pax_task_size -= PAGE_SIZE;
22473 if (len > mm->cached_hole_size) {
22474 - start_addr = mm->free_area_cache;
22475 + start_addr = mm->free_area_cache;
22477 - start_addr = TASK_UNMAPPED_BASE;
22478 - mm->cached_hole_size = 0;
22479 + start_addr = mm->mmap_base;
22480 + mm->cached_hole_size = 0;
22484 @@ -280,26 +287,27 @@ full_search:
22486 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22487 /* At this point: (!vma || addr < vma->vm_end). */
22488 - if (TASK_SIZE - len < addr) {
22489 + if (pax_task_size - len < addr) {
22491 * Start a new search - just in case we missed
22494 - if (start_addr != TASK_UNMAPPED_BASE) {
22495 - start_addr = TASK_UNMAPPED_BASE;
22496 + if (start_addr != mm->mmap_base) {
22497 + start_addr = mm->mmap_base;
22498 mm->cached_hole_size = 0;
22503 - if (!vma || addr + len <= vma->vm_start) {
22504 - mm->free_area_cache = addr + len;
22507 + if (check_heap_stack_gap(vma, addr, len))
22509 if (addr + mm->cached_hole_size < vma->vm_start)
22510 mm->cached_hole_size = vma->vm_start - addr;
22511 addr = ALIGN(vma->vm_end, huge_page_size(h));
22514 + mm->free_area_cache = addr + len;
22518 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22519 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22521 struct hstate *h = hstate_file(file);
22522 struct mm_struct *mm = current->mm;
22523 - struct vm_area_struct *vma, *prev_vma;
22524 - unsigned long base = mm->mmap_base, addr = addr0;
22525 + struct vm_area_struct *vma;
22526 + unsigned long base = mm->mmap_base, addr;
22527 unsigned long largest_hole = mm->cached_hole_size;
22528 - int first_time = 1;
22530 /* don't allow allocations above current base */
22531 if (mm->free_area_cache > base)
22532 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22534 mm->free_area_cache = base;
22538 /* make sure it can fit in the remaining address space */
22539 if (mm->free_area_cache < len)
22542 /* either no address requested or can't fit in requested address hole */
22543 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
22544 + addr = (mm->free_area_cache - len);
22546 + addr &= huge_page_mask(h);
22547 + vma = find_vma(mm, addr);
22549 * Lookup failure means no vma is above this address,
22550 * i.e. return with success:
22552 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
22556 * new region fits between prev_vma->vm_end and
22557 * vma->vm_start, use it:
22559 - if (addr + len <= vma->vm_start &&
22560 - (!prev_vma || (addr >= prev_vma->vm_end))) {
22561 + if (check_heap_stack_gap(vma, addr, len)) {
22562 /* remember the address as a hint for next time */
22563 - mm->cached_hole_size = largest_hole;
22564 - return (mm->free_area_cache = addr);
22566 - /* pull free_area_cache down to the first hole */
22567 - if (mm->free_area_cache == vma->vm_end) {
22568 - mm->free_area_cache = vma->vm_start;
22569 - mm->cached_hole_size = largest_hole;
22571 + mm->cached_hole_size = largest_hole;
22572 + return (mm->free_area_cache = addr);
22574 + /* pull free_area_cache down to the first hole */
22575 + if (mm->free_area_cache == vma->vm_end) {
22576 + mm->free_area_cache = vma->vm_start;
22577 + mm->cached_hole_size = largest_hole;
22580 /* remember the largest hole we saw so far */
22581 if (addr + largest_hole < vma->vm_start)
22582 - largest_hole = vma->vm_start - addr;
22583 + largest_hole = vma->vm_start - addr;
22585 /* try just below the current vma->vm_start */
22586 - addr = (vma->vm_start - len) & huge_page_mask(h);
22587 - } while (len <= vma->vm_start);
22588 + addr = skip_heap_stack_gap(vma, len);
22589 + } while (!IS_ERR_VALUE(addr));
22593 - * if hint left us with no space for the requested
22594 - * mapping then try again:
22596 - if (first_time) {
22597 - mm->free_area_cache = base;
22598 - largest_hole = 0;
22603 * A failed mmap() very likely causes application failure,
22604 * so fall back to the bottom-up function here. This scenario
22605 * can happen with large stack limits and large mmap()
22608 - mm->free_area_cache = TASK_UNMAPPED_BASE;
22610 +#ifdef CONFIG_PAX_SEGMEXEC
22611 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22612 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22616 + mm->mmap_base = TASK_UNMAPPED_BASE;
22618 +#ifdef CONFIG_PAX_RANDMMAP
22619 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22620 + mm->mmap_base += mm->delta_mmap;
22623 + mm->free_area_cache = mm->mmap_base;
22624 mm->cached_hole_size = ~0UL;
22625 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
22626 len, pgoff, flags);
22627 @@ -386,6 +392,7 @@ fail:
22629 * Restore the topdown base:
22631 + mm->mmap_base = base;
22632 mm->free_area_cache = base;
22633 mm->cached_hole_size = ~0UL;
22635 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22636 struct hstate *h = hstate_file(file);
22637 struct mm_struct *mm = current->mm;
22638 struct vm_area_struct *vma;
22639 + unsigned long pax_task_size = TASK_SIZE;
22641 if (len & ~huge_page_mask(h))
22643 - if (len > TASK_SIZE)
22645 +#ifdef CONFIG_PAX_SEGMEXEC
22646 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22647 + pax_task_size = SEGMEXEC_TASK_SIZE;
22650 + pax_task_size -= PAGE_SIZE;
22652 + if (len > pax_task_size)
22655 if (flags & MAP_FIXED) {
22656 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22658 addr = ALIGN(addr, huge_page_size(h));
22659 vma = find_vma(mm, addr);
22660 - if (TASK_SIZE - len >= addr &&
22661 - (!vma || addr + len <= vma->vm_start))
22662 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
22665 if (mm->get_unmapped_area == arch_get_unmapped_area)
22666 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
22667 index 87488b9..399f416 100644
22668 --- a/arch/x86/mm/init.c
22669 +++ b/arch/x86/mm/init.c
22671 #include <asm/tlbflush.h>
22672 #include <asm/tlb.h>
22673 #include <asm/proto.h>
22674 +#include <asm/desc.h>
22676 unsigned long __initdata pgt_buf_start;
22677 unsigned long __meminitdata pgt_buf_end;
22678 @@ -31,7 +32,7 @@ int direct_gbpages
22679 static void __init find_early_table_space(unsigned long end, int use_pse,
22682 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22683 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22686 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22687 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
22689 int devmem_is_allowed(unsigned long pagenr)
22691 +#ifdef CONFIG_GRKERNSEC_KMEM
22696 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22701 +#ifdef CONFIG_VM86
22702 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22707 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22709 +#ifdef CONFIG_GRKERNSEC_KMEM
22710 + /* throw out everything else below 1MB */
22715 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22717 if (!page_is_ram(pagenr))
22718 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
22720 void free_initmem(void)
22723 +#ifdef CONFIG_PAX_KERNEXEC
22724 +#ifdef CONFIG_X86_32
22725 + /* PaX: limit KERNEL_CS to actual size */
22726 + unsigned long addr, limit;
22727 + struct desc_struct d;
22730 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22731 + limit = (limit - 1UL) >> PAGE_SHIFT;
22733 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22734 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
22735 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22736 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22739 + /* PaX: make KERNEL_CS read-only */
22740 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22741 + if (!paravirt_enabled())
22742 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22744 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22745 + pgd = pgd_offset_k(addr);
22746 + pud = pud_offset(pgd, addr);
22747 + pmd = pmd_offset(pud, addr);
22748 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22751 +#ifdef CONFIG_X86_PAE
22752 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22754 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22755 + pgd = pgd_offset_k(addr);
22756 + pud = pud_offset(pgd, addr);
22757 + pmd = pmd_offset(pud, addr);
22758 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22763 +#ifdef CONFIG_MODULES
22764 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22771 + unsigned long addr, end;
22773 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22774 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22775 + pgd = pgd_offset_k(addr);
22776 + pud = pud_offset(pgd, addr);
22777 + pmd = pmd_offset(pud, addr);
22778 + if (!pmd_present(*pmd))
22780 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22781 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22783 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22786 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22787 + end = addr + KERNEL_IMAGE_SIZE;
22788 + for (; addr < end; addr += PMD_SIZE) {
22789 + pgd = pgd_offset_k(addr);
22790 + pud = pud_offset(pgd, addr);
22791 + pmd = pmd_offset(pud, addr);
22792 + if (!pmd_present(*pmd))
22794 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22795 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22802 free_init_pages("unused kernel memory",
22803 (unsigned long)(&__init_begin),
22804 (unsigned long)(&__init_end));
22805 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
22806 index 29f7c6d..b46b35b 100644
22807 --- a/arch/x86/mm/init_32.c
22808 +++ b/arch/x86/mm/init_32.c
22809 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
22813 - * Creates a middle page table and puts a pointer to it in the
22814 - * given global directory entry. This only returns the gd entry
22815 - * in non-PAE compilation mode, since the middle layer is folded.
22817 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
22820 - pmd_t *pmd_table;
22822 -#ifdef CONFIG_X86_PAE
22823 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
22824 - if (after_bootmem)
22825 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
22827 - pmd_table = (pmd_t *)alloc_low_page();
22828 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
22829 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
22830 - pud = pud_offset(pgd, 0);
22831 - BUG_ON(pmd_table != pmd_offset(pud, 0));
22833 - return pmd_table;
22836 - pud = pud_offset(pgd, 0);
22837 - pmd_table = pmd_offset(pud, 0);
22839 - return pmd_table;
22843 * Create a page table and place a pointer to it in a middle page
22846 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
22847 page_table = (pte_t *)alloc_low_page();
22849 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22850 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22851 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22853 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22855 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22858 return pte_offset_kernel(pmd, 0);
22861 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
22864 + pmd_t *pmd_table;
22866 + pud = pud_offset(pgd, 0);
22867 + pmd_table = pmd_offset(pud, 0);
22869 + return pmd_table;
22872 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22874 int pgd_idx = pgd_index(vaddr);
22875 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22876 int pgd_idx, pmd_idx;
22877 unsigned long vaddr;
22883 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22884 pgd = pgd_base + pgd_idx;
22886 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22887 - pmd = one_md_table_init(pgd);
22888 - pmd = pmd + pmd_index(vaddr);
22889 + pud = pud_offset(pgd, vaddr);
22890 + pmd = pmd_offset(pud, vaddr);
22892 +#ifdef CONFIG_X86_PAE
22893 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22896 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22897 pmd++, pmd_idx++) {
22898 pte = page_table_kmap_check(one_page_table_init(pmd),
22899 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22903 -static inline int is_kernel_text(unsigned long addr)
22904 +static inline int is_kernel_text(unsigned long start, unsigned long end)
22906 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22909 + if ((start > ktla_ktva((unsigned long)_etext) ||
22910 + end <= ktla_ktva((unsigned long)_stext)) &&
22911 + (start > ktla_ktva((unsigned long)_einittext) ||
22912 + end <= ktla_ktva((unsigned long)_sinittext)) &&
22914 +#ifdef CONFIG_ACPI_SLEEP
22915 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22918 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22924 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
22925 unsigned long last_map_addr = end;
22926 unsigned long start_pfn, end_pfn;
22927 pgd_t *pgd_base = swapper_pg_dir;
22928 - int pgd_idx, pmd_idx, pte_ofs;
22929 + unsigned int pgd_idx, pmd_idx, pte_ofs;
22935 unsigned pages_2m, pages_4k;
22936 @@ -281,8 +282,13 @@ repeat:
22938 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22939 pgd = pgd_base + pgd_idx;
22940 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22941 - pmd = one_md_table_init(pgd);
22942 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22943 + pud = pud_offset(pgd, 0);
22944 + pmd = pmd_offset(pud, 0);
22946 +#ifdef CONFIG_X86_PAE
22947 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22950 if (pfn >= end_pfn)
22952 @@ -294,14 +300,13 @@ repeat:
22954 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22955 pmd++, pmd_idx++) {
22956 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22957 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22960 * Map with big pages if possible, otherwise
22961 * create normal page tables:
22964 - unsigned int addr2;
22965 pgprot_t prot = PAGE_KERNEL_LARGE;
22967 * first pass will use the same initial
22968 @@ -311,11 +316,7 @@ repeat:
22969 __pgprot(PTE_IDENT_ATTR |
22972 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22973 - PAGE_OFFSET + PAGE_SIZE-1;
22975 - if (is_kernel_text(addr) ||
22976 - is_kernel_text(addr2))
22977 + if (is_kernel_text(address, address + PMD_SIZE))
22978 prot = PAGE_KERNEL_LARGE_EXEC;
22981 @@ -332,7 +333,7 @@ repeat:
22982 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22984 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22985 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22986 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22987 pgprot_t prot = PAGE_KERNEL;
22989 * first pass will use the same initial
22990 @@ -340,7 +341,7 @@ repeat:
22992 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22994 - if (is_kernel_text(addr))
22995 + if (is_kernel_text(address, address + PAGE_SIZE))
22996 prot = PAGE_KERNEL_EXEC;
22999 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
23001 pud = pud_offset(pgd, va);
23002 pmd = pmd_offset(pud, va);
23003 - if (!pmd_present(*pmd))
23004 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
23007 pte = pte_offset_kernel(pmd, va);
23008 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
23010 static void __init pagetable_init(void)
23012 - pgd_t *pgd_base = swapper_pg_dir;
23014 - permanent_kmaps_init(pgd_base);
23015 + permanent_kmaps_init(swapper_pg_dir);
23018 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
23019 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
23020 EXPORT_SYMBOL_GPL(__supported_pte_mask);
23022 /* user-defined highmem size */
23023 @@ -757,6 +756,12 @@ void __init mem_init(void)
23027 +#ifdef CONFIG_PAX_PER_CPU_PGD
23028 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
23029 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23030 + KERNEL_PGD_PTRS);
23033 #ifdef CONFIG_FLATMEM
23036 @@ -774,7 +779,7 @@ void __init mem_init(void)
23037 set_highmem_pages_init();
23039 codesize = (unsigned long) &_etext - (unsigned long) &_text;
23040 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
23041 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
23042 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
23044 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
23045 @@ -815,10 +820,10 @@ void __init mem_init(void)
23046 ((unsigned long)&__init_end -
23047 (unsigned long)&__init_begin) >> 10,
23049 - (unsigned long)&_etext, (unsigned long)&_edata,
23050 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
23051 + (unsigned long)&_sdata, (unsigned long)&_edata,
23052 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
23054 - (unsigned long)&_text, (unsigned long)&_etext,
23055 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
23056 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
23059 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
23060 if (!kernel_set_to_readonly)
23063 + start = ktla_ktva(start);
23064 pr_debug("Set kernel text: %lx - %lx for read write\n",
23065 start, start+size);
23067 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
23068 if (!kernel_set_to_readonly)
23071 + start = ktla_ktva(start);
23072 pr_debug("Set kernel text: %lx - %lx for read only\n",
23073 start, start+size);
23075 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
23076 unsigned long start = PFN_ALIGN(_text);
23077 unsigned long size = PFN_ALIGN(_etext) - start;
23079 + start = ktla_ktva(start);
23080 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
23081 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
23083 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
23084 index bbaaa00..796fa65 100644
23085 --- a/arch/x86/mm/init_64.c
23086 +++ b/arch/x86/mm/init_64.c
23087 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
23088 * around without checking the pgd every time.
23091 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
23092 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
23093 EXPORT_SYMBOL_GPL(__supported_pte_mask);
23095 int force_personality32;
23096 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
23098 for (address = start; address <= end; address += PGDIR_SIZE) {
23099 const pgd_t *pgd_ref = pgd_offset_k(address);
23101 +#ifdef CONFIG_PAX_PER_CPU_PGD
23102 + unsigned long cpu;
23107 if (pgd_none(*pgd_ref))
23110 spin_lock(&pgd_lock);
23112 +#ifdef CONFIG_PAX_PER_CPU_PGD
23113 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23114 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
23116 list_for_each_entry(page, &pgd_list, lru) {
23118 spinlock_t *pgt_lock;
23119 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
23120 /* the pgt_lock only for Xen */
23121 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23122 spin_lock(pgt_lock);
23125 if (pgd_none(*pgd))
23126 set_pgd(pgd, *pgd_ref);
23127 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
23128 BUG_ON(pgd_page_vaddr(*pgd)
23129 != pgd_page_vaddr(*pgd_ref));
23131 +#ifndef CONFIG_PAX_PER_CPU_PGD
23132 spin_unlock(pgt_lock);
23136 spin_unlock(&pgd_lock);
23138 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
23139 pmd = fill_pmd(pud, vaddr);
23140 pte = fill_pte(pmd, vaddr);
23142 + pax_open_kernel();
23143 set_pte(pte, new_pte);
23144 + pax_close_kernel();
23147 * It's enough to flush this one mapping.
23148 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
23149 pgd = pgd_offset_k((unsigned long)__va(phys));
23150 if (pgd_none(*pgd)) {
23151 pud = (pud_t *) spp_getpage();
23152 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
23154 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
23156 pud = pud_offset(pgd, (unsigned long)__va(phys));
23157 if (pud_none(*pud)) {
23158 pmd = (pmd_t *) spp_getpage();
23159 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
23161 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
23163 pmd = pmd_offset(pud, phys);
23164 BUG_ON(!pmd_none(*pmd));
23165 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
23166 if (pfn >= pgt_buf_top)
23167 panic("alloc_low_page: ran out of memory");
23169 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
23170 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
23172 *phys = pfn * PAGE_SIZE;
23174 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
23177 left = phys & (PAGE_SIZE - 1);
23178 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
23179 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
23180 adr = (void *)(((unsigned long)adr) | left);
23183 @@ -693,6 +707,12 @@ void __init mem_init(void)
23187 +#ifdef CONFIG_PAX_PER_CPU_PGD
23188 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
23189 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23190 + KERNEL_PGD_PTRS);
23193 /* clear_bss() already clear the empty_zero_page */
23196 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
23197 static struct vm_area_struct gate_vma = {
23198 .vm_start = VSYSCALL_START,
23199 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
23200 - .vm_page_prot = PAGE_READONLY_EXEC,
23201 - .vm_flags = VM_READ | VM_EXEC
23202 + .vm_page_prot = PAGE_READONLY,
23203 + .vm_flags = VM_READ
23206 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
23207 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
23209 const char *arch_vma_name(struct vm_area_struct *vma)
23211 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23212 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23214 if (vma == &gate_vma)
23215 return "[vsyscall]";
23216 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
23217 index 7b179b4..6bd1777 100644
23218 --- a/arch/x86/mm/iomap_32.c
23219 +++ b/arch/x86/mm/iomap_32.c
23220 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
23221 type = kmap_atomic_idx_push();
23222 idx = type + KM_TYPE_NR * smp_processor_id();
23223 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23225 + pax_open_kernel();
23226 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
23227 + pax_close_kernel();
23229 arch_flush_lazy_mmu_mode();
23231 return (void *)vaddr;
23232 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
23233 index be1ef57..55f0160 100644
23234 --- a/arch/x86/mm/ioremap.c
23235 +++ b/arch/x86/mm/ioremap.c
23236 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
23237 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
23238 int is_ram = page_is_ram(pfn);
23240 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
23241 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
23243 WARN_ON_ONCE(is_ram);
23245 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
23247 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
23248 if (page_is_ram(start >> PAGE_SHIFT))
23249 +#ifdef CONFIG_HIGHMEM
23250 + if ((start >> PAGE_SHIFT) < max_low_pfn)
23254 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
23255 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
23256 early_param("early_ioremap_debug", early_ioremap_debug_setup);
23258 static __initdata int after_paging_init;
23259 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
23260 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
23262 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
23264 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
23265 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
23267 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
23268 - memset(bm_pte, 0, sizeof(bm_pte));
23269 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
23270 + pmd_populate_user(&init_mm, pmd, bm_pte);
23273 * The boot-ioremap range spans multiple pmds, for which
23274 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
23275 index d87dd6d..bf3fa66 100644
23276 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
23277 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
23278 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
23279 * memory (e.g. tracked pages)? For now, we need this to avoid
23280 * invoking kmemcheck for PnP BIOS calls.
23282 - if (regs->flags & X86_VM_MASK)
23283 + if (v8086_mode(regs))
23285 - if (regs->cs != __KERNEL_CS)
23286 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
23289 pte = kmemcheck_pte_lookup(address);
23290 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
23291 index 845df68..1d8d29f 100644
23292 --- a/arch/x86/mm/mmap.c
23293 +++ b/arch/x86/mm/mmap.c
23294 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
23295 * Leave an at least ~128 MB hole with possible stack randomization.
23297 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
23298 -#define MAX_GAP (TASK_SIZE/6*5)
23299 +#define MAX_GAP (pax_task_size/6*5)
23301 static int mmap_is_legacy(void)
23303 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
23304 return rnd << PAGE_SHIFT;
23307 -static unsigned long mmap_base(void)
23308 +static unsigned long mmap_base(struct mm_struct *mm)
23310 unsigned long gap = rlimit(RLIMIT_STACK);
23311 + unsigned long pax_task_size = TASK_SIZE;
23313 +#ifdef CONFIG_PAX_SEGMEXEC
23314 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23315 + pax_task_size = SEGMEXEC_TASK_SIZE;
23320 else if (gap > MAX_GAP)
23323 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
23324 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
23328 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
23329 * does, but not when emulating X86_32
23331 -static unsigned long mmap_legacy_base(void)
23332 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
23334 - if (mmap_is_ia32())
23335 + if (mmap_is_ia32()) {
23337 +#ifdef CONFIG_PAX_SEGMEXEC
23338 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23339 + return SEGMEXEC_TASK_UNMAPPED_BASE;
23343 return TASK_UNMAPPED_BASE;
23346 return TASK_UNMAPPED_BASE + mmap_rnd();
23349 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
23350 void arch_pick_mmap_layout(struct mm_struct *mm)
23352 if (mmap_is_legacy()) {
23353 - mm->mmap_base = mmap_legacy_base();
23354 + mm->mmap_base = mmap_legacy_base(mm);
23356 +#ifdef CONFIG_PAX_RANDMMAP
23357 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23358 + mm->mmap_base += mm->delta_mmap;
23361 mm->get_unmapped_area = arch_get_unmapped_area;
23362 mm->unmap_area = arch_unmap_area;
23364 - mm->mmap_base = mmap_base();
23365 + mm->mmap_base = mmap_base(mm);
23367 +#ifdef CONFIG_PAX_RANDMMAP
23368 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23369 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
23372 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
23373 mm->unmap_area = arch_unmap_area_topdown;
23375 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
23376 index de54b9b..799051e 100644
23377 --- a/arch/x86/mm/mmio-mod.c
23378 +++ b/arch/x86/mm/mmio-mod.c
23379 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
23383 - unsigned char *ip = (unsigned char *)instptr;
23384 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
23385 my_trace->opcode = MMIO_UNKNOWN_OP;
23386 my_trace->width = 0;
23387 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
23388 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
23389 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23390 void __iomem *addr)
23392 - static atomic_t next_id;
23393 + static atomic_unchecked_t next_id;
23394 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
23395 /* These are page-unaligned. */
23396 struct mmiotrace_map map = {
23397 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23401 - .id = atomic_inc_return(&next_id)
23402 + .id = atomic_inc_return_unchecked(&next_id)
23404 map.map_id = trace->id;
23406 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
23407 index b008656..773eac2 100644
23408 --- a/arch/x86/mm/pageattr-test.c
23409 +++ b/arch/x86/mm/pageattr-test.c
23410 @@ -36,7 +36,7 @@ enum {
23412 static int pte_testbit(pte_t pte)
23414 - return pte_flags(pte) & _PAGE_UNUSED1;
23415 + return pte_flags(pte) & _PAGE_CPA_TEST;
23418 struct split_state {
23419 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
23420 index f9e5267..77b1a40 100644
23421 --- a/arch/x86/mm/pageattr.c
23422 +++ b/arch/x86/mm/pageattr.c
23423 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23425 #ifdef CONFIG_PCI_BIOS
23426 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
23427 - pgprot_val(forbidden) |= _PAGE_NX;
23428 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23432 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23433 * Does not cover __inittext since that is gone later on. On
23434 * 64bit we do not enforce !NX on the low mapping
23436 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
23437 - pgprot_val(forbidden) |= _PAGE_NX;
23438 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
23439 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23441 +#ifdef CONFIG_DEBUG_RODATA
23443 * The .rodata section needs to be read-only. Using the pfn
23444 * catches all aliases.
23445 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23446 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
23447 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
23448 pgprot_val(forbidden) |= _PAGE_RW;
23451 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
23453 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23457 +#ifdef CONFIG_PAX_KERNEXEC
23458 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
23459 + pgprot_val(forbidden) |= _PAGE_RW;
23460 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23464 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
23467 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
23468 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
23470 /* change init_mm */
23471 + pax_open_kernel();
23472 set_pte_atomic(kpte, pte);
23474 #ifdef CONFIG_X86_32
23475 if (!SHARED_KERNEL_PMD) {
23477 +#ifdef CONFIG_PAX_PER_CPU_PGD
23478 + unsigned long cpu;
23483 +#ifdef CONFIG_PAX_PER_CPU_PGD
23484 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23485 + pgd_t *pgd = get_cpu_pgd(cpu);
23487 list_for_each_entry(page, &pgd_list, lru) {
23489 + pgd_t *pgd = (pgd_t *)page_address(page);
23495 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
23496 + pgd += pgd_index(address);
23497 pud = pud_offset(pgd, address);
23498 pmd = pmd_offset(pud, address);
23499 set_pte_atomic((pte_t *)pmd, pte);
23503 + pax_close_kernel();
23507 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
23508 index f6ff57b..481690f 100644
23509 --- a/arch/x86/mm/pat.c
23510 +++ b/arch/x86/mm/pat.c
23511 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
23514 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
23515 - current->comm, current->pid, start, end);
23516 + current->comm, task_pid_nr(current), start, end);
23520 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23521 while (cursor < to) {
23522 if (!devmem_is_allowed(pfn)) {
23524 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23525 - current->comm, from, to);
23526 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
23527 + current->comm, from, to, cursor);
23530 cursor += PAGE_SIZE;
23531 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
23533 "%s:%d ioremap_change_attr failed %s "
23535 - current->comm, current->pid,
23536 + current->comm, task_pid_nr(current),
23538 base, (unsigned long long)(base + size));
23540 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23541 if (want_flags != flags) {
23542 printk(KERN_WARNING
23543 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
23544 - current->comm, current->pid,
23545 + current->comm, task_pid_nr(current),
23546 cattr_name(want_flags),
23547 (unsigned long long)paddr,
23548 (unsigned long long)(paddr + size),
23549 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23550 free_memtype(paddr, paddr + size);
23551 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
23552 " for %Lx-%Lx, got %s\n",
23553 - current->comm, current->pid,
23554 + current->comm, task_pid_nr(current),
23555 cattr_name(want_flags),
23556 (unsigned long long)paddr,
23557 (unsigned long long)(paddr + size),
23558 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
23559 index 9f0614d..92ae64a 100644
23560 --- a/arch/x86/mm/pf_in.c
23561 +++ b/arch/x86/mm/pf_in.c
23562 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
23564 enum reason_type rv = OTHERS;
23566 - p = (unsigned char *)ins_addr;
23567 + p = (unsigned char *)ktla_ktva(ins_addr);
23568 p += skip_prefix(p, &prf);
23569 p += get_opcode(p, &opcode);
23571 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
23572 struct prefix_bits prf;
23575 - p = (unsigned char *)ins_addr;
23576 + p = (unsigned char *)ktla_ktva(ins_addr);
23577 p += skip_prefix(p, &prf);
23578 p += get_opcode(p, &opcode);
23580 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
23581 struct prefix_bits prf;
23584 - p = (unsigned char *)ins_addr;
23585 + p = (unsigned char *)ktla_ktva(ins_addr);
23586 p += skip_prefix(p, &prf);
23587 p += get_opcode(p, &opcode);
23589 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
23590 struct prefix_bits prf;
23593 - p = (unsigned char *)ins_addr;
23594 + p = (unsigned char *)ktla_ktva(ins_addr);
23595 p += skip_prefix(p, &prf);
23596 p += get_opcode(p, &opcode);
23597 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
23598 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
23599 struct prefix_bits prf;
23602 - p = (unsigned char *)ins_addr;
23603 + p = (unsigned char *)ktla_ktva(ins_addr);
23604 p += skip_prefix(p, &prf);
23605 p += get_opcode(p, &opcode);
23606 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
23607 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
23608 index 8573b83..c3b1a30 100644
23609 --- a/arch/x86/mm/pgtable.c
23610 +++ b/arch/x86/mm/pgtable.c
23611 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
23612 list_del(&page->lru);
23615 -#define UNSHARED_PTRS_PER_PGD \
23616 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23617 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23618 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
23620 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23623 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
23627 +#ifdef CONFIG_PAX_PER_CPU_PGD
23628 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23633 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
23641 +#ifdef CONFIG_X86_64
23642 +#define pxd_t pud_t
23643 +#define pyd_t pgd_t
23644 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
23645 +#define pxd_free(mm, pud) pud_free((mm), (pud))
23646 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
23647 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
23648 +#define PYD_SIZE PGDIR_SIZE
23650 +#define pxd_t pmd_t
23651 +#define pyd_t pud_t
23652 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
23653 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
23654 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
23655 +#define pyd_offset(mm, address) pud_offset((mm), (address))
23656 +#define PYD_SIZE PUD_SIZE
23659 +#ifdef CONFIG_PAX_PER_CPU_PGD
23660 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
23661 +static inline void pgd_dtor(pgd_t *pgd) {}
23663 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
23665 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
23666 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
23668 spin_unlock(&pgd_lock);
23673 * List of all pgd's needed for non-PAE so it can invalidate entries
23674 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
23678 -#ifdef CONFIG_X86_PAE
23679 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23681 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
23682 * updating the top-level pagetable entries to guarantee the
23683 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
23684 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
23685 * and initialize the kernel pmds here.
23687 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
23688 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23690 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23692 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23696 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
23697 +#define PREALLOCATED_PXDS USER_PGD_PTRS
23698 #else /* !CONFIG_X86_PAE */
23700 /* No need to prepopulate any pagetable entries in non-PAE modes. */
23701 -#define PREALLOCATED_PMDS 0
23702 +#define PREALLOCATED_PXDS 0
23704 #endif /* CONFIG_X86_PAE */
23706 -static void free_pmds(pmd_t *pmds[])
23707 +static void free_pxds(pxd_t *pxds[])
23711 - for(i = 0; i < PREALLOCATED_PMDS; i++)
23713 - free_page((unsigned long)pmds[i]);
23714 + for(i = 0; i < PREALLOCATED_PXDS; i++)
23716 + free_page((unsigned long)pxds[i]);
23719 -static int preallocate_pmds(pmd_t *pmds[])
23720 +static int preallocate_pxds(pxd_t *pxds[])
23723 bool failed = false;
23725 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23726 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
23728 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23729 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
23742 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
23743 * preallocate which never got a corresponding vma will need to be
23746 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
23747 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
23751 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23752 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23753 pgd_t pgd = pgdp[i];
23755 if (pgd_val(pgd) != 0) {
23756 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
23757 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
23759 - pgdp[i] = native_make_pgd(0);
23760 + set_pgd(pgdp + i, native_make_pgd(0));
23762 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
23763 - pmd_free(mm, pmd);
23764 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
23765 + pxd_free(mm, pxd);
23770 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23771 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23775 unsigned long addr;
23778 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23779 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23782 - pud = pud_offset(pgd, 0);
23783 +#ifdef CONFIG_X86_64
23784 + pyd = pyd_offset(mm, 0L);
23786 + pyd = pyd_offset(pgd, 0L);
23789 - for (addr = i = 0; i < PREALLOCATED_PMDS;
23790 - i++, pud++, addr += PUD_SIZE) {
23791 - pmd_t *pmd = pmds[i];
23792 + for (addr = i = 0; i < PREALLOCATED_PXDS;
23793 + i++, pyd++, addr += PYD_SIZE) {
23794 + pxd_t *pxd = pxds[i];
23796 if (i >= KERNEL_PGD_BOUNDARY)
23797 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23798 - sizeof(pmd_t) * PTRS_PER_PMD);
23799 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23800 + sizeof(pxd_t) * PTRS_PER_PMD);
23802 - pud_populate(mm, pud, pmd);
23803 + pyd_populate(mm, pyd, pxd);
23807 pgd_t *pgd_alloc(struct mm_struct *mm)
23810 - pmd_t *pmds[PREALLOCATED_PMDS];
23811 + pxd_t *pxds[PREALLOCATED_PXDS];
23813 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23815 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23819 - if (preallocate_pmds(pmds) != 0)
23820 + if (preallocate_pxds(pxds) != 0)
23823 if (paravirt_pgd_alloc(mm) != 0)
23824 - goto out_free_pmds;
23825 + goto out_free_pxds;
23828 * Make sure that pre-populating the pmds is atomic with
23829 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23830 spin_lock(&pgd_lock);
23833 - pgd_prepopulate_pmd(mm, pgd, pmds);
23834 + pgd_prepopulate_pxd(mm, pgd, pxds);
23836 spin_unlock(&pgd_lock);
23845 free_page((unsigned long)pgd);
23847 @@ -295,7 +344,7 @@ out:
23849 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23851 - pgd_mop_up_pmds(mm, pgd);
23852 + pgd_mop_up_pxds(mm, pgd);
23854 paravirt_pgd_free(mm, pgd);
23855 free_page((unsigned long)pgd);
23856 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
23857 index cac7184..09a39fa 100644
23858 --- a/arch/x86/mm/pgtable_32.c
23859 +++ b/arch/x86/mm/pgtable_32.c
23860 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
23863 pte = pte_offset_kernel(pmd, vaddr);
23865 + pax_open_kernel();
23866 if (pte_val(pteval))
23867 set_pte_at(&init_mm, vaddr, pte, pteval);
23869 pte_clear(&init_mm, vaddr, pte);
23870 + pax_close_kernel();
23873 * It's enough to flush this one mapping.
23874 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
23875 index 410531d..0f16030 100644
23876 --- a/arch/x86/mm/setup_nx.c
23877 +++ b/arch/x86/mm/setup_nx.c
23879 #include <asm/pgtable.h>
23880 #include <asm/proto.h>
23882 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23883 static int disable_nx __cpuinitdata;
23885 +#ifndef CONFIG_PAX_PAGEEXEC
23889 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
23892 early_param("noexec", noexec_setup);
23897 void __cpuinit x86_configure_nx(void)
23899 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23900 if (cpu_has_nx && !disable_nx)
23901 __supported_pte_mask |= _PAGE_NX;
23904 __supported_pte_mask &= ~_PAGE_NX;
23907 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
23908 index d6c0418..06a0ad5 100644
23909 --- a/arch/x86/mm/tlb.c
23910 +++ b/arch/x86/mm/tlb.c
23911 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
23913 cpumask_clear_cpu(cpu,
23914 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23916 +#ifndef CONFIG_PAX_PER_CPU_PGD
23917 load_cr3(swapper_pg_dir);
23921 EXPORT_SYMBOL_GPL(leave_mm);
23923 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
23924 index 6687022..ceabcfa 100644
23925 --- a/arch/x86/net/bpf_jit.S
23926 +++ b/arch/x86/net/bpf_jit.S
23929 #include <linux/linkage.h>
23930 #include <asm/dwarf2.h>
23931 +#include <asm/alternative-asm.h>
23934 * Calling convention :
23935 @@ -35,6 +36,7 @@ sk_load_word:
23936 jle bpf_slow_path_word
23937 mov (SKBDATA,%rsi),%eax
23938 bswap %eax /* ntohl() */
23939 + pax_force_retaddr
23943 @@ -53,6 +55,7 @@ sk_load_half:
23944 jle bpf_slow_path_half
23945 movzwl (SKBDATA,%rsi),%eax
23946 rol $8,%ax # ntohs()
23947 + pax_force_retaddr
23951 @@ -66,6 +69,7 @@ sk_load_byte:
23952 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
23953 jle bpf_slow_path_byte
23954 movzbl (SKBDATA,%rsi),%eax
23955 + pax_force_retaddr
23959 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
23960 movzbl (SKBDATA,%rsi),%ebx
23963 + pax_force_retaddr
23966 ENDPROC(sk_load_byte_msh)
23967 @@ -91,6 +96,7 @@ bpf_error:
23971 + pax_force_retaddr
23974 /* rsi contains offset and can be scratched */
23975 @@ -113,6 +119,7 @@ bpf_slow_path_word:
23979 + pax_force_retaddr
23982 bpf_slow_path_half:
23983 @@ -121,12 +128,14 @@ bpf_slow_path_half:
23987 + pax_force_retaddr
23990 bpf_slow_path_byte:
23991 bpf_slow_path_common(1)
23993 movzbl -12(%rbp),%eax
23994 + pax_force_retaddr
23997 bpf_slow_path_byte_msh:
23998 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
24002 + pax_force_retaddr
24004 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
24005 index 7c1b765..8c072c6 100644
24006 --- a/arch/x86/net/bpf_jit_comp.c
24007 +++ b/arch/x86/net/bpf_jit_comp.c
24008 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
24012 +struct bpf_jit_work {
24013 + struct work_struct work;
24017 void bpf_jit_compile(struct sk_filter *fp)
24019 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
24023 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
24027 /* Before first pass, make a rough estimation of addrs[]
24028 * each bpf instruction is translated to less than 64 bytes
24030 @@ -476,7 +484,7 @@ void bpf_jit_compile(struct sk_filter *fp)
24031 func = sk_load_word;
24032 common_load: seen |= SEEN_DATAREF;
24036 t_offset = func - (image + addrs[i]);
24037 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
24038 EMIT1_off32(0xe8, t_offset); /* call */
24039 @@ -586,17 +594,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
24042 /* hmm, too complex filter, give up with jit compiler */
24046 ilen = prog - temp;
24048 if (unlikely(proglen + ilen > oldproglen)) {
24049 pr_err("bpb_jit_compile fatal error\n");
24051 - module_free(NULL, image);
24053 + module_free_exec(NULL, image);
24056 + pax_open_kernel();
24057 memcpy(image + proglen, temp, ilen);
24058 + pax_close_kernel();
24061 addrs[i] = proglen;
24062 @@ -617,11 +626,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
24065 if (proglen == oldproglen) {
24066 - image = module_alloc(max_t(unsigned int,
24068 - sizeof(struct work_struct)));
24069 + image = module_alloc_exec(proglen);
24074 oldproglen = proglen;
24076 @@ -637,7 +644,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
24077 bpf_flush_icache(image, image + proglen);
24079 fp->bpf_func = (void *)image;
24088 @@ -645,18 +655,20 @@ out:
24090 static void jit_free_defer(struct work_struct *arg)
24092 - module_free(NULL, arg);
24093 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
24097 /* run from softirq, we must use a work_struct to call
24098 - * module_free() from process context
24099 + * module_free_exec() from process context
24101 void bpf_jit_free(struct sk_filter *fp)
24103 if (fp->bpf_func != sk_run_filter) {
24104 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
24105 + struct work_struct *work = &fp->work->work;
24107 INIT_WORK(work, jit_free_defer);
24108 + fp->work->image = fp->bpf_func;
24109 schedule_work(work);
24112 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
24113 index bff89df..377758a 100644
24114 --- a/arch/x86/oprofile/backtrace.c
24115 +++ b/arch/x86/oprofile/backtrace.c
24116 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
24117 struct stack_frame_ia32 *fp;
24118 unsigned long bytes;
24120 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
24121 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
24122 if (bytes != sizeof(bufhead))
24125 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
24126 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
24128 oprofile_add_trace(bufhead[0].return_address);
24130 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
24131 struct stack_frame bufhead[2];
24132 unsigned long bytes;
24134 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
24135 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
24136 if (bytes != sizeof(bufhead))
24139 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
24141 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
24143 - if (!user_mode_vm(regs)) {
24144 + if (!user_mode(regs)) {
24145 unsigned long stack = kernel_stack_pointer(regs);
24147 dump_trace(NULL, regs, (unsigned long *)stack, 0,
24148 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
24149 index cb29191..036766d 100644
24150 --- a/arch/x86/pci/mrst.c
24151 +++ b/arch/x86/pci/mrst.c
24152 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
24153 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
24154 pci_mmcfg_late_init();
24155 pcibios_enable_irq = mrst_pci_irq_enable;
24156 - pci_root_ops = pci_mrst_ops;
24157 + pax_open_kernel();
24158 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
24159 + pax_close_kernel();
24160 /* Continue with standard init */
24163 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
24164 index db0e9a5..0372c14 100644
24165 --- a/arch/x86/pci/pcbios.c
24166 +++ b/arch/x86/pci/pcbios.c
24167 @@ -79,50 +79,93 @@ union bios32 {
24169 unsigned long address;
24170 unsigned short segment;
24171 -} bios32_indirect = { 0, __KERNEL_CS };
24172 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
24175 * Returns the entry point for the given service, NULL on error
24178 -static unsigned long bios32_service(unsigned long service)
24179 +static unsigned long __devinit bios32_service(unsigned long service)
24181 unsigned char return_code; /* %al */
24182 unsigned long address; /* %ebx */
24183 unsigned long length; /* %ecx */
24184 unsigned long entry; /* %edx */
24185 unsigned long flags;
24186 + struct desc_struct d, *gdt;
24188 local_irq_save(flags);
24189 - __asm__("lcall *(%%edi); cld"
24191 + gdt = get_cpu_gdt_table(smp_processor_id());
24193 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
24194 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
24195 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
24196 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
24198 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
24199 : "=a" (return_code),
24205 - "D" (&bios32_indirect));
24206 + "D" (&bios32_indirect),
24207 + "r"(__PCIBIOS_DS)
24210 + pax_open_kernel();
24211 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
24212 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
24213 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
24214 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
24215 + pax_close_kernel();
24217 local_irq_restore(flags);
24219 switch (return_code) {
24221 - return address + entry;
24222 - case 0x80: /* Not present */
24223 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
24225 - default: /* Shouldn't happen */
24226 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
24227 - service, return_code);
24230 + unsigned char flags;
24232 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
24233 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
24234 + printk(KERN_WARNING "bios32_service: not valid\n");
24237 + address = address + PAGE_OFFSET;
24238 + length += 16UL; /* some BIOSs underreport this... */
24240 + if (length >= 64*1024*1024) {
24241 + length >>= PAGE_SHIFT;
24245 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24246 + gdt = get_cpu_gdt_table(cpu);
24247 + pack_descriptor(&d, address, length, 0x9b, flags);
24248 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
24249 + pack_descriptor(&d, address, length, 0x93, flags);
24250 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
24254 + case 0x80: /* Not present */
24255 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
24257 + default: /* Shouldn't happen */
24258 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
24259 + service, return_code);
24265 unsigned long address;
24266 unsigned short segment;
24267 -} pci_indirect = { 0, __KERNEL_CS };
24268 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
24270 -static int pci_bios_present;
24271 +static int pci_bios_present __read_only;
24273 static int __devinit check_pcibios(void)
24275 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
24276 unsigned long flags, pcibios_entry;
24278 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
24279 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
24280 + pci_indirect.address = pcibios_entry;
24282 local_irq_save(flags);
24284 - "lcall *(%%edi); cld\n\t"
24285 + __asm__("movw %w6, %%ds\n\t"
24286 + "lcall *%%ss:(%%edi); cld\n\t"
24292 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
24295 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
24296 - "D" (&pci_indirect)
24297 + "D" (&pci_indirect),
24298 + "r" (__PCIBIOS_DS)
24300 local_irq_restore(flags);
24302 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24306 - __asm__("lcall *(%%esi); cld\n\t"
24307 + __asm__("movw %w6, %%ds\n\t"
24308 + "lcall *%%ss:(%%esi); cld\n\t"
24314 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24315 : "1" (PCIBIOS_READ_CONFIG_BYTE),
24318 - "S" (&pci_indirect));
24319 + "S" (&pci_indirect),
24320 + "r" (__PCIBIOS_DS));
24322 * Zero-extend the result beyond 8 bits, do not trust the
24323 * BIOS having done it:
24324 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24328 - __asm__("lcall *(%%esi); cld\n\t"
24329 + __asm__("movw %w6, %%ds\n\t"
24330 + "lcall *%%ss:(%%esi); cld\n\t"
24336 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24337 : "1" (PCIBIOS_READ_CONFIG_WORD),
24340 - "S" (&pci_indirect));
24341 + "S" (&pci_indirect),
24342 + "r" (__PCIBIOS_DS));
24344 * Zero-extend the result beyond 16 bits, do not trust the
24345 * BIOS having done it:
24346 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24350 - __asm__("lcall *(%%esi); cld\n\t"
24351 + __asm__("movw %w6, %%ds\n\t"
24352 + "lcall *%%ss:(%%esi); cld\n\t"
24358 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24359 : "1" (PCIBIOS_READ_CONFIG_DWORD),
24362 - "S" (&pci_indirect));
24363 + "S" (&pci_indirect),
24364 + "r" (__PCIBIOS_DS));
24368 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24372 - __asm__("lcall *(%%esi); cld\n\t"
24373 + __asm__("movw %w6, %%ds\n\t"
24374 + "lcall *%%ss:(%%esi); cld\n\t"
24380 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24384 - "S" (&pci_indirect));
24385 + "S" (&pci_indirect),
24386 + "r" (__PCIBIOS_DS));
24389 - __asm__("lcall *(%%esi); cld\n\t"
24390 + __asm__("movw %w6, %%ds\n\t"
24391 + "lcall *%%ss:(%%esi); cld\n\t"
24397 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24401 - "S" (&pci_indirect));
24402 + "S" (&pci_indirect),
24403 + "r" (__PCIBIOS_DS));
24406 - __asm__("lcall *(%%esi); cld\n\t"
24407 + __asm__("movw %w6, %%ds\n\t"
24408 + "lcall *%%ss:(%%esi); cld\n\t"
24414 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24418 - "S" (&pci_indirect));
24419 + "S" (&pci_indirect),
24420 + "r" (__PCIBIOS_DS));
24424 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24426 DBG("PCI: Fetching IRQ routing table... ");
24427 __asm__("push %%es\n\t"
24428 + "movw %w8, %%ds\n\t"
24431 - "lcall *(%%esi); cld\n\t"
24432 + "lcall *%%ss:(%%esi); cld\n\t"
24439 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24442 "S" (&pci_indirect),
24445 + "r" (__PCIBIOS_DS)
24447 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
24449 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24453 - __asm__("lcall *(%%esi); cld\n\t"
24454 + __asm__("movw %w5, %%ds\n\t"
24455 + "lcall *%%ss:(%%esi); cld\n\t"
24461 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24462 : "0" (PCIBIOS_SET_PCI_HW_INT),
24463 "b" ((dev->bus->number << 8) | dev->devfn),
24464 "c" ((irq << 8) | (pin + 10)),
24465 - "S" (&pci_indirect));
24466 + "S" (&pci_indirect),
24467 + "r" (__PCIBIOS_DS));
24468 return !(ret & 0xff00);
24470 EXPORT_SYMBOL(pcibios_set_irq_routing);
24471 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
24472 index 40e4469..1ab536e 100644
24473 --- a/arch/x86/platform/efi/efi_32.c
24474 +++ b/arch/x86/platform/efi/efi_32.c
24475 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
24477 struct desc_ptr gdt_descr;
24479 +#ifdef CONFIG_PAX_KERNEXEC
24480 + struct desc_struct d;
24483 local_irq_save(efi_rt_eflags);
24485 load_cr3(initial_page_table);
24488 +#ifdef CONFIG_PAX_KERNEXEC
24489 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
24490 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24491 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
24492 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24495 gdt_descr.address = __pa(get_cpu_gdt_table(0));
24496 gdt_descr.size = GDT_SIZE - 1;
24497 load_gdt(&gdt_descr);
24498 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
24500 struct desc_ptr gdt_descr;
24502 +#ifdef CONFIG_PAX_KERNEXEC
24503 + struct desc_struct d;
24505 + memset(&d, 0, sizeof d);
24506 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24507 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24510 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
24511 gdt_descr.size = GDT_SIZE - 1;
24512 load_gdt(&gdt_descr);
24513 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
24514 index fbe66e6..c5c0dd2 100644
24515 --- a/arch/x86/platform/efi/efi_stub_32.S
24516 +++ b/arch/x86/platform/efi/efi_stub_32.S
24520 #include <linux/linkage.h>
24521 +#include <linux/init.h>
24522 #include <asm/page_types.h>
24523 +#include <asm/segment.h>
24526 * efi_call_phys(void *, ...) is a function with variable parameters.
24528 * service functions will comply with gcc calling convention, too.
24533 ENTRY(efi_call_phys)
24535 * 0. The function can only be called in Linux kernel. So CS has been
24536 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
24537 * The mapping of lower virtual memory has been created in prelog and
24541 - subl $__PAGE_OFFSET, %edx
24543 + movl $(__KERNEXEC_EFI_DS), %edx
24547 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
24551 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
24552 * parameter 2, ..., param n. To make things easy, we save the return
24553 * address of efi_call_phys in a global variable.
24556 - movl %edx, saved_return_addr
24557 - /* get the function pointer into ECX*/
24559 - movl %ecx, efi_rt_function_ptr
24561 - subl $__PAGE_OFFSET, %edx
24563 + popl (saved_return_addr)
24564 + popl (efi_rt_function_ptr)
24567 * 3. Clear PG bit in %CR0.
24568 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
24570 * 5. Call the physical function.
24573 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
24577 * 6. After EFI runtime service returns, control will return to
24578 * following instruction. We'd better readjust stack pointer first.
24579 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
24581 orl $0x80000000, %edx
24587 * 8. Now restore the virtual mode from flat mode by
24588 * adding EIP with PAGE_OFFSET.
24592 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
24594 + movl $(__KERNEL_DS), %edx
24600 * 9. Balance the stack. And because EAX contain the return value,
24601 * we'd better not clobber it.
24603 - leal efi_rt_function_ptr, %edx
24604 - movl (%edx), %ecx
24606 + pushl (efi_rt_function_ptr)
24609 - * 10. Push the saved return address onto the stack and return.
24610 + * 10. Return to the saved return address.
24612 - leal saved_return_addr, %edx
24613 - movl (%edx), %ecx
24616 + jmpl *(saved_return_addr)
24617 ENDPROC(efi_call_phys)
24624 efi_rt_function_ptr:
24625 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
24626 index 4c07cca..2c8427d 100644
24627 --- a/arch/x86/platform/efi/efi_stub_64.S
24628 +++ b/arch/x86/platform/efi/efi_stub_64.S
24632 #include <linux/linkage.h>
24633 +#include <asm/alternative-asm.h>
24637 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
24641 + pax_force_retaddr 0, 1
24645 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
24649 + pax_force_retaddr 0, 1
24653 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
24657 + pax_force_retaddr 0, 1
24661 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
24665 + pax_force_retaddr 0, 1
24669 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
24673 + pax_force_retaddr 0, 1
24677 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
24681 + pax_force_retaddr 0, 1
24685 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
24689 + pax_force_retaddr 0, 1
24692 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
24693 index ad4ec1c..686479e 100644
24694 --- a/arch/x86/platform/mrst/mrst.c
24695 +++ b/arch/x86/platform/mrst/mrst.c
24696 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
24697 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
24700 -static void mrst_power_off(void)
24701 +static __noreturn void mrst_power_off(void)
24703 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24704 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
24708 -static void mrst_reboot(void)
24709 +static __noreturn void mrst_reboot(void)
24711 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24712 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
24714 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
24718 /* parse all the mtimer info to a static mtimer array */
24719 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
24720 index f10c0af..3ec1f95 100644
24721 --- a/arch/x86/power/cpu.c
24722 +++ b/arch/x86/power/cpu.c
24723 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
24724 static void fix_processor_context(void)
24726 int cpu = smp_processor_id();
24727 - struct tss_struct *t = &per_cpu(init_tss, cpu);
24728 + struct tss_struct *t = init_tss + cpu;
24730 set_tss_desc(cpu, t); /*
24731 * This just modifies memory; should not be
24732 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
24735 #ifdef CONFIG_X86_64
24736 + pax_open_kernel();
24737 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
24738 + pax_close_kernel();
24740 syscall_init(); /* This sets MSR_*STAR and related */
24742 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
24743 index 5d17950..2253fc9 100644
24744 --- a/arch/x86/vdso/Makefile
24745 +++ b/arch/x86/vdso/Makefile
24746 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
24747 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
24748 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
24750 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24751 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24755 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
24756 index 468d591..8e80a0a 100644
24757 --- a/arch/x86/vdso/vdso32-setup.c
24758 +++ b/arch/x86/vdso/vdso32-setup.c
24760 #include <asm/tlbflush.h>
24761 #include <asm/vdso.h>
24762 #include <asm/proto.h>
24763 +#include <asm/mman.h>
24767 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
24768 void enable_sep_cpu(void)
24770 int cpu = get_cpu();
24771 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
24772 + struct tss_struct *tss = init_tss + cpu;
24774 if (!boot_cpu_has(X86_FEATURE_SEP)) {
24776 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
24777 gate_vma.vm_start = FIXADDR_USER_START;
24778 gate_vma.vm_end = FIXADDR_USER_END;
24779 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
24780 - gate_vma.vm_page_prot = __P101;
24781 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
24783 * Make sure the vDSO gets into every core dump.
24784 * Dumping its contents makes post-mortem fully interpretable later
24785 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24787 addr = VDSO_HIGH_BASE;
24789 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
24790 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
24791 if (IS_ERR_VALUE(addr)) {
24797 - current->mm->context.vdso = (void *)addr;
24798 + current->mm->context.vdso = addr;
24800 if (compat_uses_vma || !compat) {
24802 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24805 current_thread_info()->sysenter_return =
24806 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24807 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24811 - current->mm->context.vdso = NULL;
24812 + current->mm->context.vdso = 0;
24814 up_write(&mm->mmap_sem);
24816 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24818 const char *arch_vma_name(struct vm_area_struct *vma)
24820 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24821 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24824 +#ifdef CONFIG_PAX_SEGMEXEC
24825 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24832 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24833 * Check to see if the corresponding task was created in compat vdso
24836 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24837 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24841 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
24842 index 153407c..611cba9 100644
24843 --- a/arch/x86/vdso/vma.c
24844 +++ b/arch/x86/vdso/vma.c
24846 #include <asm/vdso.h>
24847 #include <asm/page.h>
24849 -unsigned int __read_mostly vdso_enabled = 1;
24851 extern char vdso_start[], vdso_end[];
24852 extern unsigned short vdso_sync_cpuid;
24854 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24855 * unaligned here as a result of stack start randomization.
24857 addr = PAGE_ALIGN(addr);
24858 - addr = align_addr(addr, NULL, ALIGN_VDSO);
24862 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24863 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24865 struct mm_struct *mm = current->mm;
24866 - unsigned long addr;
24867 + unsigned long addr = 0;
24870 - if (!vdso_enabled)
24873 down_write(&mm->mmap_sem);
24875 +#ifdef CONFIG_PAX_RANDMMAP
24876 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24879 addr = vdso_addr(mm->start_stack, vdso_size);
24880 + addr = align_addr(addr, NULL, ALIGN_VDSO);
24881 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
24882 if (IS_ERR_VALUE(addr)) {
24887 - current->mm->context.vdso = (void *)addr;
24888 + mm->context.vdso = addr;
24890 ret = install_special_mapping(mm, addr, vdso_size,
24892 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
24896 - current->mm->context.vdso = NULL;
24901 + mm->context.vdso = 0;
24904 up_write(&mm->mmap_sem);
24908 -static __init int vdso_setup(char *s)
24910 - vdso_enabled = simple_strtoul(s, NULL, 0);
24913 -__setup("vdso=", vdso_setup);
24914 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
24915 index 1f92865..c843b20 100644
24916 --- a/arch/x86/xen/enlighten.c
24917 +++ b/arch/x86/xen/enlighten.c
24918 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24920 struct shared_info xen_dummy_shared_info;
24922 -void *xen_initial_gdt;
24924 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24925 __read_mostly int xen_have_vector_callback;
24926 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24927 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
24931 -static void xen_reboot(int reason)
24932 +static __noreturn void xen_reboot(int reason)
24934 struct sched_shutdown r = { .reason = reason };
24936 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
24940 -static void xen_restart(char *msg)
24941 +static __noreturn void xen_restart(char *msg)
24943 xen_reboot(SHUTDOWN_reboot);
24946 -static void xen_emergency_restart(void)
24947 +static __noreturn void xen_emergency_restart(void)
24949 xen_reboot(SHUTDOWN_reboot);
24952 -static void xen_machine_halt(void)
24953 +static __noreturn void xen_machine_halt(void)
24955 xen_reboot(SHUTDOWN_poweroff);
24957 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
24958 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24960 /* Work out if we support NX */
24961 - x86_configure_nx();
24962 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24963 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24964 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24967 + __supported_pte_mask |= _PAGE_NX;
24968 + rdmsr(MSR_EFER, l, h);
24970 + wrmsr(MSR_EFER, l, h);
24974 xen_setup_features();
24976 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
24978 machine_ops = xen_machine_ops;
24981 - * The only reliable way to retain the initial address of the
24982 - * percpu gdt_page is to remember it here, so we can go and
24983 - * mark it RW later, when the initial percpu area is freed.
24985 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24989 #ifdef CONFIG_ACPI_NUMA
24990 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
24991 index 87f6673..e2555a6 100644
24992 --- a/arch/x86/xen/mmu.c
24993 +++ b/arch/x86/xen/mmu.c
24994 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24995 convert_pfn_mfn(init_level4_pgt);
24996 convert_pfn_mfn(level3_ident_pgt);
24997 convert_pfn_mfn(level3_kernel_pgt);
24998 + convert_pfn_mfn(level3_vmalloc_start_pgt);
24999 + convert_pfn_mfn(level3_vmalloc_end_pgt);
25000 + convert_pfn_mfn(level3_vmemmap_pgt);
25002 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
25003 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
25004 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
25005 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
25006 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
25007 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
25008 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
25009 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
25010 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
25011 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
25012 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
25013 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
25014 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
25016 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
25017 pv_mmu_ops.set_pud = xen_set_pud;
25018 #if PAGETABLE_LEVELS == 4
25019 pv_mmu_ops.set_pgd = xen_set_pgd;
25020 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
25023 /* This will work as long as patching hasn't happened yet
25024 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
25025 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
25026 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
25027 .set_pgd = xen_set_pgd_hyper,
25028 + .set_pgd_batched = xen_set_pgd_hyper,
25030 .alloc_pud = xen_alloc_pmd_init,
25031 .release_pud = xen_release_pmd_init,
25032 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
25033 index 041d4fe..7666b7e 100644
25034 --- a/arch/x86/xen/smp.c
25035 +++ b/arch/x86/xen/smp.c
25036 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
25038 BUG_ON(smp_processor_id() != 0);
25039 native_smp_prepare_boot_cpu();
25041 - /* We've switched to the "real" per-cpu gdt, so make sure the
25042 - old memory can be recycled */
25043 - make_lowmem_page_readwrite(xen_initial_gdt);
25045 xen_filter_cpu_maps();
25046 xen_setup_vcpu_info_placement();
25048 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
25049 gdt = get_cpu_gdt_table(cpu);
25051 ctxt->flags = VGCF_IN_KERNEL;
25052 - ctxt->user_regs.ds = __USER_DS;
25053 - ctxt->user_regs.es = __USER_DS;
25054 + ctxt->user_regs.ds = __KERNEL_DS;
25055 + ctxt->user_regs.es = __KERNEL_DS;
25056 ctxt->user_regs.ss = __KERNEL_DS;
25057 #ifdef CONFIG_X86_32
25058 ctxt->user_regs.fs = __KERNEL_PERCPU;
25059 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
25060 + savesegment(gs, ctxt->user_regs.gs);
25062 ctxt->gs_base_kernel = per_cpu_offset(cpu);
25064 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
25067 per_cpu(current_task, cpu) = idle;
25068 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
25069 #ifdef CONFIG_X86_32
25072 clear_tsk_thread_flag(idle, TIF_FORK);
25073 - per_cpu(kernel_stack, cpu) =
25074 - (unsigned long)task_stack_page(idle) -
25075 - KERNEL_STACK_OFFSET + THREAD_SIZE;
25076 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25078 xen_setup_runstate_info(cpu);
25079 xen_setup_timer(cpu);
25080 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
25081 index b040b0e..8cc4fe0 100644
25082 --- a/arch/x86/xen/xen-asm_32.S
25083 +++ b/arch/x86/xen/xen-asm_32.S
25084 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
25085 ESP_OFFSET=4 # bytes pushed onto stack
25088 - * Store vcpu_info pointer for easy access. Do it this way to
25089 - * avoid having to reload %fs
25090 + * Store vcpu_info pointer for easy access.
25093 - GET_THREAD_INFO(%eax)
25094 - movl TI_cpu(%eax), %eax
25095 - movl __per_cpu_offset(,%eax,4), %eax
25096 - mov xen_vcpu(%eax), %eax
25098 + mov $(__KERNEL_PERCPU), %eax
25100 + mov PER_CPU_VAR(xen_vcpu), %eax
25103 movl xen_vcpu, %eax
25105 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
25106 index aaa7291..3f77960 100644
25107 --- a/arch/x86/xen/xen-head.S
25108 +++ b/arch/x86/xen/xen-head.S
25109 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
25110 #ifdef CONFIG_X86_32
25111 mov %esi,xen_start_info
25112 mov $init_thread_union+THREAD_SIZE,%esp
25114 + movl $cpu_gdt_table,%edi
25115 + movl $__per_cpu_load,%eax
25116 + movw %ax,__KERNEL_PERCPU + 2(%edi)
25118 + movb %al,__KERNEL_PERCPU + 4(%edi)
25119 + movb %ah,__KERNEL_PERCPU + 7(%edi)
25120 + movl $__per_cpu_end - 1,%eax
25121 + subl $__per_cpu_start,%eax
25122 + movw %ax,__KERNEL_PERCPU + 0(%edi)
25125 mov %rsi,xen_start_info
25126 mov $init_thread_union+THREAD_SIZE,%rsp
25127 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
25128 index b095739..8c17bcd 100644
25129 --- a/arch/x86/xen/xen-ops.h
25130 +++ b/arch/x86/xen/xen-ops.h
25132 extern const char xen_hypervisor_callback[];
25133 extern const char xen_failsafe_callback[];
25135 -extern void *xen_initial_gdt;
25138 void xen_copy_trap_info(struct trap_info *traps);
25140 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
25141 index 58916af..9cb880b 100644
25142 --- a/block/blk-iopoll.c
25143 +++ b/block/blk-iopoll.c
25144 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
25146 EXPORT_SYMBOL(blk_iopoll_complete);
25148 -static void blk_iopoll_softirq(struct softirq_action *h)
25149 +static void blk_iopoll_softirq(void)
25151 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
25152 int rearm = 0, budget = blk_iopoll_budget;
25153 diff --git a/block/blk-map.c b/block/blk-map.c
25154 index 623e1cd..ca1e109 100644
25155 --- a/block/blk-map.c
25156 +++ b/block/blk-map.c
25157 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
25161 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
25162 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
25164 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
25166 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
25167 index 1366a89..e17f54b 100644
25168 --- a/block/blk-softirq.c
25169 +++ b/block/blk-softirq.c
25170 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
25171 * Softirq action handler - move entries to local list and loop over them
25172 * while passing them to the queue registered handler.
25174 -static void blk_done_softirq(struct softirq_action *h)
25175 +static void blk_done_softirq(void)
25177 struct list_head *cpu_list, local_list;
25179 diff --git a/block/bsg.c b/block/bsg.c
25180 index 702f131..37808bf 100644
25183 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
25184 struct sg_io_v4 *hdr, struct bsg_device *bd,
25185 fmode_t has_write_perm)
25187 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25188 + unsigned char *cmdptr;
25190 if (hdr->request_len > BLK_MAX_CDB) {
25191 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
25195 + cmdptr = rq->cmd;
25199 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
25200 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
25204 + if (cmdptr != rq->cmd)
25205 + memcpy(rq->cmd, cmdptr, hdr->request_len);
25207 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
25208 if (blk_verify_command(rq->cmd, has_write_perm))
25210 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
25211 index 7b72502..646105c 100644
25212 --- a/block/compat_ioctl.c
25213 +++ b/block/compat_ioctl.c
25214 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
25215 err |= __get_user(f->spec1, &uf->spec1);
25216 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
25217 err |= __get_user(name, &uf->name);
25218 - f->name = compat_ptr(name);
25219 + f->name = (void __force_kernel *)compat_ptr(name);
25223 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
25224 index 688be8a..8a37d98 100644
25225 --- a/block/scsi_ioctl.c
25226 +++ b/block/scsi_ioctl.c
25227 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
25228 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
25229 struct sg_io_hdr *hdr, fmode_t mode)
25231 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
25232 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25233 + unsigned char *cmdptr;
25235 + if (rq->cmd != rq->__cmd)
25236 + cmdptr = rq->cmd;
25240 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
25243 + if (cmdptr != rq->cmd)
25244 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
25246 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
25249 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
25251 unsigned int in_len, out_len, bytes, opcode, cmdlen;
25252 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
25253 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25254 + unsigned char *cmdptr;
25258 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
25261 rq->cmd_len = cmdlen;
25262 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
25264 + if (rq->cmd != rq->__cmd)
25265 + cmdptr = rq->cmd;
25269 + if (copy_from_user(cmdptr, sic->data, cmdlen))
25272 + if (rq->cmd != cmdptr)
25273 + memcpy(rq->cmd, cmdptr, cmdlen);
25275 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
25278 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
25279 index 671d4d6..5f24030 100644
25280 --- a/crypto/cryptd.c
25281 +++ b/crypto/cryptd.c
25282 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
25284 struct cryptd_blkcipher_request_ctx {
25285 crypto_completion_t complete;
25289 struct cryptd_hash_ctx {
25290 struct crypto_shash *child;
25291 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
25293 struct cryptd_aead_request_ctx {
25294 crypto_completion_t complete;
25298 static void cryptd_queue_worker(struct work_struct *work);
25300 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
25301 index 5d41894..22021e4 100644
25302 --- a/drivers/acpi/apei/cper.c
25303 +++ b/drivers/acpi/apei/cper.c
25304 @@ -38,12 +38,12 @@
25306 u64 cper_next_record_id(void)
25308 - static atomic64_t seq;
25309 + static atomic64_unchecked_t seq;
25311 - if (!atomic64_read(&seq))
25312 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
25313 + if (!atomic64_read_unchecked(&seq))
25314 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
25316 - return atomic64_inc_return(&seq);
25317 + return atomic64_inc_return_unchecked(&seq);
25319 EXPORT_SYMBOL_GPL(cper_next_record_id);
25321 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
25322 index 6c47ae9..abfdd63 100644
25323 --- a/drivers/acpi/ec_sys.c
25324 +++ b/drivers/acpi/ec_sys.c
25326 #include <linux/acpi.h>
25327 #include <linux/debugfs.h>
25328 #include <linux/module.h>
25329 +#include <linux/uaccess.h>
25330 #include "internal.h"
25332 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
25333 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25334 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
25336 unsigned int size = EC_SPACE_SIZE;
25337 - u8 *data = (u8 *) buf;
25339 loff_t init_off = *off;
25342 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25346 - err = ec_read(*off, &data[*off - init_off]);
25347 + err = ec_read(*off, &data);
25350 + if (put_user(data, &buf[*off - init_off]))
25355 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25357 unsigned int size = count;
25358 loff_t init_off = *off;
25359 - u8 *data = (u8 *) buf;
25362 if (*off >= EC_SPACE_SIZE)
25363 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25367 - u8 byte_write = data[*off - init_off];
25369 + if (get_user(byte_write, &buf[*off - init_off]))
25371 err = ec_write(*off, byte_write);
25374 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
25375 index 251c7b62..000462d 100644
25376 --- a/drivers/acpi/proc.c
25377 +++ b/drivers/acpi/proc.c
25378 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
25379 size_t count, loff_t * ppos)
25381 struct list_head *node, *next;
25383 - char str[5] = "";
25384 - unsigned int len = count;
25385 + char strbuf[5] = {0};
25392 + if (copy_from_user(strbuf, buffer, count))
25395 - if (copy_from_user(strbuf, buffer, len))
25397 - strbuf[len] = '\0';
25398 - sscanf(strbuf, "%s", str);
25399 + strbuf[count] = '\0';
25401 mutex_lock(&acpi_device_lock);
25402 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25403 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
25404 if (!dev->wakeup.flags.valid)
25407 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25408 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25409 if (device_can_wakeup(&dev->dev)) {
25410 bool enable = !device_may_wakeup(&dev->dev);
25411 device_set_wakeup_enable(&dev->dev, enable);
25412 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
25413 index 9d7bc9f..a6fc091 100644
25414 --- a/drivers/acpi/processor_driver.c
25415 +++ b/drivers/acpi/processor_driver.c
25416 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
25420 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25421 + BUG_ON(pr->id >= nr_cpu_ids);
25425 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
25426 index c04ad68..0b99473 100644
25427 --- a/drivers/ata/libata-core.c
25428 +++ b/drivers/ata/libata-core.c
25429 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
25430 struct ata_port *ap;
25433 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25434 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25438 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
25439 struct ata_port *ap;
25440 struct ata_link *link;
25442 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25443 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25444 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25446 link = qc->dev->link;
25447 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25451 + pax_open_kernel();
25453 for (cur = ops->inherits; cur; cur = cur->inherits) {
25454 void **inherit = (void **)cur;
25455 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25459 - ops->inherits = NULL;
25460 + *(struct ata_port_operations **)&ops->inherits = NULL;
25462 + pax_close_kernel();
25463 spin_unlock(&lock);
25466 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
25467 index e8574bb..f9f6a72 100644
25468 --- a/drivers/ata/pata_arasan_cf.c
25469 +++ b/drivers/ata/pata_arasan_cf.c
25470 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
25471 /* Handle platform specific quirks */
25472 if (pdata->quirk) {
25473 if (pdata->quirk & CF_BROKEN_PIO) {
25474 - ap->ops->set_piomode = NULL;
25475 + pax_open_kernel();
25476 + *(void **)&ap->ops->set_piomode = NULL;
25477 + pax_close_kernel();
25480 if (pdata->quirk & CF_BROKEN_MWDMA)
25481 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
25482 index f9b983a..887b9d8 100644
25483 --- a/drivers/atm/adummy.c
25484 +++ b/drivers/atm/adummy.c
25485 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
25486 vcc->pop(vcc, skb);
25488 dev_kfree_skb_any(skb);
25489 - atomic_inc(&vcc->stats->tx);
25490 + atomic_inc_unchecked(&vcc->stats->tx);
25494 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
25495 index f8f41e0..1f987dd 100644
25496 --- a/drivers/atm/ambassador.c
25497 +++ b/drivers/atm/ambassador.c
25498 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
25499 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25502 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25503 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25505 // free the descriptor
25507 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25508 dump_skb ("<<<", vc, skb);
25511 - atomic_inc(&atm_vcc->stats->rx);
25512 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25513 __net_timestamp(skb);
25514 // end of our responsibility
25515 atm_vcc->push (atm_vcc, skb);
25516 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25518 PRINTK (KERN_INFO, "dropped over-size frame");
25519 // should we count this?
25520 - atomic_inc(&atm_vcc->stats->rx_drop);
25521 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25525 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
25528 if (check_area (skb->data, skb->len)) {
25529 - atomic_inc(&atm_vcc->stats->tx_err);
25530 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25531 return -ENOMEM; // ?
25534 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
25535 index b22d71c..d6e1049 100644
25536 --- a/drivers/atm/atmtcp.c
25537 +++ b/drivers/atm/atmtcp.c
25538 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25539 if (vcc->pop) vcc->pop(vcc,skb);
25540 else dev_kfree_skb(skb);
25541 if (dev_data) return 0;
25542 - atomic_inc(&vcc->stats->tx_err);
25543 + atomic_inc_unchecked(&vcc->stats->tx_err);
25546 size = skb->len+sizeof(struct atmtcp_hdr);
25547 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25549 if (vcc->pop) vcc->pop(vcc,skb);
25550 else dev_kfree_skb(skb);
25551 - atomic_inc(&vcc->stats->tx_err);
25552 + atomic_inc_unchecked(&vcc->stats->tx_err);
25555 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
25556 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25557 if (vcc->pop) vcc->pop(vcc,skb);
25558 else dev_kfree_skb(skb);
25559 out_vcc->push(out_vcc,new_skb);
25560 - atomic_inc(&vcc->stats->tx);
25561 - atomic_inc(&out_vcc->stats->rx);
25562 + atomic_inc_unchecked(&vcc->stats->tx);
25563 + atomic_inc_unchecked(&out_vcc->stats->rx);
25567 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25568 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
25569 read_unlock(&vcc_sklist_lock);
25571 - atomic_inc(&vcc->stats->tx_err);
25572 + atomic_inc_unchecked(&vcc->stats->tx_err);
25575 skb_pull(skb,sizeof(struct atmtcp_hdr));
25576 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25577 __net_timestamp(new_skb);
25578 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
25579 out_vcc->push(out_vcc,new_skb);
25580 - atomic_inc(&vcc->stats->tx);
25581 - atomic_inc(&out_vcc->stats->rx);
25582 + atomic_inc_unchecked(&vcc->stats->tx);
25583 + atomic_inc_unchecked(&out_vcc->stats->rx);
25585 if (vcc->pop) vcc->pop(vcc,skb);
25586 else dev_kfree_skb(skb);
25587 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
25588 index 956e9ac..133516d 100644
25589 --- a/drivers/atm/eni.c
25590 +++ b/drivers/atm/eni.c
25591 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
25592 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
25595 - atomic_inc(&vcc->stats->rx_err);
25596 + atomic_inc_unchecked(&vcc->stats->rx_err);
25599 length = ATM_CELL_SIZE-1; /* no HEC */
25600 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25604 - atomic_inc(&vcc->stats->rx_err);
25605 + atomic_inc_unchecked(&vcc->stats->rx_err);
25608 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25609 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25610 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25611 vcc->dev->number,vcc->vci,length,size << 2,descr);
25613 - atomic_inc(&vcc->stats->rx_err);
25614 + atomic_inc_unchecked(&vcc->stats->rx_err);
25617 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25618 @@ -771,7 +771,7 @@ rx_dequeued++;
25619 vcc->push(vcc,skb);
25622 - atomic_inc(&vcc->stats->rx);
25623 + atomic_inc_unchecked(&vcc->stats->rx);
25625 wake_up(&eni_dev->rx_wait);
25627 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
25629 if (vcc->pop) vcc->pop(vcc,skb);
25630 else dev_kfree_skb_irq(skb);
25631 - atomic_inc(&vcc->stats->tx);
25632 + atomic_inc_unchecked(&vcc->stats->tx);
25633 wake_up(&eni_dev->tx_wait);
25636 @@ -1569,7 +1569,7 @@ tx_complete++;
25637 /*--------------------------------- entries ---------------------------------*/
25640 -static const char *media_name[] __devinitdata = {
25641 +static const char *media_name[] __devinitconst = {
25642 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
25643 "UTP", "05?", "06?", "07?", /* 4- 7 */
25644 "TAXI","09?", "10?", "11?", /* 8-11 */
25645 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
25646 index 5072f8a..fa52520d 100644
25647 --- a/drivers/atm/firestream.c
25648 +++ b/drivers/atm/firestream.c
25649 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
25653 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25654 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25656 fs_dprintk (FS_DEBUG_TXMEM, "i");
25657 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25658 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25660 skb_put (skb, qe->p1 & 0xffff);
25661 ATM_SKB(skb)->vcc = atm_vcc;
25662 - atomic_inc(&atm_vcc->stats->rx);
25663 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25664 __net_timestamp(skb);
25665 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25666 atm_vcc->push (atm_vcc, skb);
25667 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25671 - atomic_inc(&atm_vcc->stats->rx_drop);
25672 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25674 case 0x1f: /* Reassembly abort: no buffers. */
25675 /* Silently increment error counter. */
25677 - atomic_inc(&atm_vcc->stats->rx_drop);
25678 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25680 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25681 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25682 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
25683 index 361f5ae..7fc552d 100644
25684 --- a/drivers/atm/fore200e.c
25685 +++ b/drivers/atm/fore200e.c
25686 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
25688 /* check error condition */
25689 if (*entry->status & STATUS_ERROR)
25690 - atomic_inc(&vcc->stats->tx_err);
25691 + atomic_inc_unchecked(&vcc->stats->tx_err);
25693 - atomic_inc(&vcc->stats->tx);
25694 + atomic_inc_unchecked(&vcc->stats->tx);
25698 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25700 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25702 - atomic_inc(&vcc->stats->rx_drop);
25703 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25707 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25709 dev_kfree_skb_any(skb);
25711 - atomic_inc(&vcc->stats->rx_drop);
25712 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25716 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25718 vcc->push(vcc, skb);
25719 - atomic_inc(&vcc->stats->rx);
25720 + atomic_inc_unchecked(&vcc->stats->rx);
25722 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25724 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
25725 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25726 fore200e->atm_dev->number,
25727 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25728 - atomic_inc(&vcc->stats->rx_err);
25729 + atomic_inc_unchecked(&vcc->stats->rx_err);
25733 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
25737 - atomic_inc(&vcc->stats->tx_err);
25738 + atomic_inc_unchecked(&vcc->stats->tx_err);
25740 fore200e->tx_sat++;
25741 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25742 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
25743 index 9a51df4..f3bb5f8 100644
25744 --- a/drivers/atm/he.c
25745 +++ b/drivers/atm/he.c
25746 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25748 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25749 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25750 - atomic_inc(&vcc->stats->rx_drop);
25751 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25752 goto return_host_buffers;
25755 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25756 RBRQ_LEN_ERR(he_dev->rbrq_head)
25758 vcc->vpi, vcc->vci);
25759 - atomic_inc(&vcc->stats->rx_err);
25760 + atomic_inc_unchecked(&vcc->stats->rx_err);
25761 goto return_host_buffers;
25764 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25765 vcc->push(vcc, skb);
25766 spin_lock(&he_dev->global_lock);
25768 - atomic_inc(&vcc->stats->rx);
25769 + atomic_inc_unchecked(&vcc->stats->rx);
25771 return_host_buffers:
25773 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
25774 tpd->vcc->pop(tpd->vcc, tpd->skb);
25776 dev_kfree_skb_any(tpd->skb);
25777 - atomic_inc(&tpd->vcc->stats->tx_err);
25778 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25780 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25782 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25783 vcc->pop(vcc, skb);
25785 dev_kfree_skb_any(skb);
25786 - atomic_inc(&vcc->stats->tx_err);
25787 + atomic_inc_unchecked(&vcc->stats->tx_err);
25791 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25792 vcc->pop(vcc, skb);
25794 dev_kfree_skb_any(skb);
25795 - atomic_inc(&vcc->stats->tx_err);
25796 + atomic_inc_unchecked(&vcc->stats->tx_err);
25800 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25801 vcc->pop(vcc, skb);
25803 dev_kfree_skb_any(skb);
25804 - atomic_inc(&vcc->stats->tx_err);
25805 + atomic_inc_unchecked(&vcc->stats->tx_err);
25806 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25809 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25810 vcc->pop(vcc, skb);
25812 dev_kfree_skb_any(skb);
25813 - atomic_inc(&vcc->stats->tx_err);
25814 + atomic_inc_unchecked(&vcc->stats->tx_err);
25815 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25818 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25819 __enqueue_tpd(he_dev, tpd, cid);
25820 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25822 - atomic_inc(&vcc->stats->tx);
25823 + atomic_inc_unchecked(&vcc->stats->tx);
25827 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
25828 index b812103..e391a49 100644
25829 --- a/drivers/atm/horizon.c
25830 +++ b/drivers/atm/horizon.c
25831 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
25833 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25835 - atomic_inc(&vcc->stats->rx);
25836 + atomic_inc_unchecked(&vcc->stats->rx);
25837 __net_timestamp(skb);
25838 // end of our responsibility
25839 vcc->push (vcc, skb);
25840 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
25841 dev->tx_iovec = NULL;
25844 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25845 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25848 hrz_kfree_skb (skb);
25849 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
25850 index 1c05212..c28e200 100644
25851 --- a/drivers/atm/idt77252.c
25852 +++ b/drivers/atm/idt77252.c
25853 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
25855 dev_kfree_skb(skb);
25857 - atomic_inc(&vcc->stats->tx);
25858 + atomic_inc_unchecked(&vcc->stats->tx);
25861 atomic_dec(&scq->used);
25862 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25863 if ((sb = dev_alloc_skb(64)) == NULL) {
25864 printk("%s: Can't allocate buffers for aal0.\n",
25866 - atomic_add(i, &vcc->stats->rx_drop);
25867 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25870 if (!atm_charge(vcc, sb->truesize)) {
25871 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25873 - atomic_add(i - 1, &vcc->stats->rx_drop);
25874 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25878 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25879 ATM_SKB(sb)->vcc = vcc;
25880 __net_timestamp(sb);
25881 vcc->push(vcc, sb);
25882 - atomic_inc(&vcc->stats->rx);
25883 + atomic_inc_unchecked(&vcc->stats->rx);
25885 cell += ATM_CELL_PAYLOAD;
25887 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25889 card->name, len, rpp->len, readl(SAR_REG_CDC));
25890 recycle_rx_pool_skb(card, rpp);
25891 - atomic_inc(&vcc->stats->rx_err);
25892 + atomic_inc_unchecked(&vcc->stats->rx_err);
25895 if (stat & SAR_RSQE_CRC) {
25896 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25897 recycle_rx_pool_skb(card, rpp);
25898 - atomic_inc(&vcc->stats->rx_err);
25899 + atomic_inc_unchecked(&vcc->stats->rx_err);
25902 if (skb_queue_len(&rpp->queue) > 1) {
25903 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25904 RXPRINTK("%s: Can't alloc RX skb.\n",
25906 recycle_rx_pool_skb(card, rpp);
25907 - atomic_inc(&vcc->stats->rx_err);
25908 + atomic_inc_unchecked(&vcc->stats->rx_err);
25911 if (!atm_charge(vcc, skb->truesize)) {
25912 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25913 __net_timestamp(skb);
25915 vcc->push(vcc, skb);
25916 - atomic_inc(&vcc->stats->rx);
25917 + atomic_inc_unchecked(&vcc->stats->rx);
25921 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25922 __net_timestamp(skb);
25924 vcc->push(vcc, skb);
25925 - atomic_inc(&vcc->stats->rx);
25926 + atomic_inc_unchecked(&vcc->stats->rx);
25928 if (skb->truesize > SAR_FB_SIZE_3)
25929 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25930 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
25931 if (vcc->qos.aal != ATM_AAL0) {
25932 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25933 card->name, vpi, vci);
25934 - atomic_inc(&vcc->stats->rx_drop);
25935 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25939 if ((sb = dev_alloc_skb(64)) == NULL) {
25940 printk("%s: Can't allocate buffers for AAL0.\n",
25942 - atomic_inc(&vcc->stats->rx_err);
25943 + atomic_inc_unchecked(&vcc->stats->rx_err);
25947 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
25948 ATM_SKB(sb)->vcc = vcc;
25949 __net_timestamp(sb);
25950 vcc->push(vcc, sb);
25951 - atomic_inc(&vcc->stats->rx);
25952 + atomic_inc_unchecked(&vcc->stats->rx);
25955 skb_pull(queue, 64);
25956 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25959 printk("%s: NULL connection in send().\n", card->name);
25960 - atomic_inc(&vcc->stats->tx_err);
25961 + atomic_inc_unchecked(&vcc->stats->tx_err);
25962 dev_kfree_skb(skb);
25965 if (!test_bit(VCF_TX, &vc->flags)) {
25966 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25967 - atomic_inc(&vcc->stats->tx_err);
25968 + atomic_inc_unchecked(&vcc->stats->tx_err);
25969 dev_kfree_skb(skb);
25972 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25975 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25976 - atomic_inc(&vcc->stats->tx_err);
25977 + atomic_inc_unchecked(&vcc->stats->tx_err);
25978 dev_kfree_skb(skb);
25982 if (skb_shinfo(skb)->nr_frags != 0) {
25983 printk("%s: No scatter-gather yet.\n", card->name);
25984 - atomic_inc(&vcc->stats->tx_err);
25985 + atomic_inc_unchecked(&vcc->stats->tx_err);
25986 dev_kfree_skb(skb);
25989 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25991 err = queue_skb(card, vc, skb, oam);
25993 - atomic_inc(&vcc->stats->tx_err);
25994 + atomic_inc_unchecked(&vcc->stats->tx_err);
25995 dev_kfree_skb(skb);
25998 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
25999 skb = dev_alloc_skb(64);
26001 printk("%s: Out of memory in send_oam().\n", card->name);
26002 - atomic_inc(&vcc->stats->tx_err);
26003 + atomic_inc_unchecked(&vcc->stats->tx_err);
26006 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
26007 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
26008 index 3d0c2b0..45441fa 100644
26009 --- a/drivers/atm/iphase.c
26010 +++ b/drivers/atm/iphase.c
26011 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
26012 status = (u_short) (buf_desc_ptr->desc_mode);
26013 if (status & (RX_CER | RX_PTE | RX_OFL))
26015 - atomic_inc(&vcc->stats->rx_err);
26016 + atomic_inc_unchecked(&vcc->stats->rx_err);
26017 IF_ERR(printk("IA: bad packet, dropping it");)
26018 if (status & RX_CER) {
26019 IF_ERR(printk(" cause: packet CRC error\n");)
26020 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
26021 len = dma_addr - buf_addr;
26022 if (len > iadev->rx_buf_sz) {
26023 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
26024 - atomic_inc(&vcc->stats->rx_err);
26025 + atomic_inc_unchecked(&vcc->stats->rx_err);
26026 goto out_free_desc;
26029 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
26030 ia_vcc = INPH_IA_VCC(vcc);
26031 if (ia_vcc == NULL)
26033 - atomic_inc(&vcc->stats->rx_err);
26034 + atomic_inc_unchecked(&vcc->stats->rx_err);
26035 dev_kfree_skb_any(skb);
26036 atm_return(vcc, atm_guess_pdu2truesize(len));
26038 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
26039 if ((length > iadev->rx_buf_sz) || (length >
26040 (skb->len - sizeof(struct cpcs_trailer))))
26042 - atomic_inc(&vcc->stats->rx_err);
26043 + atomic_inc_unchecked(&vcc->stats->rx_err);
26044 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
26045 length, skb->len);)
26046 dev_kfree_skb_any(skb);
26047 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
26049 IF_RX(printk("rx_dle_intr: skb push");)
26050 vcc->push(vcc,skb);
26051 - atomic_inc(&vcc->stats->rx);
26052 + atomic_inc_unchecked(&vcc->stats->rx);
26053 iadev->rx_pkt_cnt++;
26056 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
26058 struct k_sonet_stats *stats;
26059 stats = &PRIV(_ia_dev[board])->sonet_stats;
26060 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
26061 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
26062 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
26063 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
26064 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
26065 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
26066 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
26067 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
26068 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
26069 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
26070 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26071 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26072 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26073 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26074 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26075 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26076 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26077 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26079 ia_cmds.status = 0;
26081 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
26082 if ((desc == 0) || (desc > iadev->num_tx_desc))
26084 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26085 - atomic_inc(&vcc->stats->tx);
26086 + atomic_inc_unchecked(&vcc->stats->tx);
26088 vcc->pop(vcc, skb);
26090 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
26091 ATM_DESC(skb) = vcc->vci;
26092 skb_queue_tail(&iadev->tx_dma_q, skb);
26094 - atomic_inc(&vcc->stats->tx);
26095 + atomic_inc_unchecked(&vcc->stats->tx);
26096 iadev->tx_pkt_cnt++;
26097 /* Increment transaction counter */
26098 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
26101 /* add flow control logic */
26102 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
26103 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
26104 if (iavcc->vc_desc_cnt > 10) {
26105 vcc->tx_quota = vcc->tx_quota * 3 / 4;
26106 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
26107 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
26108 index f556969..0da15eb 100644
26109 --- a/drivers/atm/lanai.c
26110 +++ b/drivers/atm/lanai.c
26111 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
26112 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
26113 lanai_endtx(lanai, lvcc);
26114 lanai_free_skb(lvcc->tx.atmvcc, skb);
26115 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
26116 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
26119 /* Try to fill the buffer - don't call unless there is backlog */
26120 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
26121 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
26122 __net_timestamp(skb);
26123 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
26124 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
26125 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
26127 lvcc->rx.buf.ptr = end;
26128 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
26129 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26130 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
26131 "vcc %d\n", lanai->number, (unsigned int) s, vci);
26132 lanai->stats.service_rxnotaal5++;
26133 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26134 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26137 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
26138 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26140 read_unlock(&vcc_sklist_lock);
26141 DPRINTK("got trashed rx pdu on vci %d\n", vci);
26142 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26143 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26144 lvcc->stats.x.aal5.service_trash++;
26145 bytes = (SERVICE_GET_END(s) * 16) -
26146 (((unsigned long) lvcc->rx.buf.ptr) -
26147 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26149 if (s & SERVICE_STREAM) {
26150 read_unlock(&vcc_sklist_lock);
26151 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26152 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26153 lvcc->stats.x.aal5.service_stream++;
26154 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
26155 "PDU on VCI %d!\n", lanai->number, vci);
26156 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26159 DPRINTK("got rx crc error on vci %d\n", vci);
26160 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26161 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26162 lvcc->stats.x.aal5.service_rxcrc++;
26163 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
26164 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
26165 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
26166 index 1c70c45..300718d 100644
26167 --- a/drivers/atm/nicstar.c
26168 +++ b/drivers/atm/nicstar.c
26169 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26170 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
26171 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
26173 - atomic_inc(&vcc->stats->tx_err);
26174 + atomic_inc_unchecked(&vcc->stats->tx_err);
26175 dev_kfree_skb_any(skb);
26178 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26180 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
26182 - atomic_inc(&vcc->stats->tx_err);
26183 + atomic_inc_unchecked(&vcc->stats->tx_err);
26184 dev_kfree_skb_any(skb);
26187 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26188 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
26189 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
26191 - atomic_inc(&vcc->stats->tx_err);
26192 + atomic_inc_unchecked(&vcc->stats->tx_err);
26193 dev_kfree_skb_any(skb);
26197 if (skb_shinfo(skb)->nr_frags != 0) {
26198 printk("nicstar%d: No scatter-gather yet.\n", card->index);
26199 - atomic_inc(&vcc->stats->tx_err);
26200 + atomic_inc_unchecked(&vcc->stats->tx_err);
26201 dev_kfree_skb_any(skb);
26204 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26207 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
26208 - atomic_inc(&vcc->stats->tx_err);
26209 + atomic_inc_unchecked(&vcc->stats->tx_err);
26210 dev_kfree_skb_any(skb);
26213 - atomic_inc(&vcc->stats->tx);
26214 + atomic_inc_unchecked(&vcc->stats->tx);
26218 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26220 ("nicstar%d: Can't allocate buffers for aal0.\n",
26222 - atomic_add(i, &vcc->stats->rx_drop);
26223 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26226 if (!atm_charge(vcc, sb->truesize)) {
26228 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
26230 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
26231 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
26232 dev_kfree_skb_any(sb);
26235 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26236 ATM_SKB(sb)->vcc = vcc;
26237 __net_timestamp(sb);
26238 vcc->push(vcc, sb);
26239 - atomic_inc(&vcc->stats->rx);
26240 + atomic_inc_unchecked(&vcc->stats->rx);
26241 cell += ATM_CELL_PAYLOAD;
26244 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26245 if (iovb == NULL) {
26246 printk("nicstar%d: Out of iovec buffers.\n",
26248 - atomic_inc(&vcc->stats->rx_drop);
26249 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26250 recycle_rx_buf(card, skb);
26253 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26254 small or large buffer itself. */
26255 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
26256 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26257 - atomic_inc(&vcc->stats->rx_err);
26258 + atomic_inc_unchecked(&vcc->stats->rx_err);
26259 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26261 NS_PRV_IOVCNT(iovb) = 0;
26262 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26263 ("nicstar%d: Expected a small buffer, and this is not one.\n",
26265 which_list(card, skb);
26266 - atomic_inc(&vcc->stats->rx_err);
26267 + atomic_inc_unchecked(&vcc->stats->rx_err);
26268 recycle_rx_buf(card, skb);
26270 recycle_iov_buf(card, iovb);
26271 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26272 ("nicstar%d: Expected a large buffer, and this is not one.\n",
26274 which_list(card, skb);
26275 - atomic_inc(&vcc->stats->rx_err);
26276 + atomic_inc_unchecked(&vcc->stats->rx_err);
26277 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26278 NS_PRV_IOVCNT(iovb));
26280 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26281 printk(" - PDU size mismatch.\n");
26284 - atomic_inc(&vcc->stats->rx_err);
26285 + atomic_inc_unchecked(&vcc->stats->rx_err);
26286 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26287 NS_PRV_IOVCNT(iovb));
26289 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26290 /* skb points to a small buffer */
26291 if (!atm_charge(vcc, skb->truesize)) {
26292 push_rxbufs(card, skb);
26293 - atomic_inc(&vcc->stats->rx_drop);
26294 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26297 dequeue_sm_buf(card, skb);
26298 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26299 ATM_SKB(skb)->vcc = vcc;
26300 __net_timestamp(skb);
26301 vcc->push(vcc, skb);
26302 - atomic_inc(&vcc->stats->rx);
26303 + atomic_inc_unchecked(&vcc->stats->rx);
26305 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
26306 struct sk_buff *sb;
26307 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26308 if (len <= NS_SMBUFSIZE) {
26309 if (!atm_charge(vcc, sb->truesize)) {
26310 push_rxbufs(card, sb);
26311 - atomic_inc(&vcc->stats->rx_drop);
26312 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26315 dequeue_sm_buf(card, sb);
26316 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26317 ATM_SKB(sb)->vcc = vcc;
26318 __net_timestamp(sb);
26319 vcc->push(vcc, sb);
26320 - atomic_inc(&vcc->stats->rx);
26321 + atomic_inc_unchecked(&vcc->stats->rx);
26324 push_rxbufs(card, skb);
26325 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26327 if (!atm_charge(vcc, skb->truesize)) {
26328 push_rxbufs(card, skb);
26329 - atomic_inc(&vcc->stats->rx_drop);
26330 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26332 dequeue_lg_buf(card, skb);
26333 #ifdef NS_USE_DESTRUCTORS
26334 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26335 ATM_SKB(skb)->vcc = vcc;
26336 __net_timestamp(skb);
26337 vcc->push(vcc, skb);
26338 - atomic_inc(&vcc->stats->rx);
26339 + atomic_inc_unchecked(&vcc->stats->rx);
26342 push_rxbufs(card, sb);
26343 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26345 ("nicstar%d: Out of huge buffers.\n",
26347 - atomic_inc(&vcc->stats->rx_drop);
26348 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26349 recycle_iovec_rx_bufs(card,
26352 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26353 card->hbpool.count++;
26355 dev_kfree_skb_any(hb);
26356 - atomic_inc(&vcc->stats->rx_drop);
26357 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26359 /* Copy the small buffer to the huge buffer */
26360 sb = (struct sk_buff *)iov->iov_base;
26361 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26362 #endif /* NS_USE_DESTRUCTORS */
26363 __net_timestamp(hb);
26364 vcc->push(vcc, hb);
26365 - atomic_inc(&vcc->stats->rx);
26366 + atomic_inc_unchecked(&vcc->stats->rx);
26370 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
26371 index 5d1d076..12fbca4 100644
26372 --- a/drivers/atm/solos-pci.c
26373 +++ b/drivers/atm/solos-pci.c
26374 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
26376 atm_charge(vcc, skb->truesize);
26377 vcc->push(vcc, skb);
26378 - atomic_inc(&vcc->stats->rx);
26379 + atomic_inc_unchecked(&vcc->stats->rx);
26383 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
26384 vcc = SKB_CB(oldskb)->vcc;
26387 - atomic_inc(&vcc->stats->tx);
26388 + atomic_inc_unchecked(&vcc->stats->tx);
26389 solos_pop(vcc, oldskb);
26391 dev_kfree_skb_irq(oldskb);
26392 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
26393 index 90f1ccc..04c4a1e 100644
26394 --- a/drivers/atm/suni.c
26395 +++ b/drivers/atm/suni.c
26396 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26399 #define ADD_LIMITED(s,v) \
26400 - atomic_add((v),&stats->s); \
26401 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26402 + atomic_add_unchecked((v),&stats->s); \
26403 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26406 static void suni_hz(unsigned long from_timer)
26407 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
26408 index 5120a96..e2572bd 100644
26409 --- a/drivers/atm/uPD98402.c
26410 +++ b/drivers/atm/uPD98402.c
26411 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
26412 struct sonet_stats tmp;
26415 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26416 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26417 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26418 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26419 if (zero && !error) {
26420 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
26423 #define ADD_LIMITED(s,v) \
26424 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26425 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26426 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26427 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26428 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26429 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26432 static void stat_event(struct atm_dev *dev)
26433 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
26434 if (reason & uPD98402_INT_PFM) stat_event(dev);
26435 if (reason & uPD98402_INT_PCO) {
26436 (void) GET(PCOCR); /* clear interrupt cause */
26437 - atomic_add(GET(HECCT),
26438 + atomic_add_unchecked(GET(HECCT),
26439 &PRIV(dev)->sonet_stats.uncorr_hcs);
26441 if ((reason & uPD98402_INT_RFO) &&
26442 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
26443 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26444 uPD98402_INT_LOS),PIMR); /* enable them */
26445 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26446 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26447 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26448 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26449 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26450 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26451 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26455 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
26456 index d889f56..17eb71e 100644
26457 --- a/drivers/atm/zatm.c
26458 +++ b/drivers/atm/zatm.c
26459 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26462 dev_kfree_skb_irq(skb);
26463 - if (vcc) atomic_inc(&vcc->stats->rx_err);
26464 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26467 if (!atm_charge(vcc,skb->truesize)) {
26468 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26470 ATM_SKB(skb)->vcc = vcc;
26471 vcc->push(vcc,skb);
26472 - atomic_inc(&vcc->stats->rx);
26473 + atomic_inc_unchecked(&vcc->stats->rx);
26475 zout(pos & 0xffff,MTA(mbx));
26476 #if 0 /* probably a stupid idea */
26477 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
26478 skb_queue_head(&zatm_vcc->backlog,skb);
26481 - atomic_inc(&vcc->stats->tx);
26482 + atomic_inc_unchecked(&vcc->stats->tx);
26483 wake_up(&zatm_vcc->tx_wait);
26486 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
26487 index a4760e0..51283cf 100644
26488 --- a/drivers/base/devtmpfs.c
26489 +++ b/drivers/base/devtmpfs.c
26490 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
26494 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
26495 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
26497 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
26499 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
26500 index caf995f..6f76697 100644
26501 --- a/drivers/base/power/wakeup.c
26502 +++ b/drivers/base/power/wakeup.c
26503 @@ -30,14 +30,14 @@ bool events_check_enabled;
26504 * They need to be modified together atomically, so it's better to use one
26505 * atomic variable to hold them both.
26507 -static atomic_t combined_event_count = ATOMIC_INIT(0);
26508 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
26510 #define IN_PROGRESS_BITS (sizeof(int) * 4)
26511 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
26513 static void split_counters(unsigned int *cnt, unsigned int *inpr)
26515 - unsigned int comb = atomic_read(&combined_event_count);
26516 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
26518 *cnt = (comb >> IN_PROGRESS_BITS);
26519 *inpr = comb & MAX_IN_PROGRESS;
26520 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
26521 ws->last_time = ktime_get();
26523 /* Increment the counter of events in progress. */
26524 - atomic_inc(&combined_event_count);
26525 + atomic_inc_unchecked(&combined_event_count);
26529 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
26530 * Increment the counter of registered wakeup events and decrement the
26531 * couter of wakeup events in progress simultaneously.
26533 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
26534 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
26538 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
26539 index b0f553b..77b928b 100644
26540 --- a/drivers/block/cciss.c
26541 +++ b/drivers/block/cciss.c
26542 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
26546 + memset(&arg64, 0, sizeof(arg64));
26550 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
26551 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
26552 while (!list_empty(&h->reqQ)) {
26553 c = list_entry(h->reqQ.next, CommandList_struct, list);
26554 /* can't do anything if fifo is full */
26555 - if ((h->access.fifo_full(h))) {
26556 + if ((h->access->fifo_full(h))) {
26557 dev_warn(&h->pdev->dev, "fifo full\n");
26560 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
26563 /* Tell the controller execute command */
26564 - h->access.submit_command(h, c);
26565 + h->access->submit_command(h, c);
26567 /* Put job onto the completed Q */
26569 @@ -3443,17 +3445,17 @@ startio:
26571 static inline unsigned long get_next_completion(ctlr_info_t *h)
26573 - return h->access.command_completed(h);
26574 + return h->access->command_completed(h);
26577 static inline int interrupt_pending(ctlr_info_t *h)
26579 - return h->access.intr_pending(h);
26580 + return h->access->intr_pending(h);
26583 static inline long interrupt_not_for_us(ctlr_info_t *h)
26585 - return ((h->access.intr_pending(h) == 0) ||
26586 + return ((h->access->intr_pending(h) == 0) ||
26587 (h->interrupts_enabled == 0));
26590 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
26593 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
26594 - return h->access.command_completed(h);
26595 + return h->access->command_completed(h);
26597 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
26598 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
26599 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
26600 trans_support & CFGTBL_Trans_use_short_tags);
26602 /* Change the access methods to the performant access methods */
26603 - h->access = SA5_performant_access;
26604 + h->access = &SA5_performant_access;
26605 h->transMethod = CFGTBL_Trans_Performant;
26608 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
26609 if (prod_index < 0)
26611 h->product_name = products[prod_index].product_name;
26612 - h->access = *(products[prod_index].access);
26613 + h->access = products[prod_index].access;
26615 if (cciss_board_disabled(h)) {
26616 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
26617 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
26620 /* make sure the board interrupts are off */
26621 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26622 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26623 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
26626 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
26627 * fake ones to scoop up any residual completions.
26629 spin_lock_irqsave(&h->lock, flags);
26630 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26631 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26632 spin_unlock_irqrestore(&h->lock, flags);
26633 free_irq(h->intr[h->intr_mode], h);
26634 rc = cciss_request_irq(h, cciss_msix_discard_completions,
26635 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
26636 dev_info(&h->pdev->dev, "Board READY.\n");
26637 dev_info(&h->pdev->dev,
26638 "Waiting for stale completions to drain.\n");
26639 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26640 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26642 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26643 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26645 rc = controller_reset_failed(h->cfgtable);
26647 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
26648 cciss_scsi_setup(h);
26650 /* Turn the interrupts on so we can service requests */
26651 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26652 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26654 /* Get the firmware version */
26655 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
26656 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
26658 if (return_code != IO_OK)
26659 dev_warn(&h->pdev->dev, "Error flushing cache\n");
26660 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26661 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26662 free_irq(h->intr[h->intr_mode], h);
26665 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
26666 index 7fda30e..eb5dfe0 100644
26667 --- a/drivers/block/cciss.h
26668 +++ b/drivers/block/cciss.h
26669 @@ -101,7 +101,7 @@ struct ctlr_info
26670 /* information about each logical volume */
26671 drive_info_struct *drv[CISS_MAX_LUN];
26673 - struct access_method access;
26674 + struct access_method *access;
26676 /* queue and queue Info */
26677 struct list_head reqQ;
26678 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
26679 index 9125bbe..eede5c8 100644
26680 --- a/drivers/block/cpqarray.c
26681 +++ b/drivers/block/cpqarray.c
26682 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26683 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
26686 - hba[i]->access.set_intr_mask(hba[i], 0);
26687 + hba[i]->access->set_intr_mask(hba[i], 0);
26688 if (request_irq(hba[i]->intr, do_ida_intr,
26689 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
26691 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26692 add_timer(&hba[i]->timer);
26694 /* Enable IRQ now that spinlock and rate limit timer are set up */
26695 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26696 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26698 for(j=0; j<NWD; j++) {
26699 struct gendisk *disk = ida_gendisk[i][j];
26700 @@ -694,7 +694,7 @@ DBGINFO(
26701 for(i=0; i<NR_PRODUCTS; i++) {
26702 if (board_id == products[i].board_id) {
26703 c->product_name = products[i].product_name;
26704 - c->access = *(products[i].access);
26705 + c->access = products[i].access;
26709 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
26710 hba[ctlr]->intr = intr;
26711 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
26712 hba[ctlr]->product_name = products[j].product_name;
26713 - hba[ctlr]->access = *(products[j].access);
26714 + hba[ctlr]->access = products[j].access;
26715 hba[ctlr]->ctlr = ctlr;
26716 hba[ctlr]->board_id = board_id;
26717 hba[ctlr]->pci_dev = NULL; /* not PCI */
26718 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
26720 while((c = h->reqQ) != NULL) {
26721 /* Can't do anything if we're busy */
26722 - if (h->access.fifo_full(h) == 0)
26723 + if (h->access->fifo_full(h) == 0)
26726 /* Get the first entry from the request Q */
26727 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
26730 /* Tell the controller to do our bidding */
26731 - h->access.submit_command(h, c);
26732 + h->access->submit_command(h, c);
26734 /* Get onto the completion Q */
26736 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26737 unsigned long flags;
26740 - istat = h->access.intr_pending(h);
26741 + istat = h->access->intr_pending(h);
26742 /* Is this interrupt for us? */
26745 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26747 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
26748 if (istat & FIFO_NOT_EMPTY) {
26749 - while((a = h->access.command_completed(h))) {
26750 + while((a = h->access->command_completed(h))) {
26752 if ((c = h->cmpQ) == NULL)
26754 @@ -1449,11 +1449,11 @@ static int sendcmd(
26756 * Disable interrupt
26758 - info_p->access.set_intr_mask(info_p, 0);
26759 + info_p->access->set_intr_mask(info_p, 0);
26760 /* Make sure there is room in the command FIFO */
26761 /* Actually it should be completely empty at this time. */
26762 for (i = 200000; i > 0; i--) {
26763 - temp = info_p->access.fifo_full(info_p);
26764 + temp = info_p->access->fifo_full(info_p);
26768 @@ -1466,7 +1466,7 @@ DBG(
26772 - info_p->access.submit_command(info_p, c);
26773 + info_p->access->submit_command(info_p, c);
26774 complete = pollcomplete(ctlr);
26776 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
26777 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
26778 * we check the new geometry. Then turn interrupts back on when
26781 - host->access.set_intr_mask(host, 0);
26782 + host->access->set_intr_mask(host, 0);
26784 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
26785 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
26787 for(i=0; i<NWD; i++) {
26788 struct gendisk *disk = ida_gendisk[ctlr][i];
26789 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
26790 /* Wait (up to 2 seconds) for a command to complete */
26792 for (i = 200000; i > 0; i--) {
26793 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
26794 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
26796 udelay(10); /* a short fixed delay */
26798 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
26799 index be73e9d..7fbf140 100644
26800 --- a/drivers/block/cpqarray.h
26801 +++ b/drivers/block/cpqarray.h
26802 @@ -99,7 +99,7 @@ struct ctlr_info {
26803 drv_info_t drv[NWD];
26804 struct proc_dir_entry *proc;
26806 - struct access_method access;
26807 + struct access_method *access;
26811 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
26812 index 9cf2035..bffca95 100644
26813 --- a/drivers/block/drbd/drbd_int.h
26814 +++ b/drivers/block/drbd/drbd_int.h
26815 @@ -736,7 +736,7 @@ struct drbd_request;
26816 struct drbd_epoch {
26817 struct list_head list;
26818 unsigned int barrier_nr;
26819 - atomic_t epoch_size; /* increased on every request added. */
26820 + atomic_unchecked_t epoch_size; /* increased on every request added. */
26821 atomic_t active; /* increased on every req. added, and dec on every finished. */
26822 unsigned long flags;
26824 @@ -1108,7 +1108,7 @@ struct drbd_conf {
26827 wait_queue_head_t seq_wait;
26828 - atomic_t packet_seq;
26829 + atomic_unchecked_t packet_seq;
26830 unsigned int peer_seq;
26831 spinlock_t peer_seq_lock;
26832 unsigned int minor;
26833 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
26835 static inline void drbd_tcp_cork(struct socket *sock)
26837 - int __user val = 1;
26839 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26840 - (char __user *)&val, sizeof(val));
26841 + (char __force_user *)&val, sizeof(val));
26844 static inline void drbd_tcp_uncork(struct socket *sock)
26846 - int __user val = 0;
26848 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26849 - (char __user *)&val, sizeof(val));
26850 + (char __force_user *)&val, sizeof(val));
26853 static inline void drbd_tcp_nodelay(struct socket *sock)
26855 - int __user val = 1;
26857 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
26858 - (char __user *)&val, sizeof(val));
26859 + (char __force_user *)&val, sizeof(val));
26862 static inline void drbd_tcp_quickack(struct socket *sock)
26864 - int __user val = 2;
26866 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
26867 - (char __user *)&val, sizeof(val));
26868 + (char __force_user *)&val, sizeof(val));
26871 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
26872 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
26873 index 0358e55..bc33689 100644
26874 --- a/drivers/block/drbd/drbd_main.c
26875 +++ b/drivers/block/drbd/drbd_main.c
26876 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
26878 p.block_id = block_id;
26879 p.blksize = blksize;
26880 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
26881 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
26883 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
26885 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
26886 p.sector = cpu_to_be64(req->sector);
26887 p.block_id = (unsigned long)req;
26888 p.seq_num = cpu_to_be32(req->seq_num =
26889 - atomic_add_return(1, &mdev->packet_seq));
26890 + atomic_add_return_unchecked(1, &mdev->packet_seq));
26892 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
26894 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
26895 atomic_set(&mdev->unacked_cnt, 0);
26896 atomic_set(&mdev->local_cnt, 0);
26897 atomic_set(&mdev->net_cnt, 0);
26898 - atomic_set(&mdev->packet_seq, 0);
26899 + atomic_set_unchecked(&mdev->packet_seq, 0);
26900 atomic_set(&mdev->pp_in_use, 0);
26901 atomic_set(&mdev->pp_in_use_by_net, 0);
26902 atomic_set(&mdev->rs_sect_in, 0);
26903 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
26904 mdev->receiver.t_state);
26906 /* no need to lock it, I'm the only thread alive */
26907 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
26908 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
26909 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
26910 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
26911 mdev->al_writ_cnt =
26912 mdev->bm_writ_cnt =
26914 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
26915 index af2a250..219c74b 100644
26916 --- a/drivers/block/drbd/drbd_nl.c
26917 +++ b/drivers/block/drbd/drbd_nl.c
26918 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
26919 module_put(THIS_MODULE);
26922 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26923 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26925 static unsigned short *
26926 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
26927 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
26928 cn_reply->id.idx = CN_IDX_DRBD;
26929 cn_reply->id.val = CN_VAL_DRBD;
26931 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26932 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26933 cn_reply->ack = 0; /* not used here. */
26934 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26935 (int)((char *)tl - (char *)reply->tag_list);
26936 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
26937 cn_reply->id.idx = CN_IDX_DRBD;
26938 cn_reply->id.val = CN_VAL_DRBD;
26940 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26941 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26942 cn_reply->ack = 0; /* not used here. */
26943 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26944 (int)((char *)tl - (char *)reply->tag_list);
26945 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
26946 cn_reply->id.idx = CN_IDX_DRBD;
26947 cn_reply->id.val = CN_VAL_DRBD;
26949 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
26950 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
26951 cn_reply->ack = 0; // not used here.
26952 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26953 (int)((char*)tl - (char*)reply->tag_list);
26954 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
26955 cn_reply->id.idx = CN_IDX_DRBD;
26956 cn_reply->id.val = CN_VAL_DRBD;
26958 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26959 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26960 cn_reply->ack = 0; /* not used here. */
26961 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26962 (int)((char *)tl - (char *)reply->tag_list);
26963 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
26964 index 43beaca..4a5b1dd 100644
26965 --- a/drivers/block/drbd/drbd_receiver.c
26966 +++ b/drivers/block/drbd/drbd_receiver.c
26967 @@ -894,7 +894,7 @@ retry:
26968 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
26969 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
26971 - atomic_set(&mdev->packet_seq, 0);
26972 + atomic_set_unchecked(&mdev->packet_seq, 0);
26973 mdev->peer_seq = 0;
26975 drbd_thread_start(&mdev->asender);
26976 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26980 - epoch_size = atomic_read(&epoch->epoch_size);
26981 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
26983 switch (ev & ~EV_CLEANUP) {
26985 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26989 - atomic_set(&epoch->epoch_size, 0);
26990 + atomic_set_unchecked(&epoch->epoch_size, 0);
26991 /* atomic_set(&epoch->active, 0); is already zero */
26992 if (rv == FE_STILL_LIVE)
26994 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26995 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
26998 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26999 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27000 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
27005 epoch = mdev->current_epoch;
27006 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
27007 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
27009 D_ASSERT(atomic_read(&epoch->active) == 0);
27010 D_ASSERT(epoch->flags == 0);
27011 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
27015 - atomic_set(&epoch->epoch_size, 0);
27016 + atomic_set_unchecked(&epoch->epoch_size, 0);
27017 atomic_set(&epoch->active, 0);
27019 spin_lock(&mdev->epoch_lock);
27020 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
27021 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
27022 list_add(&epoch->list, &mdev->current_epoch->list);
27023 mdev->current_epoch = epoch;
27025 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
27026 spin_unlock(&mdev->peer_seq_lock);
27028 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
27029 - atomic_inc(&mdev->current_epoch->epoch_size);
27030 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
27031 return drbd_drain_block(mdev, data_size);
27034 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
27036 spin_lock(&mdev->epoch_lock);
27037 e->epoch = mdev->current_epoch;
27038 - atomic_inc(&e->epoch->epoch_size);
27039 + atomic_inc_unchecked(&e->epoch->epoch_size);
27040 atomic_inc(&e->epoch->active);
27041 spin_unlock(&mdev->epoch_lock);
27043 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
27044 D_ASSERT(list_empty(&mdev->done_ee));
27046 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
27047 - atomic_set(&mdev->current_epoch->epoch_size, 0);
27048 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
27049 D_ASSERT(list_empty(&mdev->current_epoch->list));
27052 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
27053 index 1e888c9..05cf1b0 100644
27054 --- a/drivers/block/loop.c
27055 +++ b/drivers/block/loop.c
27056 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
27057 mm_segment_t old_fs = get_fs();
27060 - bw = file->f_op->write(file, buf, len, &pos);
27061 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
27063 if (likely(bw == len))
27065 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
27066 index 4364303..9adf4ee 100644
27067 --- a/drivers/char/Kconfig
27068 +++ b/drivers/char/Kconfig
27069 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
27072 bool "/dev/kmem virtual device support"
27075 + depends on !GRKERNSEC_KMEM
27077 Say Y here if you want to support the /dev/kmem device. The
27078 /dev/kmem device is rarely used, but can be used for certain
27079 @@ -596,6 +597,7 @@ config DEVPORT
27082 depends on ISA || PCI
27083 + depends on !GRKERNSEC_KMEM
27086 source "drivers/s390/char/Kconfig"
27087 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
27088 index 2e04433..22afc64 100644
27089 --- a/drivers/char/agp/frontend.c
27090 +++ b/drivers/char/agp/frontend.c
27091 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
27092 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27095 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27096 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27099 client = agp_find_client_by_pid(reserve.pid);
27100 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
27101 index 095ab90..afad0a4 100644
27102 --- a/drivers/char/briq_panel.c
27103 +++ b/drivers/char/briq_panel.c
27105 #include <linux/types.h>
27106 #include <linux/errno.h>
27107 #include <linux/tty.h>
27108 +#include <linux/mutex.h>
27109 #include <linux/timer.h>
27110 #include <linux/kernel.h>
27111 #include <linux/wait.h>
27112 @@ -34,6 +35,7 @@ static int vfd_is_open;
27113 static unsigned char vfd[40];
27114 static int vfd_cursor;
27115 static unsigned char ledpb, led;
27116 +static DEFINE_MUTEX(vfd_mutex);
27118 static void update_vfd(void)
27120 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
27124 + mutex_lock(&vfd_mutex);
27129 - if (get_user(c, buf))
27130 + if (get_user(c, buf)) {
27131 + mutex_unlock(&vfd_mutex);
27137 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
27141 + mutex_unlock(&vfd_mutex);
27145 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
27146 index f773a9d..65cd683 100644
27147 --- a/drivers/char/genrtc.c
27148 +++ b/drivers/char/genrtc.c
27149 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
27153 + memset(&pll, 0, sizeof(pll));
27154 if (get_rtc_pll(&pll))
27157 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
27158 index 0833896..cccce52 100644
27159 --- a/drivers/char/hpet.c
27160 +++ b/drivers/char/hpet.c
27161 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
27165 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
27166 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
27167 struct hpet_info *info)
27169 struct hpet_timer __iomem *timer;
27170 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
27171 index 58c0e63..46c16bf 100644
27172 --- a/drivers/char/ipmi/ipmi_msghandler.c
27173 +++ b/drivers/char/ipmi/ipmi_msghandler.c
27174 @@ -415,7 +415,7 @@ struct ipmi_smi {
27175 struct proc_dir_entry *proc_dir;
27176 char proc_dir_name[10];
27178 - atomic_t stats[IPMI_NUM_STATS];
27179 + atomic_unchecked_t stats[IPMI_NUM_STATS];
27182 * run_to_completion duplicate of smb_info, smi_info
27183 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27186 #define ipmi_inc_stat(intf, stat) \
27187 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27188 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27189 #define ipmi_get_stat(intf, stat) \
27190 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27191 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27193 static int is_lan_addr(struct ipmi_addr *addr)
27195 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
27196 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27197 init_waitqueue_head(&intf->waitq);
27198 for (i = 0; i < IPMI_NUM_STATS; i++)
27199 - atomic_set(&intf->stats[i], 0);
27200 + atomic_set_unchecked(&intf->stats[i], 0);
27202 intf->proc_dir = NULL;
27204 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
27205 index 9397ab4..d01bee1 100644
27206 --- a/drivers/char/ipmi/ipmi_si_intf.c
27207 +++ b/drivers/char/ipmi/ipmi_si_intf.c
27208 @@ -277,7 +277,7 @@ struct smi_info {
27209 unsigned char slave_addr;
27211 /* Counters and things for the proc filesystem. */
27212 - atomic_t stats[SI_NUM_STATS];
27213 + atomic_unchecked_t stats[SI_NUM_STATS];
27215 struct task_struct *thread;
27217 @@ -286,9 +286,9 @@ struct smi_info {
27220 #define smi_inc_stat(smi, stat) \
27221 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27222 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27223 #define smi_get_stat(smi, stat) \
27224 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27225 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27227 #define SI_MAX_PARMS 4
27229 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
27230 atomic_set(&new_smi->req_events, 0);
27231 new_smi->run_to_completion = 0;
27232 for (i = 0; i < SI_NUM_STATS; i++)
27233 - atomic_set(&new_smi->stats[i], 0);
27234 + atomic_set_unchecked(&new_smi->stats[i], 0);
27236 new_smi->interrupt_disabled = 1;
27237 atomic_set(&new_smi->stop_operation, 0);
27238 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
27239 index 1aeaaba..e018570 100644
27240 --- a/drivers/char/mbcs.c
27241 +++ b/drivers/char/mbcs.c
27242 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
27246 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
27247 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
27249 .part_num = MBCS_PART_NUM,
27250 .mfg_num = MBCS_MFG_NUM,
27251 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
27252 index 1451790..f705c30 100644
27253 --- a/drivers/char/mem.c
27254 +++ b/drivers/char/mem.c
27256 #include <linux/raw.h>
27257 #include <linux/tty.h>
27258 #include <linux/capability.h>
27259 +#include <linux/security.h>
27260 #include <linux/ptrace.h>
27261 #include <linux/device.h>
27262 #include <linux/highmem.h>
27264 # include <linux/efi.h>
27267 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27268 +extern const struct file_operations grsec_fops;
27271 static inline unsigned long size_inside_page(unsigned long start,
27272 unsigned long size)
27274 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27276 while (cursor < to) {
27277 if (!devmem_is_allowed(pfn)) {
27278 +#ifdef CONFIG_GRKERNSEC_KMEM
27279 + gr_handle_mem_readwrite(from, to);
27282 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27283 current->comm, from, to);
27287 cursor += PAGE_SIZE;
27288 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27292 +#elif defined(CONFIG_GRKERNSEC_KMEM)
27293 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27298 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27300 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27302 while (count > 0) {
27303 unsigned long remaining;
27306 sz = size_inside_page(p, count);
27308 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27312 - remaining = copy_to_user(buf, ptr, sz);
27313 +#ifdef CONFIG_PAX_USERCOPY
27314 + temp = kmalloc(sz, GFP_KERNEL);
27316 + unxlate_dev_mem_ptr(p, ptr);
27319 + memcpy(temp, ptr, sz);
27324 + remaining = copy_to_user(buf, temp, sz);
27326 +#ifdef CONFIG_PAX_USERCOPY
27330 unxlate_dev_mem_ptr(p, ptr);
27333 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27334 size_t count, loff_t *ppos)
27336 unsigned long p = *ppos;
27337 - ssize_t low_count, read, sz;
27338 + ssize_t low_count, read, sz, err = 0;
27339 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27343 if (p < (unsigned long) high_memory) {
27344 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27347 while (low_count > 0) {
27350 sz = size_inside_page(p, low_count);
27353 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27355 kbuf = xlate_dev_kmem_ptr((char *)p);
27357 - if (copy_to_user(buf, kbuf, sz))
27358 +#ifdef CONFIG_PAX_USERCOPY
27359 + temp = kmalloc(sz, GFP_KERNEL);
27362 + memcpy(temp, kbuf, sz);
27367 + err = copy_to_user(buf, temp, sz);
27369 +#ifdef CONFIG_PAX_USERCOPY
27377 @@ -867,6 +914,9 @@ static const struct memdev {
27378 #ifdef CONFIG_CRASH_DUMP
27379 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27381 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27382 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27386 static int memory_open(struct inode *inode, struct file *filp)
27387 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
27388 index da3cfee..a5a6606 100644
27389 --- a/drivers/char/nvram.c
27390 +++ b/drivers/char/nvram.c
27391 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
27393 spin_unlock_irq(&rtc_lock);
27395 - if (copy_to_user(buf, contents, tmp - contents))
27396 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
27400 diff --git a/drivers/char/random.c b/drivers/char/random.c
27401 index 6035ab8..bdfe4fd 100644
27402 --- a/drivers/char/random.c
27403 +++ b/drivers/char/random.c
27404 @@ -261,8 +261,13 @@
27406 * Configuration information
27408 +#ifdef CONFIG_GRKERNSEC_RANDNET
27409 +#define INPUT_POOL_WORDS 512
27410 +#define OUTPUT_POOL_WORDS 128
27412 #define INPUT_POOL_WORDS 128
27413 #define OUTPUT_POOL_WORDS 32
27415 #define SEC_XFER_SIZE 512
27416 #define EXTRACT_SIZE 10
27418 @@ -300,10 +305,17 @@ static struct poolinfo {
27420 int tap1, tap2, tap3, tap4, tap5;
27421 } poolinfo_table[] = {
27422 +#ifdef CONFIG_GRKERNSEC_RANDNET
27423 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
27424 + { 512, 411, 308, 208, 104, 1 },
27425 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
27426 + { 128, 103, 76, 51, 25, 1 },
27428 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
27429 { 128, 103, 76, 51, 25, 1 },
27430 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
27431 { 32, 26, 20, 14, 7, 1 },
27434 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
27435 { 2048, 1638, 1231, 819, 411, 1 },
27436 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
27438 extract_buf(r, tmp);
27439 i = min_t(int, nbytes, EXTRACT_SIZE);
27440 - if (copy_to_user(buf, tmp, i)) {
27441 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
27445 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
27446 #include <linux/sysctl.h>
27448 static int min_read_thresh = 8, min_write_thresh;
27449 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
27450 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
27451 static int max_write_thresh = INPUT_POOL_WORDS * 32;
27452 static char sysctl_bootid[16];
27454 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
27455 index 1ee8ce7..b778bef 100644
27456 --- a/drivers/char/sonypi.c
27457 +++ b/drivers/char/sonypi.c
27459 #include <asm/uaccess.h>
27460 #include <asm/io.h>
27461 #include <asm/system.h>
27462 +#include <asm/local.h>
27464 #include <linux/sonypi.h>
27466 @@ -491,7 +492,7 @@ static struct sonypi_device {
27467 spinlock_t fifo_lock;
27468 wait_queue_head_t fifo_proc_list;
27469 struct fasync_struct *fifo_async;
27471 + local_t open_count;
27473 struct input_dev *input_jog_dev;
27474 struct input_dev *input_key_dev;
27475 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
27476 static int sonypi_misc_release(struct inode *inode, struct file *file)
27478 mutex_lock(&sonypi_device.lock);
27479 - sonypi_device.open_count--;
27480 + local_dec(&sonypi_device.open_count);
27481 mutex_unlock(&sonypi_device.lock);
27484 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
27486 mutex_lock(&sonypi_device.lock);
27487 /* Flush input queue on first open */
27488 - if (!sonypi_device.open_count)
27489 + if (!local_read(&sonypi_device.open_count))
27490 kfifo_reset(&sonypi_device.fifo);
27491 - sonypi_device.open_count++;
27492 + local_inc(&sonypi_device.open_count);
27493 mutex_unlock(&sonypi_device.lock);
27496 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
27497 index 361a1df..2471eee 100644
27498 --- a/drivers/char/tpm/tpm.c
27499 +++ b/drivers/char/tpm/tpm.c
27500 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
27501 chip->vendor.req_complete_val)
27504 - if ((status == chip->vendor.req_canceled)) {
27505 + if (status == chip->vendor.req_canceled) {
27506 dev_err(chip->dev, "Operation Canceled\n");
27509 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
27510 index 0636520..169c1d0 100644
27511 --- a/drivers/char/tpm/tpm_bios.c
27512 +++ b/drivers/char/tpm/tpm_bios.c
27513 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
27516 if ((event->event_type == 0 && event->event_size == 0) ||
27517 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
27518 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
27522 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
27525 if ((event->event_type == 0 && event->event_size == 0) ||
27526 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
27527 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
27531 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
27534 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
27535 - seq_putc(m, data[i]);
27536 + if (!seq_putc(m, data[i]))
27541 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
27542 log->bios_event_log_end = log->bios_event_log + len;
27544 virt = acpi_os_map_memory(start, len);
27546 + kfree(log->bios_event_log);
27547 + log->bios_event_log = NULL;
27551 - memcpy(log->bios_event_log, virt, len);
27552 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
27554 acpi_os_unmap_memory(virt, len);
27556 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
27557 index 8e3c46d..c139b99 100644
27558 --- a/drivers/char/virtio_console.c
27559 +++ b/drivers/char/virtio_console.c
27560 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
27564 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
27565 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
27569 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
27570 if (!port_has_data(port) && !port->host_connected)
27573 - return fill_readbuf(port, ubuf, count, true);
27574 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
27577 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
27578 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
27579 index eb1d864..39ee5a7 100644
27580 --- a/drivers/dma/dmatest.c
27581 +++ b/drivers/dma/dmatest.c
27582 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
27584 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
27585 cnt = dmatest_add_threads(dtc, DMA_PQ);
27586 - thread_count += cnt > 0 ?: 0;
27587 + thread_count += cnt > 0 ? cnt : 0;
27590 pr_info("dmatest: Started %u threads using %s\n",
27591 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
27592 index c9eee6d..f9d5280 100644
27593 --- a/drivers/edac/amd64_edac.c
27594 +++ b/drivers/edac/amd64_edac.c
27595 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
27596 * PCI core identifies what devices are on a system during boot, and then
27597 * inquiry this table to see if this driver is for a given device found.
27599 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
27600 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
27602 .vendor = PCI_VENDOR_ID_AMD,
27603 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
27604 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
27605 index e47e73b..348e0bd 100644
27606 --- a/drivers/edac/amd76x_edac.c
27607 +++ b/drivers/edac/amd76x_edac.c
27608 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
27612 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
27613 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
27615 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27617 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
27618 index 1af531a..3a8ff27 100644
27619 --- a/drivers/edac/e752x_edac.c
27620 +++ b/drivers/edac/e752x_edac.c
27621 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
27625 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
27626 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
27628 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27630 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
27631 index 6ffb6d2..383d8d7 100644
27632 --- a/drivers/edac/e7xxx_edac.c
27633 +++ b/drivers/edac/e7xxx_edac.c
27634 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
27638 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
27639 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
27641 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27643 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
27644 index 495198a..ac08c85 100644
27645 --- a/drivers/edac/edac_pci_sysfs.c
27646 +++ b/drivers/edac/edac_pci_sysfs.c
27647 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
27648 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27649 static int edac_pci_poll_msec = 1000; /* one second workq period */
27651 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
27652 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27653 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27654 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27656 static struct kobject *edac_pci_top_main_kobj;
27657 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27658 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27659 edac_printk(KERN_CRIT, EDAC_PCI,
27660 "Signaled System Error on %s\n",
27662 - atomic_inc(&pci_nonparity_count);
27663 + atomic_inc_unchecked(&pci_nonparity_count);
27666 if (status & (PCI_STATUS_PARITY)) {
27667 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27668 "Master Data Parity Error on %s\n",
27671 - atomic_inc(&pci_parity_count);
27672 + atomic_inc_unchecked(&pci_parity_count);
27675 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27676 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27677 "Detected Parity Error on %s\n",
27680 - atomic_inc(&pci_parity_count);
27681 + atomic_inc_unchecked(&pci_parity_count);
27685 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27686 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27687 "Signaled System Error on %s\n",
27689 - atomic_inc(&pci_nonparity_count);
27690 + atomic_inc_unchecked(&pci_nonparity_count);
27693 if (status & (PCI_STATUS_PARITY)) {
27694 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27695 "Master Data Parity Error on "
27696 "%s\n", pci_name(dev));
27698 - atomic_inc(&pci_parity_count);
27699 + atomic_inc_unchecked(&pci_parity_count);
27702 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27703 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27704 "Detected Parity Error on %s\n",
27707 - atomic_inc(&pci_parity_count);
27708 + atomic_inc_unchecked(&pci_parity_count);
27712 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
27713 if (!check_pci_errors)
27716 - before_count = atomic_read(&pci_parity_count);
27717 + before_count = atomic_read_unchecked(&pci_parity_count);
27719 /* scan all PCI devices looking for a Parity Error on devices and
27721 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
27722 /* Only if operator has selected panic on PCI Error */
27723 if (edac_pci_get_panic_on_pe()) {
27724 /* If the count is different 'after' from 'before' */
27725 - if (before_count != atomic_read(&pci_parity_count))
27726 + if (before_count != atomic_read_unchecked(&pci_parity_count))
27727 panic("EDAC: PCI Parity Error");
27730 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
27731 index c0510b3..6e2a954 100644
27732 --- a/drivers/edac/i3000_edac.c
27733 +++ b/drivers/edac/i3000_edac.c
27734 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
27738 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
27739 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
27741 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27743 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
27744 index aa08497..7e6822a 100644
27745 --- a/drivers/edac/i3200_edac.c
27746 +++ b/drivers/edac/i3200_edac.c
27747 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
27751 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
27752 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
27754 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27756 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
27757 index 4dc3ac2..67d05a6 100644
27758 --- a/drivers/edac/i5000_edac.c
27759 +++ b/drivers/edac/i5000_edac.c
27760 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
27762 * The "E500P" device is the first device supported.
27764 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
27765 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
27766 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
27767 .driver_data = I5000P},
27769 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
27770 index bcbdeec..9886d16 100644
27771 --- a/drivers/edac/i5100_edac.c
27772 +++ b/drivers/edac/i5100_edac.c
27773 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
27777 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
27778 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
27779 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
27780 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
27782 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
27783 index 74d6ec34..baff517 100644
27784 --- a/drivers/edac/i5400_edac.c
27785 +++ b/drivers/edac/i5400_edac.c
27786 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
27788 * The "E500P" device is the first device supported.
27790 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
27791 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
27792 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
27793 {0,} /* 0 terminated list. */
27795 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
27796 index 6104dba..e7ea8e1 100644
27797 --- a/drivers/edac/i7300_edac.c
27798 +++ b/drivers/edac/i7300_edac.c
27799 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
27801 * Has only 8086:360c PCI ID
27803 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
27804 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
27805 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
27806 {0,} /* 0 terminated list. */
27808 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
27809 index 70ad892..178943c 100644
27810 --- a/drivers/edac/i7core_edac.c
27811 +++ b/drivers/edac/i7core_edac.c
27812 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
27814 * pci_device_id table for which devices we are looking for
27816 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
27817 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
27818 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
27819 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
27820 {0,} /* 0 terminated list. */
27821 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
27822 index 4329d39..f3022ef 100644
27823 --- a/drivers/edac/i82443bxgx_edac.c
27824 +++ b/drivers/edac/i82443bxgx_edac.c
27825 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
27827 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
27829 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
27830 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
27831 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
27832 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
27833 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
27834 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
27835 index 931a057..fd28340 100644
27836 --- a/drivers/edac/i82860_edac.c
27837 +++ b/drivers/edac/i82860_edac.c
27838 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
27842 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
27843 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
27845 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27847 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
27848 index 33864c6..01edc61 100644
27849 --- a/drivers/edac/i82875p_edac.c
27850 +++ b/drivers/edac/i82875p_edac.c
27851 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
27855 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
27856 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
27858 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27860 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
27861 index a5da732..983363b 100644
27862 --- a/drivers/edac/i82975x_edac.c
27863 +++ b/drivers/edac/i82975x_edac.c
27864 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
27868 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
27869 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
27871 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27873 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
27874 index 0106747..0b40417 100644
27875 --- a/drivers/edac/mce_amd.h
27876 +++ b/drivers/edac/mce_amd.h
27877 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
27878 bool (*dc_mce)(u16, u8);
27879 bool (*ic_mce)(u16, u8);
27880 bool (*nb_mce)(u16, u8);
27884 void amd_report_gart_errors(bool);
27885 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
27886 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
27887 index b153674..ad2ba9b 100644
27888 --- a/drivers/edac/r82600_edac.c
27889 +++ b/drivers/edac/r82600_edac.c
27890 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
27894 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
27895 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
27897 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
27899 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
27900 index 7a402bf..af0b211 100644
27901 --- a/drivers/edac/sb_edac.c
27902 +++ b/drivers/edac/sb_edac.c
27903 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
27905 * pci_device_id table for which devices we are looking for
27907 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
27908 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
27909 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
27910 {0,} /* 0 terminated list. */
27912 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
27913 index b6f47de..c5acf3a 100644
27914 --- a/drivers/edac/x38_edac.c
27915 +++ b/drivers/edac/x38_edac.c
27916 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
27920 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
27921 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
27923 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27925 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
27926 index 85661b0..c784559a 100644
27927 --- a/drivers/firewire/core-card.c
27928 +++ b/drivers/firewire/core-card.c
27929 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
27931 void fw_core_remove_card(struct fw_card *card)
27933 - struct fw_card_driver dummy_driver = dummy_driver_template;
27934 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
27936 card->driver->update_phy_reg(card, 4,
27937 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
27938 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
27939 index 4799393..37bd3ab 100644
27940 --- a/drivers/firewire/core-cdev.c
27941 +++ b/drivers/firewire/core-cdev.c
27942 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
27945 if ((request->channels == 0 && request->bandwidth == 0) ||
27946 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27947 - request->bandwidth < 0)
27948 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27951 r = kmalloc(sizeof(*r), GFP_KERNEL);
27952 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
27953 index 855ab3f..11f4bbd 100644
27954 --- a/drivers/firewire/core-transaction.c
27955 +++ b/drivers/firewire/core-transaction.c
27957 #include <linux/timer.h>
27958 #include <linux/types.h>
27959 #include <linux/workqueue.h>
27960 +#include <linux/sched.h>
27962 #include <asm/byteorder.h>
27964 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
27965 index b45be57..5fad18b 100644
27966 --- a/drivers/firewire/core.h
27967 +++ b/drivers/firewire/core.h
27968 @@ -101,6 +101,7 @@ struct fw_card_driver {
27970 int (*stop_iso)(struct fw_iso_context *ctx);
27972 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
27974 void fw_card_initialize(struct fw_card *card,
27975 const struct fw_card_driver *driver, struct device *device);
27976 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
27977 index 153980b..4b4d046 100644
27978 --- a/drivers/firmware/dmi_scan.c
27979 +++ b/drivers/firmware/dmi_scan.c
27980 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
27985 - * no iounmap() for that ioremap(); it would be a no-op, but
27986 - * it's so early in setup that sucker gets confused into doing
27987 - * what it shouldn't if we actually call it.
27989 p = dmi_ioremap(0xF0000, 0x10000);
27992 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
27996 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
27997 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
28001 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
28002 index 98723cb..10ca85b 100644
28003 --- a/drivers/gpio/gpio-vr41xx.c
28004 +++ b/drivers/gpio/gpio-vr41xx.c
28005 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
28006 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
28007 maskl, pendl, maskh, pendh);
28009 - atomic_inc(&irq_err_count);
28010 + atomic_inc_unchecked(&irq_err_count);
28014 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
28015 index 8323fc3..5c1d755 100644
28016 --- a/drivers/gpu/drm/drm_crtc.c
28017 +++ b/drivers/gpu/drm/drm_crtc.c
28018 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
28020 if ((out_resp->count_modes >= mode_count) && mode_count) {
28022 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
28023 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
28024 list_for_each_entry(mode, &connector->modes, head) {
28025 drm_crtc_convert_to_umode(&u_mode, mode);
28026 if (copy_to_user(mode_ptr + copied,
28027 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
28029 if ((out_resp->count_props >= props_count) && props_count) {
28031 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
28032 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
28033 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
28034 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
28035 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
28036 if (connector->property_ids[i] != 0) {
28037 if (put_user(connector->property_ids[i],
28038 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
28040 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
28042 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
28043 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
28044 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
28045 if (connector->encoder_ids[i] != 0) {
28046 if (put_user(connector->encoder_ids[i],
28047 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
28050 for (i = 0; i < crtc_req->count_connectors; i++) {
28051 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
28052 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
28053 if (get_user(out_id, &set_connectors_ptr[i])) {
28056 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
28057 fb = obj_to_fb(obj);
28059 num_clips = r->num_clips;
28060 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
28061 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
28063 if (!num_clips != !clips_ptr) {
28065 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28066 out_resp->flags = property->flags;
28068 if ((out_resp->count_values >= value_count) && value_count) {
28069 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
28070 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
28071 for (i = 0; i < value_count; i++) {
28072 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
28074 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28075 if (property->flags & DRM_MODE_PROP_ENUM) {
28076 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
28078 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
28079 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
28080 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
28082 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
28083 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28084 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
28086 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
28087 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
28088 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
28090 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
28091 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
28092 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
28093 struct drm_mode_get_blob *out_resp = data;
28094 struct drm_property_blob *blob;
28097 + void __user *blob_ptr;
28099 if (!drm_core_check_feature(dev, DRIVER_MODESET))
28101 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
28102 blob = obj_to_blob(obj);
28104 if (out_resp->length == blob->length) {
28105 - blob_ptr = (void *)(unsigned long)out_resp->data;
28106 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
28107 if (copy_to_user(blob_ptr, blob->data, blob->length)){
28110 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
28111 index d2619d7..bd6bd00 100644
28112 --- a/drivers/gpu/drm/drm_crtc_helper.c
28113 +++ b/drivers/gpu/drm/drm_crtc_helper.c
28114 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
28115 struct drm_crtc *tmp;
28118 - WARN(!crtc, "checking null crtc?\n");
28123 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
28124 index 40c187c..5746164 100644
28125 --- a/drivers/gpu/drm/drm_drv.c
28126 +++ b/drivers/gpu/drm/drm_drv.c
28127 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
28129 * Copy and IOCTL return string to user space
28131 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
28132 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
28136 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
28138 dev = file_priv->minor->dev;
28139 atomic_inc(&dev->ioctl_count);
28140 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28141 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28142 ++file_priv->ioctl_count;
28144 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28145 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
28146 index 828bf65..cdaa0e9 100644
28147 --- a/drivers/gpu/drm/drm_fops.c
28148 +++ b/drivers/gpu/drm/drm_fops.c
28149 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
28152 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28153 - atomic_set(&dev->counts[i], 0);
28154 + atomic_set_unchecked(&dev->counts[i], 0);
28156 dev->sigdata.lock = NULL;
28158 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
28160 retcode = drm_open_helper(inode, filp, dev);
28162 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28163 - if (!dev->open_count++)
28164 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28165 + if (local_inc_return(&dev->open_count) == 1)
28166 retcode = drm_setup(dev);
28169 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
28171 mutex_lock(&drm_global_mutex);
28173 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28174 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28176 if (dev->driver->preclose)
28177 dev->driver->preclose(dev, file_priv);
28178 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
28179 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28180 task_pid_nr(current),
28181 (long)old_encode_dev(file_priv->minor->device),
28182 - dev->open_count);
28183 + local_read(&dev->open_count));
28185 /* Release any auth tokens that might point to this file_priv,
28186 (do that under the drm_global_mutex) */
28187 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
28188 * End inline drm_release
28191 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28192 - if (!--dev->open_count) {
28193 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28194 + if (local_dec_and_test(&dev->open_count)) {
28195 if (atomic_read(&dev->ioctl_count)) {
28196 DRM_ERROR("Device busy: %d\n",
28197 atomic_read(&dev->ioctl_count));
28198 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
28199 index c87dc96..326055d 100644
28200 --- a/drivers/gpu/drm/drm_global.c
28201 +++ b/drivers/gpu/drm/drm_global.c
28203 struct drm_global_item {
28204 struct mutex mutex;
28207 + atomic_t refcount;
28210 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28211 @@ -49,7 +49,7 @@ void drm_global_init(void)
28212 struct drm_global_item *item = &glob[i];
28213 mutex_init(&item->mutex);
28214 item->object = NULL;
28215 - item->refcount = 0;
28216 + atomic_set(&item->refcount, 0);
28220 @@ -59,7 +59,7 @@ void drm_global_release(void)
28221 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28222 struct drm_global_item *item = &glob[i];
28223 BUG_ON(item->object != NULL);
28224 - BUG_ON(item->refcount != 0);
28225 + BUG_ON(atomic_read(&item->refcount) != 0);
28229 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28232 mutex_lock(&item->mutex);
28233 - if (item->refcount == 0) {
28234 + if (atomic_read(&item->refcount) == 0) {
28235 item->object = kzalloc(ref->size, GFP_KERNEL);
28236 if (unlikely(item->object == NULL)) {
28238 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28242 - ++item->refcount;
28243 + atomic_inc(&item->refcount);
28244 ref->object = item->object;
28245 object = item->object;
28246 mutex_unlock(&item->mutex);
28247 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
28248 struct drm_global_item *item = &glob[ref->global_type];
28250 mutex_lock(&item->mutex);
28251 - BUG_ON(item->refcount == 0);
28252 + BUG_ON(atomic_read(&item->refcount) == 0);
28253 BUG_ON(ref->object != item->object);
28254 - if (--item->refcount == 0) {
28255 + if (atomic_dec_and_test(&item->refcount)) {
28257 item->object = NULL;
28259 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
28260 index ab1162d..42587b2 100644
28261 --- a/drivers/gpu/drm/drm_info.c
28262 +++ b/drivers/gpu/drm/drm_info.c
28263 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
28264 struct drm_local_map *map;
28265 struct drm_map_list *r_list;
28267 - /* Hardcoded from _DRM_FRAME_BUFFER,
28268 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28269 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28270 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28271 + static const char * const types[] = {
28272 + [_DRM_FRAME_BUFFER] = "FB",
28273 + [_DRM_REGISTERS] = "REG",
28274 + [_DRM_SHM] = "SHM",
28275 + [_DRM_AGP] = "AGP",
28276 + [_DRM_SCATTER_GATHER] = "SG",
28277 + [_DRM_CONSISTENT] = "PCI",
28278 + [_DRM_GEM] = "GEM" };
28282 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
28286 - if (map->type < 0 || map->type > 5)
28287 + if (map->type >= ARRAY_SIZE(types))
28290 type = types[map->type];
28291 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
28292 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28293 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28294 vma->vm_flags & VM_IO ? 'i' : '-',
28295 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28301 #if defined(__i386__)
28302 pgprot = pgprot_val(vma->vm_page_prot);
28303 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
28304 index ddd70db..40321e6 100644
28305 --- a/drivers/gpu/drm/drm_ioc32.c
28306 +++ b/drivers/gpu/drm/drm_ioc32.c
28307 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
28308 request = compat_alloc_user_space(nbytes);
28309 if (!access_ok(VERIFY_WRITE, request, nbytes))
28311 - list = (struct drm_buf_desc *) (request + 1);
28312 + list = (struct drm_buf_desc __user *) (request + 1);
28314 if (__put_user(count, &request->count)
28315 || __put_user(list, &request->list))
28316 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
28317 request = compat_alloc_user_space(nbytes);
28318 if (!access_ok(VERIFY_WRITE, request, nbytes))
28320 - list = (struct drm_buf_pub *) (request + 1);
28321 + list = (struct drm_buf_pub __user *) (request + 1);
28323 if (__put_user(count, &request->count)
28324 || __put_user(list, &request->list))
28325 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
28326 index 904d7e9..ab88581 100644
28327 --- a/drivers/gpu/drm/drm_ioctl.c
28328 +++ b/drivers/gpu/drm/drm_ioctl.c
28329 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
28330 stats->data[i].value =
28331 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28333 - stats->data[i].value = atomic_read(&dev->counts[i]);
28334 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28335 stats->data[i].type = dev->types[i];
28338 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
28339 index 632ae24..244cf4a 100644
28340 --- a/drivers/gpu/drm/drm_lock.c
28341 +++ b/drivers/gpu/drm/drm_lock.c
28342 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28343 if (drm_lock_take(&master->lock, lock->context)) {
28344 master->lock.file_priv = file_priv;
28345 master->lock.lock_time = jiffies;
28346 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28347 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28348 break; /* Got lock */
28351 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28355 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28356 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28358 if (drm_lock_free(&master->lock, lock->context)) {
28359 /* FIXME: Should really bail out here. */
28360 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
28361 index 8f371e8..9f85d52 100644
28362 --- a/drivers/gpu/drm/i810/i810_dma.c
28363 +++ b/drivers/gpu/drm/i810/i810_dma.c
28364 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
28365 dma->buflist[vertex->idx],
28366 vertex->discard, vertex->used);
28368 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28369 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28370 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28371 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28372 sarea_priv->last_enqueue = dev_priv->counter - 1;
28373 sarea_priv->last_dispatch = (int)hw_status[5];
28375 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
28376 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28379 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28380 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28381 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28382 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28383 sarea_priv->last_enqueue = dev_priv->counter - 1;
28384 sarea_priv->last_dispatch = (int)hw_status[5];
28386 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
28387 index c9339f4..f5e1b9d 100644
28388 --- a/drivers/gpu/drm/i810/i810_drv.h
28389 +++ b/drivers/gpu/drm/i810/i810_drv.h
28390 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28393 wait_queue_head_t irq_queue;
28394 - atomic_t irq_received;
28395 - atomic_t irq_emitted;
28396 + atomic_unchecked_t irq_received;
28397 + atomic_unchecked_t irq_emitted;
28400 } drm_i810_private_t;
28401 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
28402 index b2e3c97..58cf079 100644
28403 --- a/drivers/gpu/drm/i915/i915_debugfs.c
28404 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
28405 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
28408 seq_printf(m, "Interrupts received: %d\n",
28409 - atomic_read(&dev_priv->irq_received));
28410 + atomic_read_unchecked(&dev_priv->irq_received));
28411 for (i = 0; i < I915_NUM_RINGS; i++) {
28412 if (IS_GEN6(dev) || IS_GEN7(dev)) {
28413 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
28414 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
28417 if (opregion->header)
28418 - seq_write(m, opregion->header, OPREGION_SIZE);
28419 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
28421 mutex_unlock(&dev->struct_mutex);
28423 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
28424 index c4da951..3c59c5c 100644
28425 --- a/drivers/gpu/drm/i915/i915_dma.c
28426 +++ b/drivers/gpu/drm/i915/i915_dma.c
28427 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
28430 spin_lock(&dev->count_lock);
28431 - can_switch = (dev->open_count == 0);
28432 + can_switch = (local_read(&dev->open_count) == 0);
28433 spin_unlock(&dev->count_lock);
28436 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
28437 index ae294a0..1755461 100644
28438 --- a/drivers/gpu/drm/i915/i915_drv.h
28439 +++ b/drivers/gpu/drm/i915/i915_drv.h
28440 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
28441 /* render clock increase/decrease */
28442 /* display clock increase/decrease */
28443 /* pll clock increase/decrease */
28447 struct intel_device_info {
28449 @@ -318,7 +318,7 @@ typedef struct drm_i915_private {
28453 - atomic_t irq_received;
28454 + atomic_unchecked_t irq_received;
28456 /* protects the irq masks */
28457 spinlock_t irq_lock;
28458 @@ -893,7 +893,7 @@ struct drm_i915_gem_object {
28459 * will be page flipped away on the next vblank. When it
28460 * reaches 0, dev_priv->pending_flip_queue will be woken up.
28462 - atomic_t pending_flip;
28463 + atomic_unchecked_t pending_flip;
28466 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
28467 @@ -1273,7 +1273,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
28468 extern void intel_teardown_gmbus(struct drm_device *dev);
28469 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
28470 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
28471 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28472 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28474 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
28476 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28477 index b9da890..cad1d98 100644
28478 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28479 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28480 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
28481 i915_gem_clflush_object(obj);
28483 if (obj->base.pending_write_domain)
28484 - cd->flips |= atomic_read(&obj->pending_flip);
28485 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
28487 /* The actual obj->write_domain will be updated with
28488 * pending_write_domain after we emit the accumulated flush for all
28489 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
28492 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
28494 + unsigned int count)
28499 for (i = 0; i < count; i++) {
28500 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
28501 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
28502 index d47a53b..61154c2 100644
28503 --- a/drivers/gpu/drm/i915/i915_irq.c
28504 +++ b/drivers/gpu/drm/i915/i915_irq.c
28505 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
28506 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
28507 struct drm_i915_master_private *master_priv;
28509 - atomic_inc(&dev_priv->irq_received);
28510 + atomic_inc_unchecked(&dev_priv->irq_received);
28512 /* disable master interrupt before clearing iir */
28513 de_ier = I915_READ(DEIER);
28514 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
28515 struct drm_i915_master_private *master_priv;
28516 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
28518 - atomic_inc(&dev_priv->irq_received);
28519 + atomic_inc_unchecked(&dev_priv->irq_received);
28522 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
28523 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
28524 int ret = IRQ_NONE, pipe;
28525 bool blc_event = false;
28527 - atomic_inc(&dev_priv->irq_received);
28528 + atomic_inc_unchecked(&dev_priv->irq_received);
28530 iir = I915_READ(IIR);
28532 @@ -1750,7 +1750,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
28534 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28536 - atomic_set(&dev_priv->irq_received, 0);
28537 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28539 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28540 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28541 @@ -1938,7 +1938,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
28542 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28545 - atomic_set(&dev_priv->irq_received, 0);
28546 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28548 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28549 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28550 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
28551 index daa5743..c0757a9 100644
28552 --- a/drivers/gpu/drm/i915/intel_display.c
28553 +++ b/drivers/gpu/drm/i915/intel_display.c
28554 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
28556 wait_event(dev_priv->pending_flip_queue,
28557 atomic_read(&dev_priv->mm.wedged) ||
28558 - atomic_read(&obj->pending_flip) == 0);
28559 + atomic_read_unchecked(&obj->pending_flip) == 0);
28561 /* Big Hammer, we also need to ensure that any pending
28562 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
28563 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
28564 obj = to_intel_framebuffer(crtc->fb)->obj;
28565 dev_priv = crtc->dev->dev_private;
28566 wait_event(dev_priv->pending_flip_queue,
28567 - atomic_read(&obj->pending_flip) == 0);
28568 + atomic_read_unchecked(&obj->pending_flip) == 0);
28571 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
28572 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
28574 atomic_clear_mask(1 << intel_crtc->plane,
28575 &obj->pending_flip.counter);
28576 - if (atomic_read(&obj->pending_flip) == 0)
28577 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
28578 wake_up(&dev_priv->pending_flip_queue);
28580 schedule_work(&work->work);
28581 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28582 /* Block clients from rendering to the new back buffer until
28583 * the flip occurs and the object is no longer visible.
28585 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28586 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28588 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
28590 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28594 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28595 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28596 drm_gem_object_unreference(&work->old_fb_obj->base);
28597 drm_gem_object_unreference(&obj->base);
28598 mutex_unlock(&dev->struct_mutex);
28599 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
28600 index 54558a0..2d97005 100644
28601 --- a/drivers/gpu/drm/mga/mga_drv.h
28602 +++ b/drivers/gpu/drm/mga/mga_drv.h
28603 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28607 - atomic_t vbl_received; /**< Number of vblanks received. */
28608 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28609 wait_queue_head_t fence_queue;
28610 - atomic_t last_fence_retired;
28611 + atomic_unchecked_t last_fence_retired;
28612 u32 next_fence_to_post;
28614 unsigned int fb_cpp;
28615 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
28616 index 2581202..f230a8d9 100644
28617 --- a/drivers/gpu/drm/mga/mga_irq.c
28618 +++ b/drivers/gpu/drm/mga/mga_irq.c
28619 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
28623 - return atomic_read(&dev_priv->vbl_received);
28624 + return atomic_read_unchecked(&dev_priv->vbl_received);
28628 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28629 /* VBLANK interrupt */
28630 if (status & MGA_VLINEPEN) {
28631 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28632 - atomic_inc(&dev_priv->vbl_received);
28633 + atomic_inc_unchecked(&dev_priv->vbl_received);
28634 drm_handle_vblank(dev, 0);
28637 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28638 if ((prim_start & ~0x03) != (prim_end & ~0x03))
28639 MGA_WRITE(MGA_PRIMEND, prim_end);
28641 - atomic_inc(&dev_priv->last_fence_retired);
28642 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
28643 DRM_WAKEUP(&dev_priv->fence_queue);
28646 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
28649 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28650 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28651 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28652 - *sequence) <= (1 << 23)));
28654 *sequence = cur_fence;
28655 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
28656 index 5fc201b..7b032b9 100644
28657 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
28658 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
28659 @@ -201,7 +201,7 @@ struct methods {
28660 const char desc[8];
28661 void (*loadbios)(struct drm_device *, uint8_t *);
28666 static struct methods shadow_methods[] = {
28667 { "PRAMIN", load_vbios_pramin, true },
28668 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
28671 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
28675 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
28677 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
28678 index 4c0be3a..5757582 100644
28679 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
28680 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
28681 @@ -238,7 +238,7 @@ struct nouveau_channel {
28682 struct list_head pending;
28684 uint32_t sequence_ack;
28685 - atomic_t last_sequence_irq;
28686 + atomic_unchecked_t last_sequence_irq;
28687 struct nouveau_vma vma;
28690 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
28691 u32 handle, u16 class);
28692 void (*set_tile_region)(struct drm_device *dev, int i);
28693 void (*tlb_flush)(struct drm_device *, int engine);
28697 struct nouveau_instmem_engine {
28699 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
28700 struct nouveau_mc_engine {
28701 int (*init)(struct drm_device *dev);
28702 void (*takedown)(struct drm_device *dev);
28706 struct nouveau_timer_engine {
28707 int (*init)(struct drm_device *dev);
28708 void (*takedown)(struct drm_device *dev);
28709 uint64_t (*read)(struct drm_device *dev);
28713 struct nouveau_fb_engine {
28715 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
28716 void (*put)(struct drm_device *, struct nouveau_mem **);
28718 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
28722 struct nouveau_engine {
28723 struct nouveau_instmem_engine instmem;
28724 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
28725 struct drm_global_reference mem_global_ref;
28726 struct ttm_bo_global_ref bo_global_ref;
28727 struct ttm_bo_device bdev;
28728 - atomic_t validate_sequence;
28729 + atomic_unchecked_t validate_sequence;
28733 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
28734 index 2f6daae..c9d7b9e 100644
28735 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
28736 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
28737 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
28738 if (USE_REFCNT(dev))
28739 sequence = nvchan_rd32(chan, 0x48);
28741 - sequence = atomic_read(&chan->fence.last_sequence_irq);
28742 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
28744 if (chan->fence.sequence_ack == sequence)
28746 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
28750 - atomic_set(&chan->fence.last_sequence_irq, 0);
28751 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
28755 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
28756 index 7ce3fde..cb3ea04 100644
28757 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
28758 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
28759 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
28763 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
28764 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
28766 if (++trycnt > 100000) {
28767 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
28768 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
28769 index d8831ab..0ba8356 100644
28770 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
28771 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
28772 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
28775 spin_lock(&dev->count_lock);
28776 - can_switch = (dev->open_count == 0);
28777 + can_switch = (local_read(&dev->open_count) == 0);
28778 spin_unlock(&dev->count_lock);
28781 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
28782 index dbdea8e..cd6eeeb 100644
28783 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
28784 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
28785 @@ -554,7 +554,7 @@ static int
28786 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
28787 u32 class, u32 mthd, u32 data)
28789 - atomic_set(&chan->fence.last_sequence_irq, data);
28790 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
28794 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
28795 index bcac90b..53bfc76 100644
28796 --- a/drivers/gpu/drm/r128/r128_cce.c
28797 +++ b/drivers/gpu/drm/r128/r128_cce.c
28798 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
28800 /* GH: Simple idle check.
28802 - atomic_set(&dev_priv->idle_count, 0);
28803 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28805 /* We don't support anything other than bus-mastering ring mode,
28806 * but the ring can be in either AGP or PCI space for the ring
28807 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
28808 index 930c71b..499aded 100644
28809 --- a/drivers/gpu/drm/r128/r128_drv.h
28810 +++ b/drivers/gpu/drm/r128/r128_drv.h
28811 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28813 unsigned long cce_buffers_offset;
28815 - atomic_t idle_count;
28816 + atomic_unchecked_t idle_count;
28821 u32 crtc_offset_cntl;
28823 - atomic_t vbl_received;
28824 + atomic_unchecked_t vbl_received;
28827 unsigned int front_offset;
28828 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
28829 index 429d5a0..7e899ed 100644
28830 --- a/drivers/gpu/drm/r128/r128_irq.c
28831 +++ b/drivers/gpu/drm/r128/r128_irq.c
28832 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
28836 - return atomic_read(&dev_priv->vbl_received);
28837 + return atomic_read_unchecked(&dev_priv->vbl_received);
28840 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28841 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28842 /* VBLANK interrupt */
28843 if (status & R128_CRTC_VBLANK_INT) {
28844 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28845 - atomic_inc(&dev_priv->vbl_received);
28846 + atomic_inc_unchecked(&dev_priv->vbl_received);
28847 drm_handle_vblank(dev, 0);
28848 return IRQ_HANDLED;
28850 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
28851 index a9e33ce..09edd4b 100644
28852 --- a/drivers/gpu/drm/r128/r128_state.c
28853 +++ b/drivers/gpu/drm/r128/r128_state.c
28854 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
28856 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
28858 - if (atomic_read(&dev_priv->idle_count) == 0)
28859 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
28860 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28862 - atomic_set(&dev_priv->idle_count, 0);
28863 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28867 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
28868 index 5a82b6b..9e69c73 100644
28869 --- a/drivers/gpu/drm/radeon/mkregtable.c
28870 +++ b/drivers/gpu/drm/radeon/mkregtable.c
28871 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
28873 regmatch_t match[4];
28881 struct offset *offset;
28882 char last_reg_s[10];
28884 + unsigned long last_reg;
28887 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28888 diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
28889 index cb1acff..8861bc5 100644
28890 --- a/drivers/gpu/drm/radeon/r600_cs.c
28891 +++ b/drivers/gpu/drm/radeon/r600_cs.c
28892 @@ -1304,6 +1304,7 @@ static int r600_check_texture_resource(struct radeon_cs_parser *p, u32 idx,
28893 h0 = G_038004_TEX_HEIGHT(word1) + 1;
28894 d0 = G_038004_TEX_DEPTH(word1);
28897 switch (G_038000_DIM(word0)) {
28898 case V_038000_SQ_TEX_DIM_1D:
28899 case V_038000_SQ_TEX_DIM_2D:
28900 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
28901 index 8227e76..ce0b195 100644
28902 --- a/drivers/gpu/drm/radeon/radeon.h
28903 +++ b/drivers/gpu/drm/radeon/radeon.h
28904 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
28906 struct radeon_fence_driver {
28907 uint32_t scratch_reg;
28909 + atomic_unchecked_t seq;
28911 unsigned long last_jiffies;
28912 unsigned long last_timeout;
28913 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
28915 void (*draw_auto)(struct radeon_device *rdev);
28916 void (*set_default_state)(struct radeon_device *rdev);
28921 struct mutex mutex;
28922 @@ -954,7 +954,7 @@ struct radeon_asic {
28923 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
28924 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
28925 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
28931 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
28932 index 9231564..78b00fd 100644
28933 --- a/drivers/gpu/drm/radeon/radeon_device.c
28934 +++ b/drivers/gpu/drm/radeon/radeon_device.c
28935 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
28938 spin_lock(&dev->count_lock);
28939 - can_switch = (dev->open_count == 0);
28940 + can_switch = (local_read(&dev->open_count) == 0);
28941 spin_unlock(&dev->count_lock);
28944 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
28945 index a1b59ca..86f2d44 100644
28946 --- a/drivers/gpu/drm/radeon/radeon_drv.h
28947 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
28948 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
28951 wait_queue_head_t swi_queue;
28952 - atomic_t swi_emitted;
28953 + atomic_unchecked_t swi_emitted;
28955 uint32_t irq_enable_reg;
28956 uint32_t r500_disp_irq_reg;
28957 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
28958 index 76ec0e9..6feb1a3 100644
28959 --- a/drivers/gpu/drm/radeon/radeon_fence.c
28960 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
28961 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
28962 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28965 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28966 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28967 if (!rdev->cp.ready)
28968 /* FIXME: cp is not running assume everythings is done right
28970 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
28973 radeon_fence_write(rdev, 0);
28974 - atomic_set(&rdev->fence_drv.seq, 0);
28975 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28976 INIT_LIST_HEAD(&rdev->fence_drv.created);
28977 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28978 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28979 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
28980 index 48b7cea..342236f 100644
28981 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
28982 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
28983 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
28984 request = compat_alloc_user_space(sizeof(*request));
28985 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28986 || __put_user(req32.param, &request->param)
28987 - || __put_user((void __user *)(unsigned long)req32.value,
28988 + || __put_user((unsigned long)req32.value,
28992 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
28993 index 00da384..32f972d 100644
28994 --- a/drivers/gpu/drm/radeon/radeon_irq.c
28995 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
28996 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
29000 - atomic_inc(&dev_priv->swi_emitted);
29001 - ret = atomic_read(&dev_priv->swi_emitted);
29002 + atomic_inc_unchecked(&dev_priv->swi_emitted);
29003 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
29006 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
29007 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
29008 drm_radeon_private_t *dev_priv =
29009 (drm_radeon_private_t *) dev->dev_private;
29011 - atomic_set(&dev_priv->swi_emitted, 0);
29012 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
29013 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
29015 dev->max_vblank_count = 0x001fffff;
29016 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
29017 index e8422ae..d22d4a8 100644
29018 --- a/drivers/gpu/drm/radeon/radeon_state.c
29019 +++ b/drivers/gpu/drm/radeon/radeon_state.c
29020 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
29021 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
29022 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
29024 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29025 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
29026 sarea_priv->nbox * sizeof(depth_boxes[0])))
29029 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
29031 drm_radeon_private_t *dev_priv = dev->dev_private;
29032 drm_radeon_getparam_t *param = data;
29036 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
29038 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
29039 index 0b5468b..9c4b308 100644
29040 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
29041 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
29042 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
29044 if (unlikely(ttm_vm_ops == NULL)) {
29045 ttm_vm_ops = vma->vm_ops;
29046 - radeon_ttm_vm_ops = *ttm_vm_ops;
29047 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29048 + pax_open_kernel();
29049 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
29050 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
29051 + pax_close_kernel();
29053 vma->vm_ops = &radeon_ttm_vm_ops;
29055 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
29056 index a9049ed..501f284 100644
29057 --- a/drivers/gpu/drm/radeon/rs690.c
29058 +++ b/drivers/gpu/drm/radeon/rs690.c
29059 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
29060 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
29061 rdev->pm.sideport_bandwidth.full)
29062 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
29063 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
29064 + read_delay_latency.full = dfixed_const(800 * 1000);
29065 read_delay_latency.full = dfixed_div(read_delay_latency,
29066 rdev->pm.igp_sideport_mclk);
29067 + a.full = dfixed_const(370);
29068 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
29070 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
29071 rdev->pm.k8_bandwidth.full)
29072 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
29073 index 727e93d..1565650 100644
29074 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
29075 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
29076 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
29077 static int ttm_pool_mm_shrink(struct shrinker *shrink,
29078 struct shrink_control *sc)
29080 - static atomic_t start_pool = ATOMIC_INIT(0);
29081 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
29083 - unsigned pool_offset = atomic_add_return(1, &start_pool);
29084 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29085 struct ttm_page_pool *pool;
29086 int shrink_pages = sc->nr_to_scan;
29088 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
29089 index 9cf87d9..2000b7d 100644
29090 --- a/drivers/gpu/drm/via/via_drv.h
29091 +++ b/drivers/gpu/drm/via/via_drv.h
29092 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29093 typedef uint32_t maskarray_t[5];
29095 typedef struct drm_via_irq {
29096 - atomic_t irq_received;
29097 + atomic_unchecked_t irq_received;
29098 uint32_t pending_mask;
29099 uint32_t enable_mask;
29100 wait_queue_head_t irq_queue;
29101 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
29102 struct timeval last_vblank;
29103 int last_vblank_valid;
29104 unsigned usec_per_vblank;
29105 - atomic_t vbl_received;
29106 + atomic_unchecked_t vbl_received;
29107 drm_via_state_t hc_state;
29108 char pci_buf[VIA_PCI_BUF_SIZE];
29109 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29110 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
29111 index d391f48..10c8ca3 100644
29112 --- a/drivers/gpu/drm/via/via_irq.c
29113 +++ b/drivers/gpu/drm/via/via_irq.c
29114 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
29118 - return atomic_read(&dev_priv->vbl_received);
29119 + return atomic_read_unchecked(&dev_priv->vbl_received);
29122 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29123 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29125 status = VIA_READ(VIA_REG_INTERRUPT);
29126 if (status & VIA_IRQ_VBLANK_PENDING) {
29127 - atomic_inc(&dev_priv->vbl_received);
29128 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29129 + atomic_inc_unchecked(&dev_priv->vbl_received);
29130 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29131 do_gettimeofday(&cur_vblank);
29132 if (dev_priv->last_vblank_valid) {
29133 dev_priv->usec_per_vblank =
29134 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29135 dev_priv->last_vblank = cur_vblank;
29136 dev_priv->last_vblank_valid = 1;
29138 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29139 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29140 DRM_DEBUG("US per vblank is: %u\n",
29141 dev_priv->usec_per_vblank);
29143 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29145 for (i = 0; i < dev_priv->num_irqs; ++i) {
29146 if (status & cur_irq->pending_mask) {
29147 - atomic_inc(&cur_irq->irq_received);
29148 + atomic_inc_unchecked(&cur_irq->irq_received);
29149 DRM_WAKEUP(&cur_irq->irq_queue);
29151 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29152 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
29153 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29154 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29156 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29157 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29159 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29160 (((cur_irq_sequence =
29161 - atomic_read(&cur_irq->irq_received)) -
29162 + atomic_read_unchecked(&cur_irq->irq_received)) -
29163 *sequence) <= (1 << 23)));
29165 *sequence = cur_irq_sequence;
29166 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
29169 for (i = 0; i < dev_priv->num_irqs; ++i) {
29170 - atomic_set(&cur_irq->irq_received, 0);
29171 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29172 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29173 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29174 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29175 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
29176 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29177 case VIA_IRQ_RELATIVE:
29178 irqwait->request.sequence +=
29179 - atomic_read(&cur_irq->irq_received);
29180 + atomic_read_unchecked(&cur_irq->irq_received);
29181 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29182 case VIA_IRQ_ABSOLUTE:
29184 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29185 index dc27970..f18b008 100644
29186 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29187 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29188 @@ -260,7 +260,7 @@ struct vmw_private {
29189 * Fencing and IRQs.
29192 - atomic_t marker_seq;
29193 + atomic_unchecked_t marker_seq;
29194 wait_queue_head_t fence_queue;
29195 wait_queue_head_t fifo_queue;
29196 int fence_queue_waiters; /* Protected by hw_mutex */
29197 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29198 index a0c2f12..68ae6cb 100644
29199 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29200 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29201 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
29202 (unsigned int) min,
29203 (unsigned int) fifo->capabilities);
29205 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
29206 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
29207 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
29208 vmw_marker_queue_init(&fifo->marker_queue);
29209 return vmw_fifo_send_fence(dev_priv, &dummy);
29210 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
29212 iowrite32(bytes, fifo_mem +
29213 SVGA_FIFO_RESERVED);
29214 - return fifo_mem + (next_cmd >> 2);
29215 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
29217 need_bounce = true;
29219 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
29221 fm = vmw_fifo_reserve(dev_priv, bytes);
29222 if (unlikely(fm == NULL)) {
29223 - *seqno = atomic_read(&dev_priv->marker_seq);
29224 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
29226 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
29228 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
29232 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
29233 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
29234 } while (*seqno == 0);
29236 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29237 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29238 index cabc95f..14b3d77 100644
29239 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29240 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29241 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
29242 * emitted. Then the fence is stale and signaled.
29245 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
29246 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
29250 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
29253 down_read(&fifo_state->rwsem);
29254 - signal_seq = atomic_read(&dev_priv->marker_seq);
29255 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
29259 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29260 index 8a8725c..afed796 100644
29261 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29262 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29263 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
29264 while (!vmw_lag_lt(queue, us)) {
29265 spin_lock(&queue->lock);
29266 if (list_empty(&queue->head))
29267 - seqno = atomic_read(&dev_priv->marker_seq);
29268 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
29270 marker = list_first_entry(&queue->head,
29271 struct vmw_marker, head);
29272 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
29273 index bb656d8..4169fca 100644
29274 --- a/drivers/hid/hid-core.c
29275 +++ b/drivers/hid/hid-core.c
29276 @@ -2012,7 +2012,7 @@ static bool hid_ignore(struct hid_device *hdev)
29278 int hid_add_device(struct hid_device *hdev)
29280 - static atomic_t id = ATOMIC_INIT(0);
29281 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29284 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29285 @@ -2027,7 +2027,7 @@ int hid_add_device(struct hid_device *hdev)
29286 /* XXX hack, any other cleaner solution after the driver core
29287 * is converted to allow more than 20 bytes as the device name? */
29288 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29289 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29290 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29292 hid_debug_register(hdev, dev_name(&hdev->dev));
29293 ret = device_add(&hdev->dev);
29294 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
29295 index 4ef02b2..8a96831 100644
29296 --- a/drivers/hid/usbhid/hiddev.c
29297 +++ b/drivers/hid/usbhid/hiddev.c
29298 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29301 case HIDIOCAPPLICATION:
29302 - if (arg < 0 || arg >= hid->maxapplication)
29303 + if (arg >= hid->maxapplication)
29306 for (i = 0; i < hid->maxcollection; i++)
29307 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
29308 index 4065374..10ed7dc 100644
29309 --- a/drivers/hv/channel.c
29310 +++ b/drivers/hv/channel.c
29311 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
29315 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
29316 - atomic_inc(&vmbus_connection.next_gpadl_handle);
29317 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
29318 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
29320 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
29322 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
29323 index 0fb100e..baf87e5 100644
29324 --- a/drivers/hv/hv.c
29325 +++ b/drivers/hv/hv.c
29326 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
29327 u64 output_address = (output) ? virt_to_phys(output) : 0;
29328 u32 output_address_hi = output_address >> 32;
29329 u32 output_address_lo = output_address & 0xFFFFFFFF;
29330 - void *hypercall_page = hv_context.hypercall_page;
29331 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
29333 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
29334 "=a"(hv_status_lo) : "d" (control_hi),
29335 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
29336 index 0aee112..b72d21f 100644
29337 --- a/drivers/hv/hyperv_vmbus.h
29338 +++ b/drivers/hv/hyperv_vmbus.h
29339 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
29340 struct vmbus_connection {
29341 enum vmbus_connect_state conn_state;
29343 - atomic_t next_gpadl_handle;
29344 + atomic_unchecked_t next_gpadl_handle;
29347 * Represents channel interrupts. Each bit position represents a
29348 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
29349 index d2d0a2a..90b8f4d 100644
29350 --- a/drivers/hv/vmbus_drv.c
29351 +++ b/drivers/hv/vmbus_drv.c
29352 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
29356 - static atomic_t device_num = ATOMIC_INIT(0);
29357 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
29359 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
29360 - atomic_inc_return(&device_num));
29361 + atomic_inc_return_unchecked(&device_num));
29363 child_device_obj->device.bus = &hv_bus;
29364 child_device_obj->device.parent = &hv_acpi_dev->dev;
29365 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
29366 index 66f6729..2d6de0a 100644
29367 --- a/drivers/hwmon/acpi_power_meter.c
29368 +++ b/drivers/hwmon/acpi_power_meter.c
29369 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
29376 mutex_lock(&resource->lock);
29377 resource->trip[attr->index - 7] = temp;
29378 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
29379 index 5357925..6cf0418 100644
29380 --- a/drivers/hwmon/sht15.c
29381 +++ b/drivers/hwmon/sht15.c
29382 @@ -166,7 +166,7 @@ struct sht15_data {
29384 bool supply_uV_valid;
29385 struct work_struct update_supply_work;
29386 - atomic_t interrupt_handled;
29387 + atomic_unchecked_t interrupt_handled;
29391 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
29394 gpio_direction_input(data->pdata->gpio_data);
29395 - atomic_set(&data->interrupt_handled, 0);
29396 + atomic_set_unchecked(&data->interrupt_handled, 0);
29398 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29399 if (gpio_get_value(data->pdata->gpio_data) == 0) {
29400 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
29401 /* Only relevant if the interrupt hasn't occurred. */
29402 - if (!atomic_read(&data->interrupt_handled))
29403 + if (!atomic_read_unchecked(&data->interrupt_handled))
29404 schedule_work(&data->read_work);
29406 ret = wait_event_timeout(data->wait_queue,
29407 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
29409 /* First disable the interrupt */
29410 disable_irq_nosync(irq);
29411 - atomic_inc(&data->interrupt_handled);
29412 + atomic_inc_unchecked(&data->interrupt_handled);
29413 /* Then schedule a reading work struct */
29414 if (data->state != SHT15_READING_NOTHING)
29415 schedule_work(&data->read_work);
29416 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
29417 * If not, then start the interrupt again - care here as could
29418 * have gone low in meantime so verify it hasn't!
29420 - atomic_set(&data->interrupt_handled, 0);
29421 + atomic_set_unchecked(&data->interrupt_handled, 0);
29422 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29423 /* If still not occurred or another handler has been scheduled */
29424 if (gpio_get_value(data->pdata->gpio_data)
29425 - || atomic_read(&data->interrupt_handled))
29426 + || atomic_read_unchecked(&data->interrupt_handled))
29430 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
29431 index 378fcb5..5e91fa8 100644
29432 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
29433 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
29435 extern struct i2c_adapter amd756_smbus;
29437 static struct i2c_adapter *s4882_adapter;
29438 -static struct i2c_algorithm *s4882_algo;
29439 +static i2c_algorithm_no_const *s4882_algo;
29441 /* Wrapper access functions for multiplexed SMBus */
29442 static DEFINE_MUTEX(amd756_lock);
29443 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
29444 index 29015eb..af2d8e9 100644
29445 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
29446 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
29448 extern struct i2c_adapter *nforce2_smbus;
29450 static struct i2c_adapter *s4985_adapter;
29451 -static struct i2c_algorithm *s4985_algo;
29452 +static i2c_algorithm_no_const *s4985_algo;
29454 /* Wrapper access functions for multiplexed SMBus */
29455 static DEFINE_MUTEX(nforce2_lock);
29456 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
29457 index d7a4833..7fae376 100644
29458 --- a/drivers/i2c/i2c-mux.c
29459 +++ b/drivers/i2c/i2c-mux.c
29461 /* multiplexer per channel data */
29462 struct i2c_mux_priv {
29463 struct i2c_adapter adap;
29464 - struct i2c_algorithm algo;
29465 + i2c_algorithm_no_const algo;
29467 struct i2c_adapter *parent;
29468 void *mux_dev; /* the mux chip/device */
29469 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
29470 index 57d00ca..0145194 100644
29471 --- a/drivers/ide/aec62xx.c
29472 +++ b/drivers/ide/aec62xx.c
29473 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
29474 .cable_detect = atp86x_cable_detect,
29477 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
29478 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
29481 .init_chipset = init_chipset_aec62xx,
29482 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
29483 index 2c8016a..911a27c 100644
29484 --- a/drivers/ide/alim15x3.c
29485 +++ b/drivers/ide/alim15x3.c
29486 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
29487 .dma_sff_read_status = ide_dma_sff_read_status,
29490 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
29491 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
29493 .init_chipset = init_chipset_ali15x3,
29494 .init_hwif = init_hwif_ali15x3,
29495 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
29496 index 3747b25..56fc995 100644
29497 --- a/drivers/ide/amd74xx.c
29498 +++ b/drivers/ide/amd74xx.c
29499 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
29500 .udma_mask = udma, \
29503 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
29504 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
29505 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
29506 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
29507 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
29508 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
29509 index 15f0ead..cb43480 100644
29510 --- a/drivers/ide/atiixp.c
29511 +++ b/drivers/ide/atiixp.c
29512 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
29513 .cable_detect = atiixp_cable_detect,
29516 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
29517 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
29518 { /* 0: IXP200/300/400/700 */
29520 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
29521 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
29522 index 5f80312..d1fc438 100644
29523 --- a/drivers/ide/cmd64x.c
29524 +++ b/drivers/ide/cmd64x.c
29525 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
29526 .dma_sff_read_status = ide_dma_sff_read_status,
29529 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
29530 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
29533 .init_chipset = init_chipset_cmd64x,
29534 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
29535 index 2c1e5f7..1444762 100644
29536 --- a/drivers/ide/cs5520.c
29537 +++ b/drivers/ide/cs5520.c
29538 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
29539 .set_dma_mode = cs5520_set_dma_mode,
29542 -static const struct ide_port_info cyrix_chipset __devinitdata = {
29543 +static const struct ide_port_info cyrix_chipset __devinitconst = {
29545 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
29546 .port_ops = &cs5520_port_ops,
29547 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
29548 index 4dc4eb9..49b40ad 100644
29549 --- a/drivers/ide/cs5530.c
29550 +++ b/drivers/ide/cs5530.c
29551 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
29552 .udma_filter = cs5530_udma_filter,
29555 -static const struct ide_port_info cs5530_chipset __devinitdata = {
29556 +static const struct ide_port_info cs5530_chipset __devinitconst = {
29558 .init_chipset = init_chipset_cs5530,
29559 .init_hwif = init_hwif_cs5530,
29560 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
29561 index 5059faf..18d4c85 100644
29562 --- a/drivers/ide/cs5535.c
29563 +++ b/drivers/ide/cs5535.c
29564 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
29565 .cable_detect = cs5535_cable_detect,
29568 -static const struct ide_port_info cs5535_chipset __devinitdata = {
29569 +static const struct ide_port_info cs5535_chipset __devinitconst = {
29571 .port_ops = &cs5535_port_ops,
29572 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
29573 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
29574 index 847553f..3ffb49d 100644
29575 --- a/drivers/ide/cy82c693.c
29576 +++ b/drivers/ide/cy82c693.c
29577 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
29578 .set_dma_mode = cy82c693_set_dma_mode,
29581 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
29582 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
29584 .init_iops = init_iops_cy82c693,
29585 .port_ops = &cy82c693_port_ops,
29586 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
29587 index 58c51cd..4aec3b8 100644
29588 --- a/drivers/ide/hpt366.c
29589 +++ b/drivers/ide/hpt366.c
29590 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
29594 -static const struct hpt_info hpt36x __devinitdata = {
29595 +static const struct hpt_info hpt36x __devinitconst = {
29596 .chip_name = "HPT36x",
29597 .chip_type = HPT36x,
29598 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
29599 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
29600 .timings = &hpt36x_timings
29603 -static const struct hpt_info hpt370 __devinitdata = {
29604 +static const struct hpt_info hpt370 __devinitconst = {
29605 .chip_name = "HPT370",
29606 .chip_type = HPT370,
29607 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29608 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
29609 .timings = &hpt37x_timings
29612 -static const struct hpt_info hpt370a __devinitdata = {
29613 +static const struct hpt_info hpt370a __devinitconst = {
29614 .chip_name = "HPT370A",
29615 .chip_type = HPT370A,
29616 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29617 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
29618 .timings = &hpt37x_timings
29621 -static const struct hpt_info hpt374 __devinitdata = {
29622 +static const struct hpt_info hpt374 __devinitconst = {
29623 .chip_name = "HPT374",
29624 .chip_type = HPT374,
29625 .udma_mask = ATA_UDMA5,
29626 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
29627 .timings = &hpt37x_timings
29630 -static const struct hpt_info hpt372 __devinitdata = {
29631 +static const struct hpt_info hpt372 __devinitconst = {
29632 .chip_name = "HPT372",
29633 .chip_type = HPT372,
29634 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29635 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
29636 .timings = &hpt37x_timings
29639 -static const struct hpt_info hpt372a __devinitdata = {
29640 +static const struct hpt_info hpt372a __devinitconst = {
29641 .chip_name = "HPT372A",
29642 .chip_type = HPT372A,
29643 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29644 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
29645 .timings = &hpt37x_timings
29648 -static const struct hpt_info hpt302 __devinitdata = {
29649 +static const struct hpt_info hpt302 __devinitconst = {
29650 .chip_name = "HPT302",
29651 .chip_type = HPT302,
29652 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29653 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
29654 .timings = &hpt37x_timings
29657 -static const struct hpt_info hpt371 __devinitdata = {
29658 +static const struct hpt_info hpt371 __devinitconst = {
29659 .chip_name = "HPT371",
29660 .chip_type = HPT371,
29661 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29662 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
29663 .timings = &hpt37x_timings
29666 -static const struct hpt_info hpt372n __devinitdata = {
29667 +static const struct hpt_info hpt372n __devinitconst = {
29668 .chip_name = "HPT372N",
29669 .chip_type = HPT372N,
29670 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29671 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
29672 .timings = &hpt37x_timings
29675 -static const struct hpt_info hpt302n __devinitdata = {
29676 +static const struct hpt_info hpt302n __devinitconst = {
29677 .chip_name = "HPT302N",
29678 .chip_type = HPT302N,
29679 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29680 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
29681 .timings = &hpt37x_timings
29684 -static const struct hpt_info hpt371n __devinitdata = {
29685 +static const struct hpt_info hpt371n __devinitconst = {
29686 .chip_name = "HPT371N",
29687 .chip_type = HPT371N,
29688 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29689 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
29690 .dma_sff_read_status = ide_dma_sff_read_status,
29693 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
29694 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
29697 .init_chipset = init_chipset_hpt366,
29698 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
29699 index 8126824..55a2798 100644
29700 --- a/drivers/ide/ide-cd.c
29701 +++ b/drivers/ide/ide-cd.c
29702 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
29703 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
29704 if ((unsigned long)buf & alignment
29705 || blk_rq_bytes(rq) & q->dma_pad_mask
29706 - || object_is_on_stack(buf))
29707 + || object_starts_on_stack(buf))
29711 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
29712 index a743e68..1cfd674 100644
29713 --- a/drivers/ide/ide-pci-generic.c
29714 +++ b/drivers/ide/ide-pci-generic.c
29715 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
29716 .udma_mask = ATA_UDMA6, \
29719 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
29720 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
29722 DECLARE_GENERIC_PCI_DEV(0),
29724 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
29725 index 560e66d..d5dd180 100644
29726 --- a/drivers/ide/it8172.c
29727 +++ b/drivers/ide/it8172.c
29728 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
29729 .set_dma_mode = it8172_set_dma_mode,
29732 -static const struct ide_port_info it8172_port_info __devinitdata = {
29733 +static const struct ide_port_info it8172_port_info __devinitconst = {
29735 .port_ops = &it8172_port_ops,
29736 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
29737 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
29738 index 46816ba..1847aeb 100644
29739 --- a/drivers/ide/it8213.c
29740 +++ b/drivers/ide/it8213.c
29741 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
29742 .cable_detect = it8213_cable_detect,
29745 -static const struct ide_port_info it8213_chipset __devinitdata = {
29746 +static const struct ide_port_info it8213_chipset __devinitconst = {
29748 .enablebits = { {0x41, 0x80, 0x80} },
29749 .port_ops = &it8213_port_ops,
29750 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
29751 index 2e3169f..c5611db 100644
29752 --- a/drivers/ide/it821x.c
29753 +++ b/drivers/ide/it821x.c
29754 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
29755 .cable_detect = it821x_cable_detect,
29758 -static const struct ide_port_info it821x_chipset __devinitdata = {
29759 +static const struct ide_port_info it821x_chipset __devinitconst = {
29761 .init_chipset = init_chipset_it821x,
29762 .init_hwif = init_hwif_it821x,
29763 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
29764 index 74c2c4a..efddd7d 100644
29765 --- a/drivers/ide/jmicron.c
29766 +++ b/drivers/ide/jmicron.c
29767 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
29768 .cable_detect = jmicron_cable_detect,
29771 -static const struct ide_port_info jmicron_chipset __devinitdata = {
29772 +static const struct ide_port_info jmicron_chipset __devinitconst = {
29774 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
29775 .port_ops = &jmicron_port_ops,
29776 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
29777 index 95327a2..73f78d8 100644
29778 --- a/drivers/ide/ns87415.c
29779 +++ b/drivers/ide/ns87415.c
29780 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
29781 .dma_sff_read_status = superio_dma_sff_read_status,
29784 -static const struct ide_port_info ns87415_chipset __devinitdata = {
29785 +static const struct ide_port_info ns87415_chipset __devinitconst = {
29787 .init_hwif = init_hwif_ns87415,
29788 .tp_ops = &ns87415_tp_ops,
29789 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
29790 index 1a53a4c..39edc66 100644
29791 --- a/drivers/ide/opti621.c
29792 +++ b/drivers/ide/opti621.c
29793 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
29794 .set_pio_mode = opti621_set_pio_mode,
29797 -static const struct ide_port_info opti621_chipset __devinitdata = {
29798 +static const struct ide_port_info opti621_chipset __devinitconst = {
29800 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
29801 .port_ops = &opti621_port_ops,
29802 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
29803 index 9546fe2..2e5ceb6 100644
29804 --- a/drivers/ide/pdc202xx_new.c
29805 +++ b/drivers/ide/pdc202xx_new.c
29806 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
29807 .udma_mask = udma, \
29810 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
29811 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
29812 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
29813 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
29815 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
29816 index 3a35ec6..5634510 100644
29817 --- a/drivers/ide/pdc202xx_old.c
29818 +++ b/drivers/ide/pdc202xx_old.c
29819 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
29820 .max_sectors = sectors, \
29823 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
29824 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
29825 { /* 0: PDC20246 */
29827 .init_chipset = init_chipset_pdc202xx,
29828 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
29829 index 1892e81..fe0fd60 100644
29830 --- a/drivers/ide/piix.c
29831 +++ b/drivers/ide/piix.c
29832 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
29833 .udma_mask = udma, \
29836 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
29837 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
29840 * MPIIX actually has only a single IDE channel mapped to
29841 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
29842 index a6414a8..c04173e 100644
29843 --- a/drivers/ide/rz1000.c
29844 +++ b/drivers/ide/rz1000.c
29845 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
29849 -static const struct ide_port_info rz1000_chipset __devinitdata = {
29850 +static const struct ide_port_info rz1000_chipset __devinitconst = {
29852 .host_flags = IDE_HFLAG_NO_DMA,
29854 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
29855 index 356b9b5..d4758eb 100644
29856 --- a/drivers/ide/sc1200.c
29857 +++ b/drivers/ide/sc1200.c
29858 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
29859 .dma_sff_read_status = ide_dma_sff_read_status,
29862 -static const struct ide_port_info sc1200_chipset __devinitdata = {
29863 +static const struct ide_port_info sc1200_chipset __devinitconst = {
29865 .port_ops = &sc1200_port_ops,
29866 .dma_ops = &sc1200_dma_ops,
29867 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
29868 index b7f5b0c..9701038 100644
29869 --- a/drivers/ide/scc_pata.c
29870 +++ b/drivers/ide/scc_pata.c
29871 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
29872 .dma_sff_read_status = scc_dma_sff_read_status,
29875 -static const struct ide_port_info scc_chipset __devinitdata = {
29876 +static const struct ide_port_info scc_chipset __devinitconst = {
29878 .init_iops = init_iops_scc,
29879 .init_dma = scc_init_dma,
29880 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
29881 index 35fb8da..24d72ef 100644
29882 --- a/drivers/ide/serverworks.c
29883 +++ b/drivers/ide/serverworks.c
29884 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
29885 .cable_detect = svwks_cable_detect,
29888 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
29889 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
29892 .init_chipset = init_chipset_svwks,
29893 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
29894 index ddeda44..46f7e30 100644
29895 --- a/drivers/ide/siimage.c
29896 +++ b/drivers/ide/siimage.c
29897 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
29898 .udma_mask = ATA_UDMA6, \
29901 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
29902 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
29903 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
29904 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
29906 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
29907 index 4a00225..09e61b4 100644
29908 --- a/drivers/ide/sis5513.c
29909 +++ b/drivers/ide/sis5513.c
29910 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
29911 .cable_detect = sis_cable_detect,
29914 -static const struct ide_port_info sis5513_chipset __devinitdata = {
29915 +static const struct ide_port_info sis5513_chipset __devinitconst = {
29917 .init_chipset = init_chipset_sis5513,
29918 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
29919 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
29920 index f21dc2a..d051cd2 100644
29921 --- a/drivers/ide/sl82c105.c
29922 +++ b/drivers/ide/sl82c105.c
29923 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
29924 .dma_sff_read_status = ide_dma_sff_read_status,
29927 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
29928 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
29930 .init_chipset = init_chipset_sl82c105,
29931 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
29932 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
29933 index 864ffe0..863a5e9 100644
29934 --- a/drivers/ide/slc90e66.c
29935 +++ b/drivers/ide/slc90e66.c
29936 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
29937 .cable_detect = slc90e66_cable_detect,
29940 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
29941 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
29943 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
29944 .port_ops = &slc90e66_port_ops,
29945 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
29946 index 4799d5c..1794678 100644
29947 --- a/drivers/ide/tc86c001.c
29948 +++ b/drivers/ide/tc86c001.c
29949 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
29950 .dma_sff_read_status = ide_dma_sff_read_status,
29953 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
29954 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
29956 .init_hwif = init_hwif_tc86c001,
29957 .port_ops = &tc86c001_port_ops,
29958 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
29959 index 281c914..55ce1b8 100644
29960 --- a/drivers/ide/triflex.c
29961 +++ b/drivers/ide/triflex.c
29962 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
29963 .set_dma_mode = triflex_set_mode,
29966 -static const struct ide_port_info triflex_device __devinitdata = {
29967 +static const struct ide_port_info triflex_device __devinitconst = {
29969 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
29970 .port_ops = &triflex_port_ops,
29971 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
29972 index 4b42ca0..e494a98 100644
29973 --- a/drivers/ide/trm290.c
29974 +++ b/drivers/ide/trm290.c
29975 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
29976 .dma_check = trm290_dma_check,
29979 -static const struct ide_port_info trm290_chipset __devinitdata = {
29980 +static const struct ide_port_info trm290_chipset __devinitconst = {
29982 .init_hwif = init_hwif_trm290,
29983 .tp_ops = &trm290_tp_ops,
29984 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
29985 index f46f49c..eb77678 100644
29986 --- a/drivers/ide/via82cxxx.c
29987 +++ b/drivers/ide/via82cxxx.c
29988 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
29989 .cable_detect = via82cxxx_cable_detect,
29992 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
29993 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
29995 .init_chipset = init_chipset_via82cxxx,
29996 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
29997 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
29998 index eb0e2cc..14241c7 100644
29999 --- a/drivers/ieee802154/fakehard.c
30000 +++ b/drivers/ieee802154/fakehard.c
30001 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
30002 phy->transmit_power = 0xbf;
30004 dev->netdev_ops = &fake_ops;
30005 - dev->ml_priv = &fake_mlme;
30006 + dev->ml_priv = (void *)&fake_mlme;
30008 priv = netdev_priv(dev);
30010 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
30011 index 8b72f39..55df4c8 100644
30012 --- a/drivers/infiniband/core/cm.c
30013 +++ b/drivers/infiniband/core/cm.c
30014 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
30016 struct cm_counter_group {
30017 struct kobject obj;
30018 - atomic_long_t counter[CM_ATTR_COUNT];
30019 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
30022 struct cm_counter_attribute {
30023 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
30024 struct ib_mad_send_buf *msg = NULL;
30027 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30028 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30029 counter[CM_REQ_COUNTER]);
30031 /* Quick state check to discard duplicate REQs. */
30032 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
30036 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30037 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30038 counter[CM_REP_COUNTER]);
30039 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
30041 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
30042 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
30043 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
30044 spin_unlock_irq(&cm_id_priv->lock);
30045 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30046 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30047 counter[CM_RTU_COUNTER]);
30050 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
30051 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
30052 dreq_msg->local_comm_id);
30054 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30055 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30056 counter[CM_DREQ_COUNTER]);
30057 cm_issue_drep(work->port, work->mad_recv_wc);
30059 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
30060 case IB_CM_MRA_REP_RCVD:
30062 case IB_CM_TIMEWAIT:
30063 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30064 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30065 counter[CM_DREQ_COUNTER]);
30066 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30068 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
30071 case IB_CM_DREQ_RCVD:
30072 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30073 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30074 counter[CM_DREQ_COUNTER]);
30077 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
30078 ib_modify_mad(cm_id_priv->av.port->mad_agent,
30079 cm_id_priv->msg, timeout)) {
30080 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
30081 - atomic_long_inc(&work->port->
30082 + atomic_long_inc_unchecked(&work->port->
30083 counter_group[CM_RECV_DUPLICATES].
30084 counter[CM_MRA_COUNTER]);
30086 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
30088 case IB_CM_MRA_REQ_RCVD:
30089 case IB_CM_MRA_REP_RCVD:
30090 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30091 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30092 counter[CM_MRA_COUNTER]);
30095 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
30096 case IB_CM_LAP_IDLE:
30098 case IB_CM_MRA_LAP_SENT:
30099 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30100 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30101 counter[CM_LAP_COUNTER]);
30102 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30104 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
30107 case IB_CM_LAP_RCVD:
30108 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30109 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30110 counter[CM_LAP_COUNTER]);
30113 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
30114 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30115 if (cur_cm_id_priv) {
30116 spin_unlock_irq(&cm.lock);
30117 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30118 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30119 counter[CM_SIDR_REQ_COUNTER]);
30120 goto out; /* Duplicate message. */
30122 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
30123 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30126 - atomic_long_add(1 + msg->retries,
30127 + atomic_long_add_unchecked(1 + msg->retries,
30128 &port->counter_group[CM_XMIT].counter[attr_index]);
30130 - atomic_long_add(msg->retries,
30131 + atomic_long_add_unchecked(msg->retries,
30132 &port->counter_group[CM_XMIT_RETRIES].
30133 counter[attr_index]);
30135 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
30138 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30139 - atomic_long_inc(&port->counter_group[CM_RECV].
30140 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30141 counter[attr_id - CM_ATTR_ID_OFFSET]);
30143 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30144 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
30145 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30147 return sprintf(buf, "%ld\n",
30148 - atomic_long_read(&group->counter[cm_attr->index]));
30149 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30152 static const struct sysfs_ops cm_counter_ops = {
30153 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
30154 index 176c8f9..2627b62 100644
30155 --- a/drivers/infiniband/core/fmr_pool.c
30156 +++ b/drivers/infiniband/core/fmr_pool.c
30157 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
30159 struct task_struct *thread;
30161 - atomic_t req_ser;
30162 - atomic_t flush_ser;
30163 + atomic_unchecked_t req_ser;
30164 + atomic_unchecked_t flush_ser;
30166 wait_queue_head_t force_wait;
30168 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30169 struct ib_fmr_pool *pool = pool_ptr;
30172 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30173 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30174 ib_fmr_batch_release(pool);
30176 - atomic_inc(&pool->flush_ser);
30177 + atomic_inc_unchecked(&pool->flush_ser);
30178 wake_up_interruptible(&pool->force_wait);
30180 if (pool->flush_function)
30181 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30184 set_current_state(TASK_INTERRUPTIBLE);
30185 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30186 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30187 !kthread_should_stop())
30189 __set_current_state(TASK_RUNNING);
30190 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
30191 pool->dirty_watermark = params->dirty_watermark;
30192 pool->dirty_len = 0;
30193 spin_lock_init(&pool->pool_lock);
30194 - atomic_set(&pool->req_ser, 0);
30195 - atomic_set(&pool->flush_ser, 0);
30196 + atomic_set_unchecked(&pool->req_ser, 0);
30197 + atomic_set_unchecked(&pool->flush_ser, 0);
30198 init_waitqueue_head(&pool->force_wait);
30200 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30201 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
30203 spin_unlock_irq(&pool->pool_lock);
30205 - serial = atomic_inc_return(&pool->req_ser);
30206 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30207 wake_up_process(pool->thread);
30209 if (wait_event_interruptible(pool->force_wait,
30210 - atomic_read(&pool->flush_ser) - serial >= 0))
30211 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30215 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
30217 list_add_tail(&fmr->list, &pool->dirty_list);
30218 if (++pool->dirty_len >= pool->dirty_watermark) {
30219 - atomic_inc(&pool->req_ser);
30220 + atomic_inc_unchecked(&pool->req_ser);
30221 wake_up_process(pool->thread);
30224 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
30225 index 40c8353..946b0e4 100644
30226 --- a/drivers/infiniband/hw/cxgb4/mem.c
30227 +++ b/drivers/infiniband/hw/cxgb4/mem.c
30228 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30230 struct fw_ri_tpte tpt;
30232 - static atomic_t key;
30233 + static atomic_unchecked_t key;
30235 if (c4iw_fatal_error(rdev))
30237 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30238 &rdev->resource.tpt_fifo_lock);
30241 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30242 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30244 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30245 __func__, stag_state, type, pdid, stag_idx);
30246 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
30247 index 79b3dbc..96e5fcc 100644
30248 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
30249 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
30250 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30251 struct ib_atomic_eth *ateth;
30252 struct ipath_ack_entry *e;
30254 - atomic64_t *maddr;
30255 + atomic64_unchecked_t *maddr;
30259 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30260 IB_ACCESS_REMOTE_ATOMIC)))
30261 goto nack_acc_unlck;
30262 /* Perform atomic OP and save result. */
30263 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30264 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30265 sdata = be64_to_cpu(ateth->swap_data);
30266 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30267 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30268 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30269 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30270 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30271 be64_to_cpu(ateth->compare_data),
30273 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
30274 index 1f95bba..9530f87 100644
30275 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
30276 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
30277 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
30278 unsigned long flags;
30281 - atomic64_t *maddr;
30282 + atomic64_unchecked_t *maddr;
30283 enum ib_wc_status send_status;
30286 @@ -382,11 +382,11 @@ again:
30287 IB_ACCESS_REMOTE_ATOMIC)))
30289 /* Perform atomic OP and save result. */
30290 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30291 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30292 sdata = wqe->wr.wr.atomic.compare_add;
30293 *(u64 *) sqp->s_sge.sge.vaddr =
30294 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30295 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30296 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30297 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30298 sdata, wqe->wr.wr.atomic.swap);
30300 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
30301 index 5965b3d..16817fb 100644
30302 --- a/drivers/infiniband/hw/nes/nes.c
30303 +++ b/drivers/infiniband/hw/nes/nes.c
30304 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
30305 LIST_HEAD(nes_adapter_list);
30306 static LIST_HEAD(nes_dev_list);
30308 -atomic_t qps_destroyed;
30309 +atomic_unchecked_t qps_destroyed;
30311 static unsigned int ee_flsh_adapter;
30312 static unsigned int sysfs_nonidx_addr;
30313 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
30314 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30315 struct nes_adapter *nesadapter = nesdev->nesadapter;
30317 - atomic_inc(&qps_destroyed);
30318 + atomic_inc_unchecked(&qps_destroyed);
30320 /* Free the control structures */
30322 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
30323 index 568b4f1..5ea3eff 100644
30324 --- a/drivers/infiniband/hw/nes/nes.h
30325 +++ b/drivers/infiniband/hw/nes/nes.h
30326 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
30327 extern unsigned int wqm_quanta;
30328 extern struct list_head nes_adapter_list;
30330 -extern atomic_t cm_connects;
30331 -extern atomic_t cm_accepts;
30332 -extern atomic_t cm_disconnects;
30333 -extern atomic_t cm_closes;
30334 -extern atomic_t cm_connecteds;
30335 -extern atomic_t cm_connect_reqs;
30336 -extern atomic_t cm_rejects;
30337 -extern atomic_t mod_qp_timouts;
30338 -extern atomic_t qps_created;
30339 -extern atomic_t qps_destroyed;
30340 -extern atomic_t sw_qps_destroyed;
30341 +extern atomic_unchecked_t cm_connects;
30342 +extern atomic_unchecked_t cm_accepts;
30343 +extern atomic_unchecked_t cm_disconnects;
30344 +extern atomic_unchecked_t cm_closes;
30345 +extern atomic_unchecked_t cm_connecteds;
30346 +extern atomic_unchecked_t cm_connect_reqs;
30347 +extern atomic_unchecked_t cm_rejects;
30348 +extern atomic_unchecked_t mod_qp_timouts;
30349 +extern atomic_unchecked_t qps_created;
30350 +extern atomic_unchecked_t qps_destroyed;
30351 +extern atomic_unchecked_t sw_qps_destroyed;
30352 extern u32 mh_detected;
30353 extern u32 mh_pauses_sent;
30354 extern u32 cm_packets_sent;
30355 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
30356 extern u32 cm_packets_received;
30357 extern u32 cm_packets_dropped;
30358 extern u32 cm_packets_retrans;
30359 -extern atomic_t cm_listens_created;
30360 -extern atomic_t cm_listens_destroyed;
30361 +extern atomic_unchecked_t cm_listens_created;
30362 +extern atomic_unchecked_t cm_listens_destroyed;
30363 extern u32 cm_backlog_drops;
30364 -extern atomic_t cm_loopbacks;
30365 -extern atomic_t cm_nodes_created;
30366 -extern atomic_t cm_nodes_destroyed;
30367 -extern atomic_t cm_accel_dropped_pkts;
30368 -extern atomic_t cm_resets_recvd;
30369 -extern atomic_t pau_qps_created;
30370 -extern atomic_t pau_qps_destroyed;
30371 +extern atomic_unchecked_t cm_loopbacks;
30372 +extern atomic_unchecked_t cm_nodes_created;
30373 +extern atomic_unchecked_t cm_nodes_destroyed;
30374 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30375 +extern atomic_unchecked_t cm_resets_recvd;
30376 +extern atomic_unchecked_t pau_qps_created;
30377 +extern atomic_unchecked_t pau_qps_destroyed;
30379 extern u32 int_mod_timer_init;
30380 extern u32 int_mod_cq_depth_256;
30381 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
30382 index 0a52d72..0642f36 100644
30383 --- a/drivers/infiniband/hw/nes/nes_cm.c
30384 +++ b/drivers/infiniband/hw/nes/nes_cm.c
30385 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30386 u32 cm_packets_retrans;
30387 u32 cm_packets_created;
30388 u32 cm_packets_received;
30389 -atomic_t cm_listens_created;
30390 -atomic_t cm_listens_destroyed;
30391 +atomic_unchecked_t cm_listens_created;
30392 +atomic_unchecked_t cm_listens_destroyed;
30393 u32 cm_backlog_drops;
30394 -atomic_t cm_loopbacks;
30395 -atomic_t cm_nodes_created;
30396 -atomic_t cm_nodes_destroyed;
30397 -atomic_t cm_accel_dropped_pkts;
30398 -atomic_t cm_resets_recvd;
30399 +atomic_unchecked_t cm_loopbacks;
30400 +atomic_unchecked_t cm_nodes_created;
30401 +atomic_unchecked_t cm_nodes_destroyed;
30402 +atomic_unchecked_t cm_accel_dropped_pkts;
30403 +atomic_unchecked_t cm_resets_recvd;
30405 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
30406 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
30407 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
30409 static struct nes_cm_core *g_cm_core;
30411 -atomic_t cm_connects;
30412 -atomic_t cm_accepts;
30413 -atomic_t cm_disconnects;
30414 -atomic_t cm_closes;
30415 -atomic_t cm_connecteds;
30416 -atomic_t cm_connect_reqs;
30417 -atomic_t cm_rejects;
30418 +atomic_unchecked_t cm_connects;
30419 +atomic_unchecked_t cm_accepts;
30420 +atomic_unchecked_t cm_disconnects;
30421 +atomic_unchecked_t cm_closes;
30422 +atomic_unchecked_t cm_connecteds;
30423 +atomic_unchecked_t cm_connect_reqs;
30424 +atomic_unchecked_t cm_rejects;
30426 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
30428 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
30432 - atomic_inc(&cm_listens_destroyed);
30433 + atomic_inc_unchecked(&cm_listens_destroyed);
30435 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30437 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
30440 add_hte_node(cm_core, cm_node);
30441 - atomic_inc(&cm_nodes_created);
30442 + atomic_inc_unchecked(&cm_nodes_created);
30446 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
30449 atomic_dec(&cm_core->node_cnt);
30450 - atomic_inc(&cm_nodes_destroyed);
30451 + atomic_inc_unchecked(&cm_nodes_destroyed);
30452 nesqp = cm_node->nesqp;
30454 nesqp->cm_node = NULL;
30455 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
30457 static void drop_packet(struct sk_buff *skb)
30459 - atomic_inc(&cm_accel_dropped_pkts);
30460 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30461 dev_kfree_skb_any(skb);
30464 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
30467 int reset = 0; /* whether to send reset in case of err.. */
30468 - atomic_inc(&cm_resets_recvd);
30469 + atomic_inc_unchecked(&cm_resets_recvd);
30470 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30471 " refcnt=%d\n", cm_node, cm_node->state,
30472 atomic_read(&cm_node->ref_count));
30473 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
30474 rem_ref_cm_node(cm_node->cm_core, cm_node);
30477 - atomic_inc(&cm_loopbacks);
30478 + atomic_inc_unchecked(&cm_loopbacks);
30479 loopbackremotenode->loopbackpartner = cm_node;
30480 loopbackremotenode->tcp_cntxt.rcv_wscale =
30481 NES_CM_DEFAULT_RCV_WND_SCALE;
30482 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
30483 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
30485 rem_ref_cm_node(cm_core, cm_node);
30486 - atomic_inc(&cm_accel_dropped_pkts);
30487 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30488 dev_kfree_skb_any(skb);
30491 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30493 if ((cm_id) && (cm_id->event_handler)) {
30494 if (issue_disconn) {
30495 - atomic_inc(&cm_disconnects);
30496 + atomic_inc_unchecked(&cm_disconnects);
30497 cm_event.event = IW_CM_EVENT_DISCONNECT;
30498 cm_event.status = disconn_status;
30499 cm_event.local_addr = cm_id->local_addr;
30500 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30504 - atomic_inc(&cm_closes);
30505 + atomic_inc_unchecked(&cm_closes);
30506 nes_disconnect(nesqp, 1);
30508 cm_id->provider_data = nesqp;
30509 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30511 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30512 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30513 - atomic_inc(&cm_accepts);
30514 + atomic_inc_unchecked(&cm_accepts);
30516 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30517 netdev_refcnt_read(nesvnic->netdev));
30518 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
30519 struct nes_cm_core *cm_core;
30522 - atomic_inc(&cm_rejects);
30523 + atomic_inc_unchecked(&cm_rejects);
30524 cm_node = (struct nes_cm_node *)cm_id->provider_data;
30525 loopback = cm_node->loopbackpartner;
30526 cm_core = cm_node->cm_core;
30527 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30528 ntohl(cm_id->local_addr.sin_addr.s_addr),
30529 ntohs(cm_id->local_addr.sin_port));
30531 - atomic_inc(&cm_connects);
30532 + atomic_inc_unchecked(&cm_connects);
30533 nesqp->active_conn = 1;
30535 /* cache the cm_id in the qp */
30536 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
30537 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30540 - atomic_inc(&cm_listens_created);
30541 + atomic_inc_unchecked(&cm_listens_created);
30544 cm_id->add_ref(cm_id);
30545 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
30547 if (nesqp->destroyed)
30549 - atomic_inc(&cm_connecteds);
30550 + atomic_inc_unchecked(&cm_connecteds);
30551 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30552 " local port 0x%04X. jiffies = %lu.\n",
30554 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
30556 cm_id->add_ref(cm_id);
30557 ret = cm_id->event_handler(cm_id, &cm_event);
30558 - atomic_inc(&cm_closes);
30559 + atomic_inc_unchecked(&cm_closes);
30560 cm_event.event = IW_CM_EVENT_CLOSE;
30561 cm_event.status = 0;
30562 cm_event.provider_data = cm_id->provider_data;
30563 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
30565 cm_id = cm_node->cm_id;
30567 - atomic_inc(&cm_connect_reqs);
30568 + atomic_inc_unchecked(&cm_connect_reqs);
30569 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30570 cm_node, cm_id, jiffies);
30572 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
30574 cm_id = cm_node->cm_id;
30576 - atomic_inc(&cm_connect_reqs);
30577 + atomic_inc_unchecked(&cm_connect_reqs);
30578 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30579 cm_node, cm_id, jiffies);
30581 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
30582 index b3b2a24..7bfaf1e 100644
30583 --- a/drivers/infiniband/hw/nes/nes_mgt.c
30584 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
30587 #include "nes_mgt.h"
30589 -atomic_t pau_qps_created;
30590 -atomic_t pau_qps_destroyed;
30591 +atomic_unchecked_t pau_qps_created;
30592 +atomic_unchecked_t pau_qps_destroyed;
30594 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
30596 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
30598 struct sk_buff *skb;
30599 unsigned long flags;
30600 - atomic_inc(&pau_qps_destroyed);
30601 + atomic_inc_unchecked(&pau_qps_destroyed);
30603 /* Free packets that have not yet been forwarded */
30604 /* Lock is acquired by skb_dequeue when removing the skb */
30605 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
30606 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
30607 skb_queue_head_init(&nesqp->pau_list);
30608 spin_lock_init(&nesqp->pau_lock);
30609 - atomic_inc(&pau_qps_created);
30610 + atomic_inc_unchecked(&pau_qps_created);
30611 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
30614 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
30615 index c00d2f3..8834298 100644
30616 --- a/drivers/infiniband/hw/nes/nes_nic.c
30617 +++ b/drivers/infiniband/hw/nes/nes_nic.c
30618 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
30619 target_stat_values[++index] = mh_detected;
30620 target_stat_values[++index] = mh_pauses_sent;
30621 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30622 - target_stat_values[++index] = atomic_read(&cm_connects);
30623 - target_stat_values[++index] = atomic_read(&cm_accepts);
30624 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30625 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30626 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30627 - target_stat_values[++index] = atomic_read(&cm_rejects);
30628 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30629 - target_stat_values[++index] = atomic_read(&qps_created);
30630 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30631 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30632 - target_stat_values[++index] = atomic_read(&cm_closes);
30633 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30634 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30635 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30636 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30637 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30638 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30639 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30640 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30641 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30642 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30643 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30644 target_stat_values[++index] = cm_packets_sent;
30645 target_stat_values[++index] = cm_packets_bounced;
30646 target_stat_values[++index] = cm_packets_created;
30647 target_stat_values[++index] = cm_packets_received;
30648 target_stat_values[++index] = cm_packets_dropped;
30649 target_stat_values[++index] = cm_packets_retrans;
30650 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30651 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30652 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30653 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30654 target_stat_values[++index] = cm_backlog_drops;
30655 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30656 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30657 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30658 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30659 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30660 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30661 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30662 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30663 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30664 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30665 target_stat_values[++index] = nesadapter->free_4kpbl;
30666 target_stat_values[++index] = nesadapter->free_256pbl;
30667 target_stat_values[++index] = int_mod_timer_init;
30668 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
30669 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
30670 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
30671 - target_stat_values[++index] = atomic_read(&pau_qps_created);
30672 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
30673 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
30674 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
30678 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
30679 index 5095bc4..41e8fff 100644
30680 --- a/drivers/infiniband/hw/nes/nes_verbs.c
30681 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
30684 #include <rdma/ib_umem.h>
30686 -atomic_t mod_qp_timouts;
30687 -atomic_t qps_created;
30688 -atomic_t sw_qps_destroyed;
30689 +atomic_unchecked_t mod_qp_timouts;
30690 +atomic_unchecked_t qps_created;
30691 +atomic_unchecked_t sw_qps_destroyed;
30693 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30695 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
30696 if (init_attr->create_flags)
30697 return ERR_PTR(-EINVAL);
30699 - atomic_inc(&qps_created);
30700 + atomic_inc_unchecked(&qps_created);
30701 switch (init_attr->qp_type) {
30703 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30704 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
30705 struct iw_cm_event cm_event;
30708 - atomic_inc(&sw_qps_destroyed);
30709 + atomic_inc_unchecked(&sw_qps_destroyed);
30710 nesqp->destroyed = 1;
30712 /* Blow away the connection if it exists. */
30713 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
30714 index b881bdc..c2e360c 100644
30715 --- a/drivers/infiniband/hw/qib/qib.h
30716 +++ b/drivers/infiniband/hw/qib/qib.h
30718 #include <linux/completion.h>
30719 #include <linux/kref.h>
30720 #include <linux/sched.h>
30721 +#include <linux/slab.h>
30723 #include "qib_common.h"
30724 #include "qib_verbs.h"
30725 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
30726 index c351aa4..e6967c2 100644
30727 --- a/drivers/input/gameport/gameport.c
30728 +++ b/drivers/input/gameport/gameport.c
30729 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
30731 static void gameport_init_port(struct gameport *gameport)
30733 - static atomic_t gameport_no = ATOMIC_INIT(0);
30734 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30736 __module_get(THIS_MODULE);
30738 mutex_init(&gameport->drv_mutex);
30739 device_initialize(&gameport->dev);
30740 dev_set_name(&gameport->dev, "gameport%lu",
30741 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
30742 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30743 gameport->dev.bus = &gameport_bus;
30744 gameport->dev.release = gameport_release_port;
30745 if (gameport->parent)
30746 diff --git a/drivers/input/input.c b/drivers/input/input.c
30747 index da38d97..2aa0b79 100644
30748 --- a/drivers/input/input.c
30749 +++ b/drivers/input/input.c
30750 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
30752 int input_register_device(struct input_dev *dev)
30754 - static atomic_t input_no = ATOMIC_INIT(0);
30755 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30756 struct input_handler *handler;
30759 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
30760 dev->setkeycode = input_default_setkeycode;
30762 dev_set_name(&dev->dev, "input%ld",
30763 - (unsigned long) atomic_inc_return(&input_no) - 1);
30764 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30766 error = device_add(&dev->dev);
30768 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
30769 index b8d8611..7a4a04b 100644
30770 --- a/drivers/input/joystick/sidewinder.c
30771 +++ b/drivers/input/joystick/sidewinder.c
30773 #include <linux/kernel.h>
30774 #include <linux/module.h>
30775 #include <linux/slab.h>
30776 +#include <linux/sched.h>
30777 #include <linux/init.h>
30778 #include <linux/input.h>
30779 #include <linux/gameport.h>
30780 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
30781 index d728875..844c89b 100644
30782 --- a/drivers/input/joystick/xpad.c
30783 +++ b/drivers/input/joystick/xpad.c
30784 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
30786 static int xpad_led_probe(struct usb_xpad *xpad)
30788 - static atomic_t led_seq = ATOMIC_INIT(0);
30789 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
30791 struct xpad_led *led;
30792 struct led_classdev *led_cdev;
30793 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
30797 - led_no = (long)atomic_inc_return(&led_seq) - 1;
30798 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
30800 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
30802 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
30803 index 0110b5a..d3ad144 100644
30804 --- a/drivers/input/mousedev.c
30805 +++ b/drivers/input/mousedev.c
30806 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
30808 spin_unlock_irq(&client->packet_lock);
30810 - if (copy_to_user(buffer, data, count))
30811 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
30815 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
30816 index ba70058..571d25d 100644
30817 --- a/drivers/input/serio/serio.c
30818 +++ b/drivers/input/serio/serio.c
30819 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
30821 static void serio_init_port(struct serio *serio)
30823 - static atomic_t serio_no = ATOMIC_INIT(0);
30824 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
30826 __module_get(THIS_MODULE);
30828 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
30829 mutex_init(&serio->drv_mutex);
30830 device_initialize(&serio->dev);
30831 dev_set_name(&serio->dev, "serio%ld",
30832 - (long)atomic_inc_return(&serio_no) - 1);
30833 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
30834 serio->dev.bus = &serio_bus;
30835 serio->dev.release = serio_release_port;
30836 serio->dev.groups = serio_device_attr_groups;
30837 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
30838 index e44933d..9ba484a 100644
30839 --- a/drivers/isdn/capi/capi.c
30840 +++ b/drivers/isdn/capi/capi.c
30841 @@ -83,8 +83,8 @@ struct capiminor {
30843 struct capi20_appl *ap;
30845 - atomic_t datahandle;
30847 + atomic_unchecked_t datahandle;
30848 + atomic_unchecked_t msgid;
30850 struct tty_port port;
30852 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
30853 capimsg_setu16(s, 2, mp->ap->applid);
30854 capimsg_setu8 (s, 4, CAPI_DATA_B3);
30855 capimsg_setu8 (s, 5, CAPI_RESP);
30856 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
30857 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
30858 capimsg_setu32(s, 8, mp->ncci);
30859 capimsg_setu16(s, 12, datahandle);
30861 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
30862 mp->outbytes -= len;
30863 spin_unlock_bh(&mp->outlock);
30865 - datahandle = atomic_inc_return(&mp->datahandle);
30866 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
30867 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
30868 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30869 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30870 capimsg_setu16(skb->data, 2, mp->ap->applid);
30871 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
30872 capimsg_setu8 (skb->data, 5, CAPI_REQ);
30873 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
30874 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
30875 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
30876 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
30877 capimsg_setu16(skb->data, 16, len); /* Data length */
30878 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
30879 index db621db..825ea1a 100644
30880 --- a/drivers/isdn/gigaset/common.c
30881 +++ b/drivers/isdn/gigaset/common.c
30882 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
30883 cs->commands_pending = 0;
30884 cs->cur_at_seq = 0;
30886 - cs->open_count = 0;
30887 + local_set(&cs->open_count, 0);
30890 cs->tty_dev = NULL;
30891 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
30892 index 212efaf..f187c6b 100644
30893 --- a/drivers/isdn/gigaset/gigaset.h
30894 +++ b/drivers/isdn/gigaset/gigaset.h
30896 #include <linux/tty_driver.h>
30897 #include <linux/list.h>
30898 #include <linux/atomic.h>
30899 +#include <asm/local.h>
30901 #define GIG_VERSION {0, 5, 0, 0}
30902 #define GIG_COMPAT {0, 4, 0, 0}
30903 @@ -433,7 +434,7 @@ struct cardstate {
30904 spinlock_t cmdlock;
30905 unsigned curlen, cmdbytes;
30907 - unsigned open_count;
30908 + local_t open_count;
30909 struct tty_struct *tty;
30910 struct tasklet_struct if_wake_tasklet;
30911 unsigned control_state;
30912 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
30913 index ee0a549..a7c9798 100644
30914 --- a/drivers/isdn/gigaset/interface.c
30915 +++ b/drivers/isdn/gigaset/interface.c
30916 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
30918 tty->driver_data = cs;
30920 - ++cs->open_count;
30922 - if (cs->open_count == 1) {
30923 + if (local_inc_return(&cs->open_count) == 1) {
30924 spin_lock_irqsave(&cs->lock, flags);
30926 spin_unlock_irqrestore(&cs->lock, flags);
30927 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
30929 if (!cs->connected)
30930 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30931 - else if (!cs->open_count)
30932 + else if (!local_read(&cs->open_count))
30933 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30935 - if (!--cs->open_count) {
30936 + if (!local_dec_return(&cs->open_count)) {
30937 spin_lock_irqsave(&cs->lock, flags);
30939 spin_unlock_irqrestore(&cs->lock, flags);
30940 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
30941 if (!cs->connected) {
30942 gig_dbg(DEBUG_IF, "not connected");
30944 - } else if (!cs->open_count)
30945 + } else if (!local_read(&cs->open_count))
30946 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30949 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
30953 - if (!cs->open_count) {
30954 + if (!local_read(&cs->open_count)) {
30955 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30958 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
30959 if (!cs->connected) {
30960 gig_dbg(DEBUG_IF, "not connected");
30962 - } else if (!cs->open_count)
30963 + } else if (!local_read(&cs->open_count))
30964 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30965 else if (cs->mstate != MS_LOCKED) {
30966 dev_warn(cs->dev, "can't write to unlocked device\n");
30967 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
30969 if (!cs->connected)
30970 gig_dbg(DEBUG_IF, "not connected");
30971 - else if (!cs->open_count)
30972 + else if (!local_read(&cs->open_count))
30973 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30974 else if (cs->mstate != MS_LOCKED)
30975 dev_warn(cs->dev, "can't write to unlocked device\n");
30976 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
30978 if (!cs->connected)
30979 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30980 - else if (!cs->open_count)
30981 + else if (!local_read(&cs->open_count))
30982 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30984 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30985 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
30987 if (!cs->connected)
30988 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30989 - else if (!cs->open_count)
30990 + else if (!local_read(&cs->open_count))
30991 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30993 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30994 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
30998 - if (!cs->open_count) {
30999 + if (!local_read(&cs->open_count)) {
31000 dev_warn(cs->dev, "%s: device not opened\n", __func__);
31003 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
31004 index 2a57da59..e7a12ed 100644
31005 --- a/drivers/isdn/hardware/avm/b1.c
31006 +++ b/drivers/isdn/hardware/avm/b1.c
31007 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
31010 if (t4file->user) {
31011 - if (copy_from_user(buf, dp, left))
31012 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31015 memcpy(buf, dp, left);
31016 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
31019 if (config->user) {
31020 - if (copy_from_user(buf, dp, left))
31021 + if (left > sizeof buf || copy_from_user(buf, dp, left))
31024 memcpy(buf, dp, left);
31025 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
31026 index 85784a7..a19ca98 100644
31027 --- a/drivers/isdn/hardware/eicon/divasync.h
31028 +++ b/drivers/isdn/hardware/eicon/divasync.h
31029 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
31030 } diva_didd_add_adapter_t;
31031 typedef struct _diva_didd_remove_adapter {
31032 IDI_CALL p_request;
31033 -} diva_didd_remove_adapter_t;
31034 +} __no_const diva_didd_remove_adapter_t;
31035 typedef struct _diva_didd_read_adapter_array {
31038 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
31039 index a3bd163..8956575 100644
31040 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
31041 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
31042 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
31043 typedef struct _diva_os_idi_adapter_interface {
31044 diva_init_card_proc_t cleanup_adapter_proc;
31045 diva_cmd_card_proc_t cmd_proc;
31046 -} diva_os_idi_adapter_interface_t;
31047 +} __no_const diva_os_idi_adapter_interface_t;
31049 typedef struct _diva_os_xdi_adapter {
31050 struct list_head link;
31051 diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
31052 index 2339d73..802ab87 100644
31053 --- a/drivers/isdn/i4l/isdn_net.c
31054 +++ b/drivers/isdn/i4l/isdn_net.c
31055 @@ -1901,7 +1901,7 @@ static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
31057 isdn_net_local *lp = netdev_priv(dev);
31062 switch (lp->p_encap) {
31063 case ISDN_NET_ENCAP_ETHER:
31064 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
31065 index 1f355bb..43f1fea 100644
31066 --- a/drivers/isdn/icn/icn.c
31067 +++ b/drivers/isdn/icn/icn.c
31068 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
31072 - if (copy_from_user(msg, buf, count))
31073 + if (count > sizeof msg || copy_from_user(msg, buf, count))
31076 memcpy(msg, buf, count);
31077 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
31078 index b5fdcb7..5b6c59f 100644
31079 --- a/drivers/lguest/core.c
31080 +++ b/drivers/lguest/core.c
31081 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
31082 * it's worked so far. The end address needs +1 because __get_vm_area
31083 * allocates an extra guard page, so we need space for that.
31086 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31087 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31088 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31089 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31091 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31092 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31093 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31096 if (!switcher_vma) {
31098 printk("lguest: could not map switcher pages high\n");
31099 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31100 * Now the Switcher is mapped at the right address, we can't fail!
31101 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
31103 - memcpy(switcher_vma->addr, start_switcher_text,
31104 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31105 end_switcher_text - start_switcher_text);
31107 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31108 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
31109 index 65af42f..530c87a 100644
31110 --- a/drivers/lguest/x86/core.c
31111 +++ b/drivers/lguest/x86/core.c
31112 @@ -59,7 +59,7 @@ static struct {
31113 /* Offset from where switcher.S was compiled to where we've copied it */
31114 static unsigned long switcher_offset(void)
31116 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31117 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31120 /* This cpu's struct lguest_pages. */
31121 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
31122 * These copies are pretty cheap, so we do them unconditionally: */
31123 /* Save the current Host top-level page directory.
31126 +#ifdef CONFIG_PAX_PER_CPU_PGD
31127 + pages->state.host_cr3 = read_cr3();
31129 pages->state.host_cr3 = __pa(current->mm->pgd);
31133 * Set up the Guest's page tables to see this CPU's pages (and no
31134 * other CPU's pages).
31135 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
31136 * compiled-in switcher code and the high-mapped copy we just made.
31138 for (i = 0; i < IDT_ENTRIES; i++)
31139 - default_idt_entries[i] += switcher_offset();
31140 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31143 * Set up the Switcher's per-cpu areas.
31144 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
31145 * it will be undisturbed when we switch. To change %cs and jump we
31146 * need this structure to feed to Intel's "lcall" instruction.
31148 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31149 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31150 lguest_entry.segment = LGUEST_CS;
31153 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
31154 index 40634b0..4f5855e 100644
31155 --- a/drivers/lguest/x86/switcher_32.S
31156 +++ b/drivers/lguest/x86/switcher_32.S
31158 #include <asm/page.h>
31159 #include <asm/segment.h>
31160 #include <asm/lguest.h>
31161 +#include <asm/processor-flags.h>
31163 // We mark the start of the code to copy
31164 // It's placed in .text tho it's never run here
31165 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31166 // Changes type when we load it: damn Intel!
31167 // For after we switch over our page tables
31168 // That entry will be read-only: we'd crash.
31170 +#ifdef CONFIG_PAX_KERNEXEC
31172 + xor $X86_CR0_WP, %edx
31176 movl $(GDT_ENTRY_TSS*8), %edx
31179 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31180 // Let's clear it again for our return.
31181 // The GDT descriptor of the Host
31182 // Points to the table after two "size" bytes
31183 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31184 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31185 // Clear "used" from type field (byte 5, bit 2)
31186 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31187 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31189 +#ifdef CONFIG_PAX_KERNEXEC
31191 + xor $X86_CR0_WP, %eax
31195 // Once our page table's switched, the Guest is live!
31196 // The Host fades as we run this final step.
31197 @@ -295,13 +309,12 @@ deliver_to_host:
31198 // I consulted gcc, and it gave
31199 // These instructions, which I gladly credit:
31200 leal (%edx,%ebx,8), %eax
31201 - movzwl (%eax),%edx
31202 - movl 4(%eax), %eax
31205 + movl 4(%eax), %edx
31207 // Now the address of the handler's in %edx
31208 // We call it now: its "iret" drops us home.
31210 + ljmp $__KERNEL_CS, $1f
31213 // Every interrupt can come to us here
31214 // But we must truly tell each apart.
31215 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
31216 index 4daf9e5..b8d1d0f 100644
31217 --- a/drivers/macintosh/macio_asic.c
31218 +++ b/drivers/macintosh/macio_asic.c
31219 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
31220 * MacIO is matched against any Apple ID, it's probe() function
31221 * will then decide wether it applies or not
31223 -static const struct pci_device_id __devinitdata pci_ids [] = { {
31224 +static const struct pci_device_id __devinitconst pci_ids [] = { {
31225 .vendor = PCI_VENDOR_ID_APPLE,
31226 .device = PCI_ANY_ID,
31227 .subvendor = PCI_ANY_ID,
31228 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
31229 index 31c2dc2..a2de7a6 100644
31230 --- a/drivers/md/dm-ioctl.c
31231 +++ b/drivers/md/dm-ioctl.c
31232 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
31233 cmd == DM_LIST_VERSIONS_CMD)
31236 - if ((cmd == DM_DEV_CREATE_CMD)) {
31237 + if (cmd == DM_DEV_CREATE_CMD) {
31238 if (!*param->name) {
31239 DMWARN("name not supplied when creating device");
31241 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
31242 index 9bfd057..01180bc 100644
31243 --- a/drivers/md/dm-raid1.c
31244 +++ b/drivers/md/dm-raid1.c
31245 @@ -40,7 +40,7 @@ enum dm_raid1_error {
31248 struct mirror_set *ms;
31249 - atomic_t error_count;
31250 + atomic_unchecked_t error_count;
31251 unsigned long error_type;
31252 struct dm_dev *dev;
31254 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
31257 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31258 - if (!atomic_read(&m->error_count))
31259 + if (!atomic_read_unchecked(&m->error_count))
31263 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
31264 * simple way to tell if a device has encountered
31267 - atomic_inc(&m->error_count);
31268 + atomic_inc_unchecked(&m->error_count);
31270 if (test_and_set_bit(error_type, &m->error_type))
31272 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
31273 struct mirror *m = get_default_mirror(ms);
31276 - if (likely(!atomic_read(&m->error_count)))
31277 + if (likely(!atomic_read_unchecked(&m->error_count)))
31280 if (m-- == ms->mirror)
31281 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
31283 struct mirror *default_mirror = get_default_mirror(m->ms);
31285 - return !atomic_read(&default_mirror->error_count);
31286 + return !atomic_read_unchecked(&default_mirror->error_count);
31289 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31290 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
31292 if (likely(region_in_sync(ms, region, 1)))
31293 m = choose_mirror(ms, bio->bi_sector);
31294 - else if (m && atomic_read(&m->error_count))
31295 + else if (m && atomic_read_unchecked(&m->error_count))
31299 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
31302 ms->mirror[mirror].ms = ms;
31303 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31304 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31305 ms->mirror[mirror].error_type = 0;
31306 ms->mirror[mirror].offset = offset;
31308 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
31310 static char device_status_char(struct mirror *m)
31312 - if (!atomic_read(&(m->error_count)))
31313 + if (!atomic_read_unchecked(&(m->error_count)))
31316 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31317 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
31318 index 3d80cf0..b77cc47 100644
31319 --- a/drivers/md/dm-stripe.c
31320 +++ b/drivers/md/dm-stripe.c
31321 @@ -20,7 +20,7 @@ struct stripe {
31322 struct dm_dev *dev;
31323 sector_t physical_start;
31325 - atomic_t error_count;
31326 + atomic_unchecked_t error_count;
31330 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31334 - atomic_set(&(sc->stripe[i].error_count), 0);
31335 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31339 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
31340 DMEMIT("%d ", sc->stripes);
31341 for (i = 0; i < sc->stripes; i++) {
31342 DMEMIT("%s ", sc->stripe[i].dev->name);
31343 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31344 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31348 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
31350 for (i = 0; i < sc->stripes; i++)
31351 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31352 - atomic_inc(&(sc->stripe[i].error_count));
31353 - if (atomic_read(&(sc->stripe[i].error_count)) <
31354 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31355 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31356 DM_IO_ERROR_THRESHOLD)
31357 schedule_work(&sc->trigger_event);
31359 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
31360 index 8e91321..fd17aef 100644
31361 --- a/drivers/md/dm-table.c
31362 +++ b/drivers/md/dm-table.c
31363 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
31367 - if ((start >= dev_size) || (start + len > dev_size)) {
31368 + if ((start >= dev_size) || (len > dev_size - start)) {
31369 DMWARN("%s: %s too small for target: "
31370 "start=%llu, len=%llu, dev_size=%llu",
31371 dm_device_name(ti->table->md), bdevname(bdev, b),
31372 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
31373 index 59c4f04..4c7b661 100644
31374 --- a/drivers/md/dm-thin-metadata.c
31375 +++ b/drivers/md/dm-thin-metadata.c
31376 @@ -431,7 +431,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31379 pmd->info.levels = 2;
31380 - pmd->info.value_type.context = pmd->data_sm;
31381 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31382 pmd->info.value_type.size = sizeof(__le64);
31383 pmd->info.value_type.inc = data_block_inc;
31384 pmd->info.value_type.dec = data_block_dec;
31385 @@ -450,7 +450,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31387 pmd->bl_info.tm = tm;
31388 pmd->bl_info.levels = 1;
31389 - pmd->bl_info.value_type.context = pmd->data_sm;
31390 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31391 pmd->bl_info.value_type.size = sizeof(__le64);
31392 pmd->bl_info.value_type.inc = data_block_inc;
31393 pmd->bl_info.value_type.dec = data_block_dec;
31394 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
31395 index 4720f68..78d1df7 100644
31396 --- a/drivers/md/dm.c
31397 +++ b/drivers/md/dm.c
31398 @@ -177,9 +177,9 @@ struct mapped_device {
31402 - atomic_t event_nr;
31403 + atomic_unchecked_t event_nr;
31404 wait_queue_head_t eventq;
31405 - atomic_t uevent_seq;
31406 + atomic_unchecked_t uevent_seq;
31407 struct list_head uevent_list;
31408 spinlock_t uevent_lock; /* Protect access to uevent_list */
31410 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
31411 rwlock_init(&md->map_lock);
31412 atomic_set(&md->holders, 1);
31413 atomic_set(&md->open_count, 0);
31414 - atomic_set(&md->event_nr, 0);
31415 - atomic_set(&md->uevent_seq, 0);
31416 + atomic_set_unchecked(&md->event_nr, 0);
31417 + atomic_set_unchecked(&md->uevent_seq, 0);
31418 INIT_LIST_HEAD(&md->uevent_list);
31419 spin_lock_init(&md->uevent_lock);
31421 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
31423 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31425 - atomic_inc(&md->event_nr);
31426 + atomic_inc_unchecked(&md->event_nr);
31427 wake_up(&md->eventq);
31430 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
31432 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31434 - return atomic_add_return(1, &md->uevent_seq);
31435 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31438 uint32_t dm_get_event_nr(struct mapped_device *md)
31440 - return atomic_read(&md->event_nr);
31441 + return atomic_read_unchecked(&md->event_nr);
31444 int dm_wait_event(struct mapped_device *md, int event_nr)
31446 return wait_event_interruptible(md->eventq,
31447 - (event_nr != atomic_read(&md->event_nr)));
31448 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31451 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31452 diff --git a/drivers/md/md.c b/drivers/md/md.c
31453 index f47f1f8..b7f559e 100644
31454 --- a/drivers/md/md.c
31455 +++ b/drivers/md/md.c
31456 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
31457 * start build, activate spare
31459 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31460 -static atomic_t md_event_count;
31461 +static atomic_unchecked_t md_event_count;
31462 void md_new_event(struct mddev *mddev)
31464 - atomic_inc(&md_event_count);
31465 + atomic_inc_unchecked(&md_event_count);
31466 wake_up(&md_event_waiters);
31468 EXPORT_SYMBOL_GPL(md_new_event);
31469 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31471 static void md_new_event_inintr(struct mddev *mddev)
31473 - atomic_inc(&md_event_count);
31474 + atomic_inc_unchecked(&md_event_count);
31475 wake_up(&md_event_waiters);
31478 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
31480 rdev->preferred_minor = 0xffff;
31481 rdev->data_offset = le64_to_cpu(sb->data_offset);
31482 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31483 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31485 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31486 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31487 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
31489 sb->resync_offset = cpu_to_le64(0);
31491 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31492 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31494 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31495 sb->size = cpu_to_le64(mddev->dev_sectors);
31496 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
31498 errors_show(struct md_rdev *rdev, char *page)
31500 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31501 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31505 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
31507 unsigned long n = simple_strtoul(buf, &e, 10);
31508 if (*buf && (*e == 0 || *e == '\n')) {
31509 - atomic_set(&rdev->corrected_errors, n);
31510 + atomic_set_unchecked(&rdev->corrected_errors, n);
31514 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
31515 rdev->sb_loaded = 0;
31516 rdev->bb_page = NULL;
31517 atomic_set(&rdev->nr_pending, 0);
31518 - atomic_set(&rdev->read_errors, 0);
31519 - atomic_set(&rdev->corrected_errors, 0);
31520 + atomic_set_unchecked(&rdev->read_errors, 0);
31521 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31523 INIT_LIST_HEAD(&rdev->same_set);
31524 init_waitqueue_head(&rdev->blocked_wait);
31525 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31527 spin_unlock(&pers_lock);
31528 seq_printf(seq, "\n");
31529 - seq->poll_event = atomic_read(&md_event_count);
31530 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31533 if (v == (void*)2) {
31534 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31535 chunk_kb ? "KB" : "B");
31536 if (bitmap->file) {
31537 seq_printf(seq, ", file: ");
31538 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31539 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31542 seq_printf(seq, "\n");
31543 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
31546 seq = file->private_data;
31547 - seq->poll_event = atomic_read(&md_event_count);
31548 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31552 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
31553 /* always allow read */
31554 mask = POLLIN | POLLRDNORM;
31556 - if (seq->poll_event != atomic_read(&md_event_count))
31557 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
31558 mask |= POLLERR | POLLPRI;
31561 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
31562 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31563 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31564 (int)part_stat_read(&disk->part0, sectors[1]) -
31565 - atomic_read(&disk->sync_io);
31566 + atomic_read_unchecked(&disk->sync_io);
31567 /* sync IO will cause sync_io to increase before the disk_stats
31568 * as sync_io is counted when a request starts, and
31569 * disk_stats is counted when it completes.
31570 diff --git a/drivers/md/md.h b/drivers/md/md.h
31571 index cf742d9..7c7c745 100644
31572 --- a/drivers/md/md.h
31573 +++ b/drivers/md/md.h
31574 @@ -120,13 +120,13 @@ struct md_rdev {
31575 * only maintained for arrays that
31576 * support hot removal
31578 - atomic_t read_errors; /* number of consecutive read errors that
31579 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
31580 * we have tried to ignore.
31582 struct timespec last_read_error; /* monotonic time since our
31585 - atomic_t corrected_errors; /* number of corrected read errors,
31586 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31587 * for reporting to userspace and storing
31590 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
31592 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31594 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31595 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31598 struct md_personality
31599 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
31600 index 50ed53b..4f29d7d 100644
31601 --- a/drivers/md/persistent-data/dm-space-map-checker.c
31602 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
31603 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
31604 /*----------------------------------------------------------------*/
31606 struct sm_checker {
31607 - struct dm_space_map sm;
31608 + dm_space_map_no_const sm;
31610 struct count_array old_counts;
31611 struct count_array counts;
31612 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
31613 index fc469ba..2d91555 100644
31614 --- a/drivers/md/persistent-data/dm-space-map-disk.c
31615 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
31617 * Space map interface.
31620 - struct dm_space_map sm;
31621 + dm_space_map_no_const sm;
31624 struct ll_disk old_ll;
31625 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
31626 index e89ae5e..062e4c2 100644
31627 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
31628 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
31629 @@ -43,7 +43,7 @@ struct block_op {
31632 struct sm_metadata {
31633 - struct dm_space_map sm;
31634 + dm_space_map_no_const sm;
31637 struct ll_disk old_ll;
31638 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
31639 index 1cbfc6b..56e1dbb 100644
31640 --- a/drivers/md/persistent-data/dm-space-map.h
31641 +++ b/drivers/md/persistent-data/dm-space-map.h
31642 @@ -60,6 +60,7 @@ struct dm_space_map {
31643 int (*root_size)(struct dm_space_map *sm, size_t *result);
31644 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
31646 +typedef struct dm_space_map __no_const dm_space_map_no_const;
31648 /*----------------------------------------------------------------*/
31650 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
31651 index 7d9e071..015b1d5 100644
31652 --- a/drivers/md/raid1.c
31653 +++ b/drivers/md/raid1.c
31654 @@ -1568,7 +1568,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
31655 if (r1_sync_page_io(rdev, sect, s,
31656 bio->bi_io_vec[idx].bv_page,
31658 - atomic_add(s, &rdev->corrected_errors);
31659 + atomic_add_unchecked(s, &rdev->corrected_errors);
31663 @@ -1781,7 +1781,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
31664 test_bit(In_sync, &rdev->flags)) {
31665 if (r1_sync_page_io(rdev, sect, s,
31666 conf->tmppage, READ)) {
31667 - atomic_add(s, &rdev->corrected_errors);
31668 + atomic_add_unchecked(s, &rdev->corrected_errors);
31670 "md/raid1:%s: read error corrected "
31671 "(%d sectors at %llu on %s)\n",
31672 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
31673 index 685ddf3..955b087 100644
31674 --- a/drivers/md/raid10.c
31675 +++ b/drivers/md/raid10.c
31676 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
31677 /* The write handler will notice the lack of
31678 * R10BIO_Uptodate and record any errors etc
31680 - atomic_add(r10_bio->sectors,
31681 + atomic_add_unchecked(r10_bio->sectors,
31682 &conf->mirrors[d].rdev->corrected_errors);
31684 /* for reconstruct, we always reschedule after a read.
31685 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31687 struct timespec cur_time_mon;
31688 unsigned long hours_since_last;
31689 - unsigned int read_errors = atomic_read(&rdev->read_errors);
31690 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
31692 ktime_get_ts(&cur_time_mon);
31694 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31695 * overflowing the shift of read_errors by hours_since_last.
31697 if (hours_since_last >= 8 * sizeof(read_errors))
31698 - atomic_set(&rdev->read_errors, 0);
31699 + atomic_set_unchecked(&rdev->read_errors, 0);
31701 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
31702 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
31705 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
31706 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31709 check_decay_read_errors(mddev, rdev);
31710 - atomic_inc(&rdev->read_errors);
31711 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
31712 + atomic_inc_unchecked(&rdev->read_errors);
31713 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
31714 char b[BDEVNAME_SIZE];
31715 bdevname(rdev->bdev, b);
31717 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31718 "md/raid10:%s: %s: Raid device exceeded "
31719 "read_error threshold [cur %d:max %d]\n",
31721 - atomic_read(&rdev->read_errors), max_read_errors);
31722 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
31724 "md/raid10:%s: %s: Failing raid device\n",
31726 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31727 (unsigned long long)(
31728 sect + rdev->data_offset),
31729 bdevname(rdev->bdev, b));
31730 - atomic_add(s, &rdev->corrected_errors);
31731 + atomic_add_unchecked(s, &rdev->corrected_errors);
31734 rdev_dec_pending(rdev, mddev);
31735 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
31736 index 858fdbb..b2dac95 100644
31737 --- a/drivers/md/raid5.c
31738 +++ b/drivers/md/raid5.c
31739 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
31740 (unsigned long long)(sh->sector
31741 + rdev->data_offset),
31742 bdevname(rdev->bdev, b));
31743 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
31744 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
31745 clear_bit(R5_ReadError, &sh->dev[i].flags);
31746 clear_bit(R5_ReWrite, &sh->dev[i].flags);
31748 - if (atomic_read(&conf->disks[i].rdev->read_errors))
31749 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
31750 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
31751 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
31753 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
31755 rdev = conf->disks[i].rdev;
31757 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
31758 - atomic_inc(&rdev->read_errors);
31759 + atomic_inc_unchecked(&rdev->read_errors);
31760 if (conf->mddev->degraded >= conf->max_degraded)
31761 printk_ratelimited(
31763 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
31764 (unsigned long long)(sh->sector
31765 + rdev->data_offset),
31767 - else if (atomic_read(&rdev->read_errors)
31768 + else if (atomic_read_unchecked(&rdev->read_errors)
31769 > conf->max_nr_stripes)
31770 printk(KERN_WARNING
31771 "md/raid:%s: Too many read errors, failing device %s.\n",
31772 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
31773 index ba9a643..e474ab5 100644
31774 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
31775 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
31776 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
31777 .subvendor = _subvend, .subdevice = _subdev, \
31778 .driver_data = (unsigned long)&_driverdata }
31780 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
31781 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
31782 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
31783 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
31784 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
31785 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
31786 index a7d876f..8c21b61 100644
31787 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
31788 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
31789 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
31792 dmx_section_cb sec;
31796 struct dvb_demux *demux;
31798 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
31799 index f732877..d38c35a 100644
31800 --- a/drivers/media/dvb/dvb-core/dvbdev.c
31801 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
31802 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
31803 const struct dvb_device *template, void *priv, int type)
31805 struct dvb_device *dvbdev;
31806 - struct file_operations *dvbdevfops;
31807 + file_operations_no_const *dvbdevfops;
31808 struct device *clsdev;
31811 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
31812 index 9f2a02c..5920f88 100644
31813 --- a/drivers/media/dvb/dvb-usb/cxusb.c
31814 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
31815 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
31816 struct dib0700_adapter_state {
31817 int (*set_param_save) (struct dvb_frontend *,
31818 struct dvb_frontend_parameters *);
31822 static int dib7070_set_param_override(struct dvb_frontend *fe,
31823 struct dvb_frontend_parameters *fep)
31824 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
31825 index f103ec1..5e8968b 100644
31826 --- a/drivers/media/dvb/dvb-usb/dw2102.c
31827 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
31828 @@ -95,7 +95,7 @@ struct su3000_state {
31830 struct s6x0_state {
31831 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
31836 static int dvb_usb_dw2102_debug;
31837 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
31838 index 404f63a..4796533 100644
31839 --- a/drivers/media/dvb/frontends/dib3000.h
31840 +++ b/drivers/media/dvb/frontends/dib3000.h
31841 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
31842 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
31843 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
31844 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
31848 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
31849 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
31850 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
31851 index 90bf573..e8463da 100644
31852 --- a/drivers/media/dvb/frontends/ds3000.c
31853 +++ b/drivers/media/dvb/frontends/ds3000.c
31854 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
31856 for (i = 0; i < 30 ; i++) {
31857 ds3000_read_status(fe, &status);
31858 - if (status && FE_HAS_LOCK)
31859 + if (status & FE_HAS_LOCK)
31863 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
31864 index 0564192..75b16f5 100644
31865 --- a/drivers/media/dvb/ngene/ngene-cards.c
31866 +++ b/drivers/media/dvb/ngene/ngene-cards.c
31867 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
31869 /****************************************************************************/
31871 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
31872 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
31873 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
31874 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
31875 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
31876 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
31877 index 16a089f..ab1667d 100644
31878 --- a/drivers/media/radio/radio-cadet.c
31879 +++ b/drivers/media/radio/radio-cadet.c
31880 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
31881 unsigned char readbuf[RDS_BUFFER];
31884 + if (count > RDS_BUFFER)
31886 mutex_lock(&dev->lock);
31887 if (dev->rdsstat == 0) {
31889 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
31890 index 61287fc..8b08712 100644
31891 --- a/drivers/media/rc/redrat3.c
31892 +++ b/drivers/media/rc/redrat3.c
31893 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
31897 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
31898 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
31900 struct redrat3_dev *rr3 = rcdev->priv;
31901 struct device *dev = rr3->dev;
31902 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
31903 index 9cde353..8c6a1c3 100644
31904 --- a/drivers/media/video/au0828/au0828.h
31905 +++ b/drivers/media/video/au0828/au0828.h
31906 @@ -191,7 +191,7 @@ struct au0828_dev {
31909 struct i2c_adapter i2c_adap;
31910 - struct i2c_algorithm i2c_algo;
31911 + i2c_algorithm_no_const i2c_algo;
31912 struct i2c_client i2c_client;
31915 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
31916 index 68d1240..46b32eb 100644
31917 --- a/drivers/media/video/cx88/cx88-alsa.c
31918 +++ b/drivers/media/video/cx88/cx88-alsa.c
31919 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
31920 * Only boards with eeprom and byte 1 at eeprom=1 have it
31923 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
31924 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
31925 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31926 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31928 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31929 index 305e6aa..0143317 100644
31930 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31931 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31932 @@ -196,7 +196,7 @@ struct pvr2_hdw {
31935 struct i2c_adapter i2c_adap;
31936 - struct i2c_algorithm i2c_algo;
31937 + i2c_algorithm_no_const i2c_algo;
31938 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
31939 int i2c_cx25840_hack_state;
31941 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
31942 index a0895bf..b7ebb1b 100644
31943 --- a/drivers/media/video/timblogiw.c
31944 +++ b/drivers/media/video/timblogiw.c
31945 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
31947 /* Platform device functions */
31949 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31950 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
31951 .vidioc_querycap = timblogiw_querycap,
31952 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
31953 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
31954 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31955 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
31958 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
31959 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
31960 .owner = THIS_MODULE,
31961 .open = timblogiw_open,
31962 .release = timblogiw_close,
31963 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
31964 index e9c6a60..daf6a33 100644
31965 --- a/drivers/message/fusion/mptbase.c
31966 +++ b/drivers/message/fusion/mptbase.c
31967 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
31968 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
31969 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
31971 +#ifdef CONFIG_GRKERNSEC_HIDESYM
31972 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
31974 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
31975 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
31979 * Rounding UP to nearest 4-kB boundary here...
31981 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
31982 index 9d95042..b808101 100644
31983 --- a/drivers/message/fusion/mptsas.c
31984 +++ b/drivers/message/fusion/mptsas.c
31985 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
31989 +static inline void
31990 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31992 + if (phy_info->port_details) {
31993 + phy_info->port_details->rphy = rphy;
31994 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31995 + ioc->name, rphy));
31999 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32000 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32001 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32002 + ioc->name, rphy, rphy->dev.release));
32008 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
32009 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
32013 -static inline void
32014 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
32016 - if (phy_info->port_details) {
32017 - phy_info->port_details->rphy = rphy;
32018 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
32019 - ioc->name, rphy));
32023 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
32024 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
32025 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
32026 - ioc->name, rphy, rphy->dev.release));
32030 static inline struct sas_port *
32031 mptsas_get_port(struct mptsas_phyinfo *phy_info)
32033 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
32034 index 0c3ced7..1fe34ec 100644
32035 --- a/drivers/message/fusion/mptscsih.c
32036 +++ b/drivers/message/fusion/mptscsih.c
32037 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
32039 h = shost_priv(SChost);
32042 - if (h->info_kbuf == NULL)
32043 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32044 - return h->info_kbuf;
32045 - h->info_kbuf[0] = '\0';
32049 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32050 - h->info_kbuf[size-1] = '\0';
32052 + if (h->info_kbuf == NULL)
32053 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
32054 + return h->info_kbuf;
32055 + h->info_kbuf[0] = '\0';
32057 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
32058 + h->info_kbuf[size-1] = '\0';
32060 return h->info_kbuf;
32062 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
32063 index 07dbeaf..5533142 100644
32064 --- a/drivers/message/i2o/i2o_proc.c
32065 +++ b/drivers/message/i2o/i2o_proc.c
32066 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
32067 "Array Controller Device"
32070 -static char *chtostr(u8 * chars, int n)
32074 - return strncat(tmp, (char *)chars, n);
32077 static int i2o_report_query_status(struct seq_file *seq, int block_status,
32080 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
32082 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
32083 seq_printf(seq, "%-#8x", ddm_table.module_id);
32084 - seq_printf(seq, "%-29s",
32085 - chtostr(ddm_table.module_name_version, 28));
32086 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
32087 seq_printf(seq, "%9d ", ddm_table.data_size);
32088 seq_printf(seq, "%8d", ddm_table.code_size);
32090 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
32092 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
32093 seq_printf(seq, "%-#8x", dst->module_id);
32094 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
32095 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
32096 + seq_printf(seq, "%-.28s", dst->module_name_version);
32097 + seq_printf(seq, "%-.8s", dst->date);
32098 seq_printf(seq, "%8d ", dst->module_size);
32099 seq_printf(seq, "%8d ", dst->mpb_size);
32100 seq_printf(seq, "0x%04x", dst->module_flags);
32101 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
32102 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
32103 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
32104 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
32105 - seq_printf(seq, "Vendor info : %s\n",
32106 - chtostr((u8 *) (work32 + 2), 16));
32107 - seq_printf(seq, "Product info : %s\n",
32108 - chtostr((u8 *) (work32 + 6), 16));
32109 - seq_printf(seq, "Description : %s\n",
32110 - chtostr((u8 *) (work32 + 10), 16));
32111 - seq_printf(seq, "Product rev. : %s\n",
32112 - chtostr((u8 *) (work32 + 14), 8));
32113 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
32114 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
32115 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
32116 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
32118 seq_printf(seq, "Serial number : ");
32119 print_serial_number(seq, (u8 *) (work32 + 16),
32120 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
32123 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
32124 - seq_printf(seq, "Module name : %s\n",
32125 - chtostr(result.module_name, 24));
32126 - seq_printf(seq, "Module revision : %s\n",
32127 - chtostr(result.module_rev, 8));
32128 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
32129 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
32131 seq_printf(seq, "Serial number : ");
32132 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
32133 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
32137 - seq_printf(seq, "Device name : %s\n",
32138 - chtostr(result.device_name, 64));
32139 - seq_printf(seq, "Service name : %s\n",
32140 - chtostr(result.service_name, 64));
32141 - seq_printf(seq, "Physical name : %s\n",
32142 - chtostr(result.physical_location, 64));
32143 - seq_printf(seq, "Instance number : %s\n",
32144 - chtostr(result.instance_number, 4));
32145 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
32146 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
32147 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
32148 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
32152 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
32153 index a8c08f3..155fe3d 100644
32154 --- a/drivers/message/i2o/iop.c
32155 +++ b/drivers/message/i2o/iop.c
32156 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
32158 spin_lock_irqsave(&c->context_list_lock, flags);
32160 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
32161 - atomic_inc(&c->context_list_counter);
32162 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
32163 + atomic_inc_unchecked(&c->context_list_counter);
32165 - entry->context = atomic_read(&c->context_list_counter);
32166 + entry->context = atomic_read_unchecked(&c->context_list_counter);
32168 list_add(&entry->list, &c->context_list);
32170 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
32172 #if BITS_PER_LONG == 64
32173 spin_lock_init(&c->context_list_lock);
32174 - atomic_set(&c->context_list_counter, 0);
32175 + atomic_set_unchecked(&c->context_list_counter, 0);
32176 INIT_LIST_HEAD(&c->context_list);
32179 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
32180 index 7ce65f4..e66e9bc 100644
32181 --- a/drivers/mfd/abx500-core.c
32182 +++ b/drivers/mfd/abx500-core.c
32183 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
32185 struct abx500_device_entry {
32186 struct list_head list;
32187 - struct abx500_ops ops;
32188 + abx500_ops_no_const ops;
32189 struct device *dev;
32192 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
32193 index 5c2a06a..8fa077c 100644
32194 --- a/drivers/mfd/janz-cmodio.c
32195 +++ b/drivers/mfd/janz-cmodio.c
32198 #include <linux/kernel.h>
32199 #include <linux/module.h>
32200 +#include <linux/slab.h>
32201 #include <linux/init.h>
32202 #include <linux/pci.h>
32203 #include <linux/interrupt.h>
32204 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
32205 index 29d12a7..f900ba4 100644
32206 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
32207 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
32208 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
32209 * the lid is closed. This leads to interrupts as soon as a little move
32212 - atomic_inc(&lis3->count);
32213 + atomic_inc_unchecked(&lis3->count);
32215 wake_up_interruptible(&lis3->misc_wait);
32216 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
32217 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
32219 pm_runtime_get_sync(lis3->pm_dev);
32221 - atomic_set(&lis3->count, 0);
32222 + atomic_set_unchecked(&lis3->count, 0);
32226 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
32227 add_wait_queue(&lis3->misc_wait, &wait);
32229 set_current_state(TASK_INTERRUPTIBLE);
32230 - data = atomic_xchg(&lis3->count, 0);
32231 + data = atomic_xchg_unchecked(&lis3->count, 0);
32235 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
32236 struct lis3lv02d, miscdev);
32238 poll_wait(file, &lis3->misc_wait, wait);
32239 - if (atomic_read(&lis3->count))
32240 + if (atomic_read_unchecked(&lis3->count))
32241 return POLLIN | POLLRDNORM;
32244 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
32245 index 2b1482a..5d33616 100644
32246 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
32247 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
32248 @@ -266,7 +266,7 @@ struct lis3lv02d {
32249 struct input_polled_dev *idev; /* input device */
32250 struct platform_device *pdev; /* platform device */
32251 struct regulator_bulk_data regulators[2];
32252 - atomic_t count; /* interrupt count after last read */
32253 + atomic_unchecked_t count; /* interrupt count after last read */
32254 union axis_conversion ac; /* hw -> logical axis */
32255 int mapped_btns[3];
32257 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
32258 index 2f30bad..c4c13d0 100644
32259 --- a/drivers/misc/sgi-gru/gruhandles.c
32260 +++ b/drivers/misc/sgi-gru/gruhandles.c
32261 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
32262 unsigned long nsec;
32264 nsec = CLKS2NSEC(clks);
32265 - atomic_long_inc(&mcs_op_statistics[op].count);
32266 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
32267 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
32268 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
32269 if (mcs_op_statistics[op].max < nsec)
32270 mcs_op_statistics[op].max = nsec;
32272 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
32273 index 7768b87..f8aac38 100644
32274 --- a/drivers/misc/sgi-gru/gruprocfs.c
32275 +++ b/drivers/misc/sgi-gru/gruprocfs.c
32278 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
32280 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
32281 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
32283 - unsigned long val = atomic_long_read(v);
32284 + unsigned long val = atomic_long_read_unchecked(v);
32286 seq_printf(s, "%16lu %s\n", val, id);
32288 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
32290 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
32291 for (op = 0; op < mcsop_last; op++) {
32292 - count = atomic_long_read(&mcs_op_statistics[op].count);
32293 - total = atomic_long_read(&mcs_op_statistics[op].total);
32294 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32295 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32296 max = mcs_op_statistics[op].max;
32297 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32298 count ? total / count : 0, max);
32299 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
32300 index 5c3ce24..4915ccb 100644
32301 --- a/drivers/misc/sgi-gru/grutables.h
32302 +++ b/drivers/misc/sgi-gru/grutables.h
32303 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
32306 struct gru_stats_s {
32307 - atomic_long_t vdata_alloc;
32308 - atomic_long_t vdata_free;
32309 - atomic_long_t gts_alloc;
32310 - atomic_long_t gts_free;
32311 - atomic_long_t gms_alloc;
32312 - atomic_long_t gms_free;
32313 - atomic_long_t gts_double_allocate;
32314 - atomic_long_t assign_context;
32315 - atomic_long_t assign_context_failed;
32316 - atomic_long_t free_context;
32317 - atomic_long_t load_user_context;
32318 - atomic_long_t load_kernel_context;
32319 - atomic_long_t lock_kernel_context;
32320 - atomic_long_t unlock_kernel_context;
32321 - atomic_long_t steal_user_context;
32322 - atomic_long_t steal_kernel_context;
32323 - atomic_long_t steal_context_failed;
32324 - atomic_long_t nopfn;
32325 - atomic_long_t asid_new;
32326 - atomic_long_t asid_next;
32327 - atomic_long_t asid_wrap;
32328 - atomic_long_t asid_reuse;
32329 - atomic_long_t intr;
32330 - atomic_long_t intr_cbr;
32331 - atomic_long_t intr_tfh;
32332 - atomic_long_t intr_spurious;
32333 - atomic_long_t intr_mm_lock_failed;
32334 - atomic_long_t call_os;
32335 - atomic_long_t call_os_wait_queue;
32336 - atomic_long_t user_flush_tlb;
32337 - atomic_long_t user_unload_context;
32338 - atomic_long_t user_exception;
32339 - atomic_long_t set_context_option;
32340 - atomic_long_t check_context_retarget_intr;
32341 - atomic_long_t check_context_unload;
32342 - atomic_long_t tlb_dropin;
32343 - atomic_long_t tlb_preload_page;
32344 - atomic_long_t tlb_dropin_fail_no_asid;
32345 - atomic_long_t tlb_dropin_fail_upm;
32346 - atomic_long_t tlb_dropin_fail_invalid;
32347 - atomic_long_t tlb_dropin_fail_range_active;
32348 - atomic_long_t tlb_dropin_fail_idle;
32349 - atomic_long_t tlb_dropin_fail_fmm;
32350 - atomic_long_t tlb_dropin_fail_no_exception;
32351 - atomic_long_t tfh_stale_on_fault;
32352 - atomic_long_t mmu_invalidate_range;
32353 - atomic_long_t mmu_invalidate_page;
32354 - atomic_long_t flush_tlb;
32355 - atomic_long_t flush_tlb_gru;
32356 - atomic_long_t flush_tlb_gru_tgh;
32357 - atomic_long_t flush_tlb_gru_zero_asid;
32358 + atomic_long_unchecked_t vdata_alloc;
32359 + atomic_long_unchecked_t vdata_free;
32360 + atomic_long_unchecked_t gts_alloc;
32361 + atomic_long_unchecked_t gts_free;
32362 + atomic_long_unchecked_t gms_alloc;
32363 + atomic_long_unchecked_t gms_free;
32364 + atomic_long_unchecked_t gts_double_allocate;
32365 + atomic_long_unchecked_t assign_context;
32366 + atomic_long_unchecked_t assign_context_failed;
32367 + atomic_long_unchecked_t free_context;
32368 + atomic_long_unchecked_t load_user_context;
32369 + atomic_long_unchecked_t load_kernel_context;
32370 + atomic_long_unchecked_t lock_kernel_context;
32371 + atomic_long_unchecked_t unlock_kernel_context;
32372 + atomic_long_unchecked_t steal_user_context;
32373 + atomic_long_unchecked_t steal_kernel_context;
32374 + atomic_long_unchecked_t steal_context_failed;
32375 + atomic_long_unchecked_t nopfn;
32376 + atomic_long_unchecked_t asid_new;
32377 + atomic_long_unchecked_t asid_next;
32378 + atomic_long_unchecked_t asid_wrap;
32379 + atomic_long_unchecked_t asid_reuse;
32380 + atomic_long_unchecked_t intr;
32381 + atomic_long_unchecked_t intr_cbr;
32382 + atomic_long_unchecked_t intr_tfh;
32383 + atomic_long_unchecked_t intr_spurious;
32384 + atomic_long_unchecked_t intr_mm_lock_failed;
32385 + atomic_long_unchecked_t call_os;
32386 + atomic_long_unchecked_t call_os_wait_queue;
32387 + atomic_long_unchecked_t user_flush_tlb;
32388 + atomic_long_unchecked_t user_unload_context;
32389 + atomic_long_unchecked_t user_exception;
32390 + atomic_long_unchecked_t set_context_option;
32391 + atomic_long_unchecked_t check_context_retarget_intr;
32392 + atomic_long_unchecked_t check_context_unload;
32393 + atomic_long_unchecked_t tlb_dropin;
32394 + atomic_long_unchecked_t tlb_preload_page;
32395 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
32396 + atomic_long_unchecked_t tlb_dropin_fail_upm;
32397 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
32398 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
32399 + atomic_long_unchecked_t tlb_dropin_fail_idle;
32400 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
32401 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
32402 + atomic_long_unchecked_t tfh_stale_on_fault;
32403 + atomic_long_unchecked_t mmu_invalidate_range;
32404 + atomic_long_unchecked_t mmu_invalidate_page;
32405 + atomic_long_unchecked_t flush_tlb;
32406 + atomic_long_unchecked_t flush_tlb_gru;
32407 + atomic_long_unchecked_t flush_tlb_gru_tgh;
32408 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
32410 - atomic_long_t copy_gpa;
32411 - atomic_long_t read_gpa;
32412 + atomic_long_unchecked_t copy_gpa;
32413 + atomic_long_unchecked_t read_gpa;
32415 - atomic_long_t mesq_receive;
32416 - atomic_long_t mesq_receive_none;
32417 - atomic_long_t mesq_send;
32418 - atomic_long_t mesq_send_failed;
32419 - atomic_long_t mesq_noop;
32420 - atomic_long_t mesq_send_unexpected_error;
32421 - atomic_long_t mesq_send_lb_overflow;
32422 - atomic_long_t mesq_send_qlimit_reached;
32423 - atomic_long_t mesq_send_amo_nacked;
32424 - atomic_long_t mesq_send_put_nacked;
32425 - atomic_long_t mesq_page_overflow;
32426 - atomic_long_t mesq_qf_locked;
32427 - atomic_long_t mesq_qf_noop_not_full;
32428 - atomic_long_t mesq_qf_switch_head_failed;
32429 - atomic_long_t mesq_qf_unexpected_error;
32430 - atomic_long_t mesq_noop_unexpected_error;
32431 - atomic_long_t mesq_noop_lb_overflow;
32432 - atomic_long_t mesq_noop_qlimit_reached;
32433 - atomic_long_t mesq_noop_amo_nacked;
32434 - atomic_long_t mesq_noop_put_nacked;
32435 - atomic_long_t mesq_noop_page_overflow;
32436 + atomic_long_unchecked_t mesq_receive;
32437 + atomic_long_unchecked_t mesq_receive_none;
32438 + atomic_long_unchecked_t mesq_send;
32439 + atomic_long_unchecked_t mesq_send_failed;
32440 + atomic_long_unchecked_t mesq_noop;
32441 + atomic_long_unchecked_t mesq_send_unexpected_error;
32442 + atomic_long_unchecked_t mesq_send_lb_overflow;
32443 + atomic_long_unchecked_t mesq_send_qlimit_reached;
32444 + atomic_long_unchecked_t mesq_send_amo_nacked;
32445 + atomic_long_unchecked_t mesq_send_put_nacked;
32446 + atomic_long_unchecked_t mesq_page_overflow;
32447 + atomic_long_unchecked_t mesq_qf_locked;
32448 + atomic_long_unchecked_t mesq_qf_noop_not_full;
32449 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
32450 + atomic_long_unchecked_t mesq_qf_unexpected_error;
32451 + atomic_long_unchecked_t mesq_noop_unexpected_error;
32452 + atomic_long_unchecked_t mesq_noop_lb_overflow;
32453 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
32454 + atomic_long_unchecked_t mesq_noop_amo_nacked;
32455 + atomic_long_unchecked_t mesq_noop_put_nacked;
32456 + atomic_long_unchecked_t mesq_noop_page_overflow;
32460 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
32461 tghop_invalidate, mcsop_last};
32463 struct mcs_op_statistic {
32464 - atomic_long_t count;
32465 - atomic_long_t total;
32466 + atomic_long_unchecked_t count;
32467 + atomic_long_unchecked_t total;
32471 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
32473 #define STAT(id) do { \
32474 if (gru_options & OPT_STATS) \
32475 - atomic_long_inc(&gru_stats.id); \
32476 + atomic_long_inc_unchecked(&gru_stats.id); \
32479 #ifdef CONFIG_SGI_GRU_DEBUG
32480 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
32481 index 851b2f2..a4ec097 100644
32482 --- a/drivers/misc/sgi-xp/xp.h
32483 +++ b/drivers/misc/sgi-xp/xp.h
32484 @@ -289,7 +289,7 @@ struct xpc_interface {
32485 xpc_notify_func, void *);
32486 void (*received) (short, int, void *);
32487 enum xp_retval (*partid_to_nasids) (short, void *);
32491 extern struct xpc_interface xpc_interface;
32493 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
32494 index b94d5f7..7f494c5 100644
32495 --- a/drivers/misc/sgi-xp/xpc.h
32496 +++ b/drivers/misc/sgi-xp/xpc.h
32497 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
32498 void (*received_payload) (struct xpc_channel *, void *);
32499 void (*notify_senders_of_disconnect) (struct xpc_channel *);
32501 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
32503 /* struct xpc_partition act_state values (for XPC HB) */
32505 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
32506 /* found in xpc_main.c */
32507 extern struct device *xpc_part;
32508 extern struct device *xpc_chan;
32509 -extern struct xpc_arch_operations xpc_arch_ops;
32510 +extern xpc_arch_operations_no_const xpc_arch_ops;
32511 extern int xpc_disengage_timelimit;
32512 extern int xpc_disengage_timedout;
32513 extern int xpc_activate_IRQ_rcvd;
32514 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
32515 index 8d082b4..aa749ae 100644
32516 --- a/drivers/misc/sgi-xp/xpc_main.c
32517 +++ b/drivers/misc/sgi-xp/xpc_main.c
32518 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
32519 .notifier_call = xpc_system_die,
32522 -struct xpc_arch_operations xpc_arch_ops;
32523 +xpc_arch_operations_no_const xpc_arch_ops;
32526 * Timer function to enforce the timelimit on the partition disengage.
32527 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
32528 index 6878a94..fe5c5f1 100644
32529 --- a/drivers/mmc/host/sdhci-pci.c
32530 +++ b/drivers/mmc/host/sdhci-pci.c
32531 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
32532 .probe = via_probe,
32535 -static const struct pci_device_id pci_ids[] __devinitdata = {
32536 +static const struct pci_device_id pci_ids[] __devinitconst = {
32538 .vendor = PCI_VENDOR_ID_RICOH,
32539 .device = PCI_DEVICE_ID_RICOH_R5C822,
32540 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
32541 index e9fad91..0a7a16a 100644
32542 --- a/drivers/mtd/devices/doc2000.c
32543 +++ b/drivers/mtd/devices/doc2000.c
32544 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
32546 /* The ECC will not be calculated correctly if less than 512 is written */
32548 - if (len != 0x200 && eccbuf)
32549 + if (len != 0x200)
32550 printk(KERN_WARNING
32551 "ECC needs a full sector write (adr: %lx size %lx)\n",
32552 (long) to, (long) len);
32553 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
32554 index a3f7a27..234016e 100644
32555 --- a/drivers/mtd/devices/doc2001.c
32556 +++ b/drivers/mtd/devices/doc2001.c
32557 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
32558 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
32560 /* Don't allow read past end of device */
32561 - if (from >= this->totlen)
32562 + if (from >= this->totlen || !len)
32565 /* Don't allow a single read to cross a 512-byte block boundary */
32566 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
32567 index 3984d48..28aa897 100644
32568 --- a/drivers/mtd/nand/denali.c
32569 +++ b/drivers/mtd/nand/denali.c
32571 #include <linux/pci.h>
32572 #include <linux/mtd/mtd.h>
32573 #include <linux/module.h>
32574 +#include <linux/slab.h>
32576 #include "denali.h"
32578 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
32579 index ac40925..483b753 100644
32580 --- a/drivers/mtd/nftlmount.c
32581 +++ b/drivers/mtd/nftlmount.c
32583 #include <asm/errno.h>
32584 #include <linux/delay.h>
32585 #include <linux/slab.h>
32586 +#include <linux/sched.h>
32587 #include <linux/mtd/mtd.h>
32588 #include <linux/mtd/nand.h>
32589 #include <linux/mtd/nftl.h>
32590 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
32591 index 6c3fb5a..c542a81 100644
32592 --- a/drivers/mtd/ubi/build.c
32593 +++ b/drivers/mtd/ubi/build.c
32594 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
32595 static int __init bytes_str_to_int(const char *str)
32598 - unsigned long result;
32599 + unsigned long result, scale = 1;
32601 result = simple_strtoul(str, &endp, 0);
32602 if (str == endp || result >= INT_MAX) {
32603 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
32615 if (endp[1] == 'i' && endp[2] == 'B')
32618 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
32623 + if ((intoverflow_t)result*scale >= INT_MAX) {
32624 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
32629 + return result*scale;
32633 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
32634 index 1feae59..c2a61d2 100644
32635 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
32636 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
32637 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
32640 #define ATL2_PARAM(X, desc) \
32641 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32642 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32643 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
32644 MODULE_PARM_DESC(X, desc);
32646 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32647 index 9a517c2..a50cfcb 100644
32648 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32649 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32650 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
32652 int (*wait_comp)(struct bnx2x *bp,
32653 struct bnx2x_rx_mode_ramrod_params *p);
32657 /********************** Set multicast group ***********************************/
32659 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
32660 index 94b4bd0..73c02de 100644
32661 --- a/drivers/net/ethernet/broadcom/tg3.h
32662 +++ b/drivers/net/ethernet/broadcom/tg3.h
32663 @@ -134,6 +134,7 @@
32664 #define CHIPREV_ID_5750_A0 0x4000
32665 #define CHIPREV_ID_5750_A1 0x4001
32666 #define CHIPREV_ID_5750_A3 0x4003
32667 +#define CHIPREV_ID_5750_C1 0x4201
32668 #define CHIPREV_ID_5750_C2 0x4202
32669 #define CHIPREV_ID_5752_A0_HW 0x5000
32670 #define CHIPREV_ID_5752_A0 0x6000
32671 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32672 index c5f5479..2e8c260 100644
32673 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32674 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32675 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
32677 struct l2t_skb_cb {
32678 arp_failure_handler_func arp_failure_handler;
32682 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
32684 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
32685 index 871bcaa..4043505 100644
32686 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
32687 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
32688 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32689 for (i=0; i<ETH_ALEN; i++) {
32690 tmp.addr[i] = dev->dev_addr[i];
32692 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32693 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32696 case DE4X5_SET_HWADDR: /* Set the hardware address */
32697 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32698 spin_lock_irqsave(&lp->lock, flags);
32699 memcpy(&statbuf, &lp->pktStats, ioc->len);
32700 spin_unlock_irqrestore(&lp->lock, flags);
32701 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
32702 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
32706 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
32707 index 14d5b61..1398636 100644
32708 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
32709 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
32710 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
32714 -static const char *block_name[] __devinitdata = {
32715 +static const char *block_name[] __devinitconst = {
32718 "21142 Serial PHY",
32719 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
32720 index 4d01219..b58d26d 100644
32721 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
32722 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
32723 @@ -236,7 +236,7 @@ struct pci_id_info {
32724 int drv_flags; /* Driver use, intended as capability flags. */
32727 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32728 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32729 { /* Sometime a Level-One switch card. */
32730 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
32731 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
32732 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
32733 index dcd7f7a..ecb7fb3 100644
32734 --- a/drivers/net/ethernet/dlink/sundance.c
32735 +++ b/drivers/net/ethernet/dlink/sundance.c
32736 @@ -218,7 +218,7 @@ enum {
32737 struct pci_id_info {
32740 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32741 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32742 {"D-Link DFE-550TX FAST Ethernet Adapter"},
32743 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
32744 {"D-Link DFE-580TX 4 port Server Adapter"},
32745 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
32746 index bf266a0..e024af7 100644
32747 --- a/drivers/net/ethernet/emulex/benet/be_main.c
32748 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
32749 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
32753 - ACCESS_ONCE(*acc) = newacc;
32754 + ACCESS_ONCE_RW(*acc) = newacc;
32757 void be_parse_stats(struct be_adapter *adapter)
32758 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
32759 index 61d2bdd..7f1154a 100644
32760 --- a/drivers/net/ethernet/fealnx.c
32761 +++ b/drivers/net/ethernet/fealnx.c
32762 @@ -150,7 +150,7 @@ struct chip_info {
32766 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
32767 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
32768 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32769 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
32770 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32771 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32772 index e1159e5..e18684d 100644
32773 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32774 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32775 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
32777 struct e1000_hw *hw = &adapter->hw;
32778 struct e1000_mac_info *mac = &hw->mac;
32779 - struct e1000_mac_operations *func = &mac->ops;
32780 + e1000_mac_operations_no_const *func = &mac->ops;
32782 /* Set media type */
32783 switch (adapter->pdev->device) {
32784 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
32785 index a3e65fd..f451444 100644
32786 --- a/drivers/net/ethernet/intel/e1000e/82571.c
32787 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
32788 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
32790 struct e1000_hw *hw = &adapter->hw;
32791 struct e1000_mac_info *mac = &hw->mac;
32792 - struct e1000_mac_operations *func = &mac->ops;
32793 + e1000_mac_operations_no_const *func = &mac->ops;
32796 bool force_clear_smbi = false;
32797 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
32798 index 2967039..ca8c40c 100644
32799 --- a/drivers/net/ethernet/intel/e1000e/hw.h
32800 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
32801 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
32802 void (*write_vfta)(struct e1000_hw *, u32, u32);
32803 s32 (*read_mac_addr)(struct e1000_hw *);
32805 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32808 * When to use various PHY register access functions:
32809 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
32810 void (*power_up)(struct e1000_hw *);
32811 void (*power_down)(struct e1000_hw *);
32813 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32815 /* Function pointers for the NVM. */
32816 struct e1000_nvm_operations {
32817 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
32818 s32 (*validate)(struct e1000_hw *);
32819 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
32821 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32823 struct e1000_mac_info {
32824 - struct e1000_mac_operations ops;
32825 + e1000_mac_operations_no_const ops;
32827 u8 perm_addr[ETH_ALEN];
32829 @@ -872,7 +875,7 @@ struct e1000_mac_info {
32832 struct e1000_phy_info {
32833 - struct e1000_phy_operations ops;
32834 + e1000_phy_operations_no_const ops;
32836 enum e1000_phy_type type;
32838 @@ -906,7 +909,7 @@ struct e1000_phy_info {
32841 struct e1000_nvm_info {
32842 - struct e1000_nvm_operations ops;
32843 + e1000_nvm_operations_no_const ops;
32845 enum e1000_nvm_type type;
32846 enum e1000_nvm_override override;
32847 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
32848 index 4519a13..f97fcd0 100644
32849 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
32850 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
32851 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
32852 s32 (*read_mac_addr)(struct e1000_hw *);
32853 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
32855 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32857 struct e1000_phy_operations {
32858 s32 (*acquire)(struct e1000_hw *);
32859 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
32860 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
32861 s32 (*write_reg)(struct e1000_hw *, u32, u16);
32863 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32865 struct e1000_nvm_operations {
32866 s32 (*acquire)(struct e1000_hw *);
32867 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
32868 s32 (*update)(struct e1000_hw *);
32869 s32 (*validate)(struct e1000_hw *);
32871 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32873 struct e1000_info {
32874 s32 (*get_invariants)(struct e1000_hw *);
32875 @@ -350,7 +353,7 @@ struct e1000_info {
32876 extern const struct e1000_info e1000_82575_info;
32878 struct e1000_mac_info {
32879 - struct e1000_mac_operations ops;
32880 + e1000_mac_operations_no_const ops;
32884 @@ -388,7 +391,7 @@ struct e1000_mac_info {
32887 struct e1000_phy_info {
32888 - struct e1000_phy_operations ops;
32889 + e1000_phy_operations_no_const ops;
32891 enum e1000_phy_type type;
32893 @@ -423,7 +426,7 @@ struct e1000_phy_info {
32896 struct e1000_nvm_info {
32897 - struct e1000_nvm_operations ops;
32898 + e1000_nvm_operations_no_const ops;
32899 enum e1000_nvm_type type;
32900 enum e1000_nvm_override override;
32902 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
32903 s32 (*check_for_ack)(struct e1000_hw *, u16);
32904 s32 (*check_for_rst)(struct e1000_hw *, u16);
32906 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32908 struct e1000_mbx_stats {
32910 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
32913 struct e1000_mbx_info {
32914 - struct e1000_mbx_operations ops;
32915 + e1000_mbx_operations_no_const ops;
32916 struct e1000_mbx_stats stats;
32919 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
32920 index d7ed58f..64cde36 100644
32921 --- a/drivers/net/ethernet/intel/igbvf/vf.h
32922 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
32923 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
32924 s32 (*read_mac_addr)(struct e1000_hw *);
32925 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
32927 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32929 struct e1000_mac_info {
32930 - struct e1000_mac_operations ops;
32931 + e1000_mac_operations_no_const ops;
32935 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
32936 s32 (*check_for_ack)(struct e1000_hw *);
32937 s32 (*check_for_rst)(struct e1000_hw *);
32939 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32941 struct e1000_mbx_stats {
32943 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
32946 struct e1000_mbx_info {
32947 - struct e1000_mbx_operations ops;
32948 + e1000_mbx_operations_no_const ops;
32949 struct e1000_mbx_stats stats;
32952 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32953 index 6c5cca8..de8ef63 100644
32954 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32955 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32956 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
32957 s32 (*update_checksum)(struct ixgbe_hw *);
32958 u16 (*calc_checksum)(struct ixgbe_hw *);
32960 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
32962 struct ixgbe_mac_operations {
32963 s32 (*init_hw)(struct ixgbe_hw *);
32964 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
32965 /* Manageability interface */
32966 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
32968 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32970 struct ixgbe_phy_operations {
32971 s32 (*identify)(struct ixgbe_hw *);
32972 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
32973 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
32974 s32 (*check_overtemp)(struct ixgbe_hw *);
32976 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
32978 struct ixgbe_eeprom_info {
32979 - struct ixgbe_eeprom_operations ops;
32980 + ixgbe_eeprom_operations_no_const ops;
32981 enum ixgbe_eeprom_type type;
32982 u32 semaphore_delay;
32984 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
32986 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
32987 struct ixgbe_mac_info {
32988 - struct ixgbe_mac_operations ops;
32989 + ixgbe_mac_operations_no_const ops;
32990 enum ixgbe_mac_type type;
32991 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32992 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32993 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
32996 struct ixgbe_phy_info {
32997 - struct ixgbe_phy_operations ops;
32998 + ixgbe_phy_operations_no_const ops;
32999 struct mdio_if_info mdio;
33000 enum ixgbe_phy_type type;
33002 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
33003 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
33004 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
33006 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
33008 struct ixgbe_mbx_stats {
33010 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
33013 struct ixgbe_mbx_info {
33014 - struct ixgbe_mbx_operations ops;
33015 + ixgbe_mbx_operations_no_const ops;
33016 struct ixgbe_mbx_stats stats;
33019 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
33020 index 10306b4..28df758 100644
33021 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
33022 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
33023 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
33024 s32 (*clear_vfta)(struct ixgbe_hw *);
33025 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
33027 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
33029 enum ixgbe_mac_type {
33030 ixgbe_mac_unknown = 0,
33031 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
33034 struct ixgbe_mac_info {
33035 - struct ixgbe_mac_operations ops;
33036 + ixgbe_mac_operations_no_const ops;
33040 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
33041 s32 (*check_for_ack)(struct ixgbe_hw *);
33042 s32 (*check_for_rst)(struct ixgbe_hw *);
33044 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
33046 struct ixgbe_mbx_stats {
33048 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
33051 struct ixgbe_mbx_info {
33052 - struct ixgbe_mbx_operations ops;
33053 + ixgbe_mbx_operations_no_const ops;
33054 struct ixgbe_mbx_stats stats;
33057 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
33058 index 94bbc85..78c12e6 100644
33059 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
33060 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
33062 #include <linux/dma-mapping.h>
33063 #include <linux/slab.h>
33064 #include <linux/io-mapping.h>
33065 +#include <linux/sched.h>
33067 #include <linux/mlx4/device.h>
33068 #include <linux/mlx4/doorbell.h>
33069 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
33070 index 5046a64..71ca936 100644
33071 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
33072 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
33073 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
33074 void (*link_down)(struct __vxge_hw_device *devh);
33075 void (*crit_err)(struct __vxge_hw_device *devh,
33076 enum vxge_hw_event type, u64 ext_data);
33081 * struct __vxge_hw_blockpool_entry - Block private data structure
33082 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
33083 index 4a518a3..936b334 100644
33084 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
33085 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
33086 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
33087 struct vxge_hw_mempool_dma *dma_object,
33093 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
33094 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
33095 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
33096 index c8f47f1..5da9840 100644
33097 --- a/drivers/net/ethernet/realtek/r8169.c
33098 +++ b/drivers/net/ethernet/realtek/r8169.c
33099 @@ -698,17 +698,17 @@ struct rtl8169_private {
33101 void (*write)(void __iomem *, int, int);
33102 int (*read)(void __iomem *, int);
33104 + } __no_const mdio_ops;
33106 struct pll_power_ops {
33107 void (*down)(struct rtl8169_private *);
33108 void (*up)(struct rtl8169_private *);
33110 + } __no_const pll_power_ops;
33113 void (*enable)(struct rtl8169_private *);
33114 void (*disable)(struct rtl8169_private *);
33116 + } __no_const jumbo_ops;
33118 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
33119 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
33120 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
33121 index 1b4658c..a30dabb 100644
33122 --- a/drivers/net/ethernet/sis/sis190.c
33123 +++ b/drivers/net/ethernet/sis/sis190.c
33124 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
33125 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
33126 struct net_device *dev)
33128 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
33129 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
33130 struct sis190_private *tp = netdev_priv(dev);
33131 struct pci_dev *isa_bridge;
33133 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
33134 index edfa15d..002bfa9 100644
33135 --- a/drivers/net/ppp/ppp_generic.c
33136 +++ b/drivers/net/ppp/ppp_generic.c
33137 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33138 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
33139 struct ppp_stats stats;
33140 struct ppp_comp_stats cstats;
33144 case SIOCGPPPSTATS:
33145 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33149 - vers = PPP_VERSION;
33150 - if (copy_to_user(addr, vers, strlen(vers) + 1))
33151 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
33155 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
33156 index 515f122..41dd273 100644
33157 --- a/drivers/net/tokenring/abyss.c
33158 +++ b/drivers/net/tokenring/abyss.c
33159 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
33161 static int __init abyss_init (void)
33163 - abyss_netdev_ops = tms380tr_netdev_ops;
33164 + pax_open_kernel();
33165 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33167 - abyss_netdev_ops.ndo_open = abyss_open;
33168 - abyss_netdev_ops.ndo_stop = abyss_close;
33169 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
33170 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
33171 + pax_close_kernel();
33173 return pci_register_driver(&abyss_driver);
33175 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
33176 index 6153cfd..cf69c1c 100644
33177 --- a/drivers/net/tokenring/madgemc.c
33178 +++ b/drivers/net/tokenring/madgemc.c
33179 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
33181 static int __init madgemc_init (void)
33183 - madgemc_netdev_ops = tms380tr_netdev_ops;
33184 - madgemc_netdev_ops.ndo_open = madgemc_open;
33185 - madgemc_netdev_ops.ndo_stop = madgemc_close;
33186 + pax_open_kernel();
33187 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33188 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
33189 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
33190 + pax_close_kernel();
33192 return mca_register_driver (&madgemc_driver);
33194 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
33195 index 8d362e6..f91cc52 100644
33196 --- a/drivers/net/tokenring/proteon.c
33197 +++ b/drivers/net/tokenring/proteon.c
33198 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
33199 struct platform_device *pdev;
33200 int i, num = 0, err = 0;
33202 - proteon_netdev_ops = tms380tr_netdev_ops;
33203 - proteon_netdev_ops.ndo_open = proteon_open;
33204 - proteon_netdev_ops.ndo_stop = tms380tr_close;
33205 + pax_open_kernel();
33206 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33207 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
33208 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
33209 + pax_close_kernel();
33211 err = platform_driver_register(&proteon_driver);
33213 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
33214 index 46db5c5..37c1536 100644
33215 --- a/drivers/net/tokenring/skisa.c
33216 +++ b/drivers/net/tokenring/skisa.c
33217 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
33218 struct platform_device *pdev;
33219 int i, num = 0, err = 0;
33221 - sk_isa_netdev_ops = tms380tr_netdev_ops;
33222 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
33223 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
33224 + pax_open_kernel();
33225 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33226 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
33227 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
33228 + pax_close_kernel();
33230 err = platform_driver_register(&sk_isa_driver);
33232 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
33233 index 304fe78..db112fa 100644
33234 --- a/drivers/net/usb/hso.c
33235 +++ b/drivers/net/usb/hso.c
33237 #include <asm/byteorder.h>
33238 #include <linux/serial_core.h>
33239 #include <linux/serial.h>
33241 +#include <asm/local.h>
33243 #define MOD_AUTHOR "Option Wireless"
33244 #define MOD_DESCRIPTION "USB High Speed Option driver"
33245 @@ -257,7 +257,7 @@ struct hso_serial {
33247 /* from usb_serial_port */
33248 struct tty_struct *tty;
33250 + local_t open_count;
33251 spinlock_t serial_lock;
33253 int (*write_data) (struct hso_serial *serial);
33254 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
33257 urb = serial->rx_urb[0];
33258 - if (serial->open_count > 0) {
33259 + if (local_read(&serial->open_count) > 0) {
33260 count = put_rxbuf_data(urb, serial);
33263 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
33264 DUMP1(urb->transfer_buffer, urb->actual_length);
33266 /* Anyone listening? */
33267 - if (serial->open_count == 0)
33268 + if (local_read(&serial->open_count) == 0)
33272 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
33273 spin_unlock_irq(&serial->serial_lock);
33275 /* check for port already opened, if not set the termios */
33276 - serial->open_count++;
33277 - if (serial->open_count == 1) {
33278 + if (local_inc_return(&serial->open_count) == 1) {
33279 serial->rx_state = RX_IDLE;
33280 /* Force default termio settings */
33281 _hso_serial_set_termios(tty, NULL);
33282 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
33283 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
33285 hso_stop_serial_device(serial->parent);
33286 - serial->open_count--;
33287 + local_dec(&serial->open_count);
33288 kref_put(&serial->parent->ref, hso_serial_ref_free);
33291 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
33293 /* reset the rts and dtr */
33294 /* do the actual close */
33295 - serial->open_count--;
33296 + local_dec(&serial->open_count);
33298 - if (serial->open_count <= 0) {
33299 - serial->open_count = 0;
33300 + if (local_read(&serial->open_count) <= 0) {
33301 + local_set(&serial->open_count, 0);
33302 spin_lock_irq(&serial->serial_lock);
33303 if (serial->tty == tty) {
33304 serial->tty->driver_data = NULL;
33305 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
33307 /* the actual setup */
33308 spin_lock_irqsave(&serial->serial_lock, flags);
33309 - if (serial->open_count)
33310 + if (local_read(&serial->open_count))
33311 _hso_serial_set_termios(tty, old);
33313 tty->termios = old;
33314 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
33315 D1("Pending read interrupt on port %d\n", i);
33316 spin_lock(&serial->serial_lock);
33317 if (serial->rx_state == RX_IDLE &&
33318 - serial->open_count > 0) {
33319 + local_read(&serial->open_count) > 0) {
33320 /* Setup and send a ctrl req read on
33322 if (!serial->rx_urb_filled[0]) {
33323 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
33324 /* Start all serial ports */
33325 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
33326 if (serial_table[i] && (serial_table[i]->interface == iface)) {
33327 - if (dev2ser(serial_table[i])->open_count) {
33328 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
33330 hso_start_serial_device(serial_table[i], GFP_NOIO);
33331 hso_kick_transmit(dev2ser(serial_table[i]));
33332 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33333 index e662cbc..8d4a102 100644
33334 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
33335 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33336 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
33337 * Return with error code if any of the queue indices
33340 - if (p->ring_index[i] < 0 ||
33341 - p->ring_index[i] >= adapter->num_rx_queues)
33342 + if (p->ring_index[i] >= adapter->num_rx_queues)
33346 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
33347 index 0f9ee46..e2d6e65 100644
33348 --- a/drivers/net/wireless/ath/ath.h
33349 +++ b/drivers/net/wireless/ath/ath.h
33350 @@ -119,6 +119,7 @@ struct ath_ops {
33351 void (*write_flush) (void *);
33352 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
33354 +typedef struct ath_ops __no_const ath_ops_no_const;
33357 struct ath_bus_ops;
33358 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33359 index b592016..fe47870 100644
33360 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33361 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33362 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33363 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
33364 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
33366 - ACCESS_ONCE(ads->ds_link) = i->link;
33367 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
33368 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
33369 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
33371 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
33372 ctl6 = SM(i->keytype, AR_EncrType);
33373 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33375 if ((i->is_first || i->is_last) &&
33376 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
33377 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
33378 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
33379 | set11nTries(i->rates, 1)
33380 | set11nTries(i->rates, 2)
33381 | set11nTries(i->rates, 3)
33382 | (i->dur_update ? AR_DurUpdateEna : 0)
33383 | SM(0, AR_BurstDur);
33385 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
33386 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
33387 | set11nRate(i->rates, 1)
33388 | set11nRate(i->rates, 2)
33389 | set11nRate(i->rates, 3);
33391 - ACCESS_ONCE(ads->ds_ctl2) = 0;
33392 - ACCESS_ONCE(ads->ds_ctl3) = 0;
33393 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
33394 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
33397 if (!i->is_first) {
33398 - ACCESS_ONCE(ads->ds_ctl0) = 0;
33399 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33400 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33401 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
33402 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33403 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33407 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33411 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33412 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33413 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33414 | SM(i->txpower, AR_XmitPower)
33415 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33416 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33417 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
33418 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
33420 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33421 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33422 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33423 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33425 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
33428 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33429 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33430 | set11nPktDurRTSCTS(i->rates, 1);
33432 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33433 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33434 | set11nPktDurRTSCTS(i->rates, 3);
33436 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33437 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33438 | set11nRateFlags(i->rates, 1)
33439 | set11nRateFlags(i->rates, 2)
33440 | set11nRateFlags(i->rates, 3)
33441 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33442 index f5ae3c6..7936af3 100644
33443 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33444 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33445 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33446 (i->qcu << AR_TxQcuNum_S) | 0x17;
33449 - ACCESS_ONCE(ads->info) = val;
33450 + ACCESS_ONCE_RW(ads->info) = val;
33452 checksum += i->link;
33453 - ACCESS_ONCE(ads->link) = i->link;
33454 + ACCESS_ONCE_RW(ads->link) = i->link;
33456 checksum += i->buf_addr[0];
33457 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
33458 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
33459 checksum += i->buf_addr[1];
33460 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
33461 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
33462 checksum += i->buf_addr[2];
33463 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
33464 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
33465 checksum += i->buf_addr[3];
33466 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
33467 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
33469 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
33470 - ACCESS_ONCE(ads->ctl3) = val;
33471 + ACCESS_ONCE_RW(ads->ctl3) = val;
33472 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
33473 - ACCESS_ONCE(ads->ctl5) = val;
33474 + ACCESS_ONCE_RW(ads->ctl5) = val;
33475 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
33476 - ACCESS_ONCE(ads->ctl7) = val;
33477 + ACCESS_ONCE_RW(ads->ctl7) = val;
33478 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
33479 - ACCESS_ONCE(ads->ctl9) = val;
33480 + ACCESS_ONCE_RW(ads->ctl9) = val;
33482 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
33483 - ACCESS_ONCE(ads->ctl10) = checksum;
33484 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
33486 if (i->is_first || i->is_last) {
33487 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
33488 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
33489 | set11nTries(i->rates, 1)
33490 | set11nTries(i->rates, 2)
33491 | set11nTries(i->rates, 3)
33492 | (i->dur_update ? AR_DurUpdateEna : 0)
33493 | SM(0, AR_BurstDur);
33495 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
33496 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
33497 | set11nRate(i->rates, 1)
33498 | set11nRate(i->rates, 2)
33499 | set11nRate(i->rates, 3);
33501 - ACCESS_ONCE(ads->ctl13) = 0;
33502 - ACCESS_ONCE(ads->ctl14) = 0;
33503 + ACCESS_ONCE_RW(ads->ctl13) = 0;
33504 + ACCESS_ONCE_RW(ads->ctl14) = 0;
33508 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33510 ctl17 = SM(i->keytype, AR_EncrType);
33511 if (!i->is_first) {
33512 - ACCESS_ONCE(ads->ctl11) = 0;
33513 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33514 - ACCESS_ONCE(ads->ctl15) = 0;
33515 - ACCESS_ONCE(ads->ctl16) = 0;
33516 - ACCESS_ONCE(ads->ctl17) = ctl17;
33517 - ACCESS_ONCE(ads->ctl18) = 0;
33518 - ACCESS_ONCE(ads->ctl19) = 0;
33519 + ACCESS_ONCE_RW(ads->ctl11) = 0;
33520 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33521 + ACCESS_ONCE_RW(ads->ctl15) = 0;
33522 + ACCESS_ONCE_RW(ads->ctl16) = 0;
33523 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33524 + ACCESS_ONCE_RW(ads->ctl18) = 0;
33525 + ACCESS_ONCE_RW(ads->ctl19) = 0;
33529 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33530 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33531 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33532 | SM(i->txpower, AR_XmitPower)
33533 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33534 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33535 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
33536 ctl12 |= SM(val, AR_PAPRDChainMask);
33538 - ACCESS_ONCE(ads->ctl12) = ctl12;
33539 - ACCESS_ONCE(ads->ctl17) = ctl17;
33540 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
33541 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33543 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33544 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33545 | set11nPktDurRTSCTS(i->rates, 1);
33547 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33548 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33549 | set11nPktDurRTSCTS(i->rates, 3);
33551 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
33552 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
33553 | set11nRateFlags(i->rates, 1)
33554 | set11nRateFlags(i->rates, 2)
33555 | set11nRateFlags(i->rates, 3)
33556 | SM(i->rtscts_rate, AR_RTSCTSRate);
33558 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
33559 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
33562 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
33563 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
33564 index f389b3c..7359e18 100644
33565 --- a/drivers/net/wireless/ath/ath9k/hw.h
33566 +++ b/drivers/net/wireless/ath/ath9k/hw.h
33567 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
33570 void (*ani_cache_ini_regs)(struct ath_hw *ah);
33575 * struct ath_hw_ops - callbacks used by hardware code and driver code
33576 @@ -635,7 +635,7 @@ struct ath_hw_ops {
33577 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
33578 struct ath_hw_antcomb_conf *antconf);
33583 struct ath_nf_limits {
33585 @@ -655,7 +655,7 @@ enum ath_cal_list {
33586 #define AH_FASTCC 0x4
33589 - struct ath_ops reg_ops;
33590 + ath_ops_no_const reg_ops;
33592 struct ieee80211_hw *hw;
33593 struct ath_common common;
33594 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33595 index bea8524..c677c06 100644
33596 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33597 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33598 @@ -547,7 +547,7 @@ struct phy_func_ptr {
33599 void (*carrsuppr)(struct brcms_phy *);
33600 s32 (*rxsigpwr)(struct brcms_phy *, s32);
33601 void (*detach)(struct brcms_phy *);
33606 struct brcms_phy_pub pubpi_ro;
33607 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33608 index 05f2ad1..ae00eea 100644
33609 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
33610 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33611 @@ -3685,7 +3685,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
33613 if (iwl3945_mod_params.disable_hw_scan) {
33614 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
33615 - iwl3945_hw_ops.hw_scan = NULL;
33616 + pax_open_kernel();
33617 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
33618 + pax_close_kernel();
33621 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
33622 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
33623 index 69a77e2..552b42c 100644
33624 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
33625 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
33626 @@ -71,8 +71,8 @@ do { \
33630 -#define IWL_DEBUG(m, level, fmt, args...)
33631 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
33632 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
33633 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
33634 #define iwl_print_hex_dump(m, level, p, len)
33635 #endif /* CONFIG_IWLWIFI_DEBUG */
33637 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
33638 index 523ad55..f8c5dc5 100644
33639 --- a/drivers/net/wireless/mac80211_hwsim.c
33640 +++ b/drivers/net/wireless/mac80211_hwsim.c
33641 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
33644 if (fake_hw_scan) {
33645 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33646 - mac80211_hwsim_ops.sw_scan_start = NULL;
33647 - mac80211_hwsim_ops.sw_scan_complete = NULL;
33648 + pax_open_kernel();
33649 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33650 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
33651 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
33652 + pax_close_kernel();
33655 spin_lock_init(&hwsim_radio_lock);
33656 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
33657 index 30f138b..c904585 100644
33658 --- a/drivers/net/wireless/mwifiex/main.h
33659 +++ b/drivers/net/wireless/mwifiex/main.h
33660 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
33661 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
33662 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
33663 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
33667 struct mwifiex_adapter {
33669 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
33670 index 0c13840..a5c3ed6 100644
33671 --- a/drivers/net/wireless/rndis_wlan.c
33672 +++ b/drivers/net/wireless/rndis_wlan.c
33673 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
33675 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
33677 - if (rts_threshold < 0 || rts_threshold > 2347)
33678 + if (rts_threshold > 2347)
33679 rts_threshold = 2347;
33681 tmp = cpu_to_le32(rts_threshold);
33682 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
33683 index a77f1bb..c608b2b 100644
33684 --- a/drivers/net/wireless/wl1251/wl1251.h
33685 +++ b/drivers/net/wireless/wl1251/wl1251.h
33686 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
33687 void (*reset)(struct wl1251 *wl);
33688 void (*enable_irq)(struct wl1251 *wl);
33689 void (*disable_irq)(struct wl1251 *wl);
33694 struct ieee80211_hw *hw;
33695 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
33696 index f34b5b2..b5abb9f 100644
33697 --- a/drivers/oprofile/buffer_sync.c
33698 +++ b/drivers/oprofile/buffer_sync.c
33699 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
33700 if (cookie == NO_COOKIE)
33702 if (cookie == INVALID_COOKIE) {
33703 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33704 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33707 if (cookie != last_cookie) {
33708 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
33709 /* add userspace sample */
33712 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
33713 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
33717 cookie = lookup_dcookie(mm, s->eip, &offset);
33719 if (cookie == INVALID_COOKIE) {
33720 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33721 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33725 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
33726 /* ignore backtraces if failed to add a sample */
33727 if (state == sb_bt_start) {
33728 state = sb_bt_ignore;
33729 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
33730 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
33734 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
33735 index c0cc4e7..44d4e54 100644
33736 --- a/drivers/oprofile/event_buffer.c
33737 +++ b/drivers/oprofile/event_buffer.c
33738 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
33741 if (buffer_pos == buffer_size) {
33742 - atomic_inc(&oprofile_stats.event_lost_overflow);
33743 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
33747 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
33748 index f8c752e..28bf4fc 100644
33749 --- a/drivers/oprofile/oprof.c
33750 +++ b/drivers/oprofile/oprof.c
33751 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
33752 if (oprofile_ops.switch_events())
33755 - atomic_inc(&oprofile_stats.multiplex_counter);
33756 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
33757 start_switch_worker();
33760 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
33761 index 917d28e..d62d981 100644
33762 --- a/drivers/oprofile/oprofile_stats.c
33763 +++ b/drivers/oprofile/oprofile_stats.c
33764 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
33765 cpu_buf->sample_invalid_eip = 0;
33768 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
33769 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
33770 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
33771 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
33772 - atomic_set(&oprofile_stats.multiplex_counter, 0);
33773 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
33774 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
33775 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
33776 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
33777 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
33781 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
33782 index 38b6fc0..b5cbfce 100644
33783 --- a/drivers/oprofile/oprofile_stats.h
33784 +++ b/drivers/oprofile/oprofile_stats.h
33785 @@ -13,11 +13,11 @@
33786 #include <linux/atomic.h>
33788 struct oprofile_stat_struct {
33789 - atomic_t sample_lost_no_mm;
33790 - atomic_t sample_lost_no_mapping;
33791 - atomic_t bt_lost_no_mapping;
33792 - atomic_t event_lost_overflow;
33793 - atomic_t multiplex_counter;
33794 + atomic_unchecked_t sample_lost_no_mm;
33795 + atomic_unchecked_t sample_lost_no_mapping;
33796 + atomic_unchecked_t bt_lost_no_mapping;
33797 + atomic_unchecked_t event_lost_overflow;
33798 + atomic_unchecked_t multiplex_counter;
33801 extern struct oprofile_stat_struct oprofile_stats;
33802 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
33803 index 2f0aa0f..90fab02 100644
33804 --- a/drivers/oprofile/oprofilefs.c
33805 +++ b/drivers/oprofile/oprofilefs.c
33806 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
33809 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
33810 - char const *name, atomic_t *val)
33811 + char const *name, atomic_unchecked_t *val)
33813 return __oprofilefs_create_file(sb, root, name,
33814 &atomic_ro_fops, 0444, val);
33815 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
33816 index 3f56bc0..707d642 100644
33817 --- a/drivers/parport/procfs.c
33818 +++ b/drivers/parport/procfs.c
33819 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
33823 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
33824 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
33827 #ifdef CONFIG_PARPORT_1284
33828 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
33832 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
33833 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
33835 #endif /* IEEE1284.3 support. */
33837 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
33838 index 9fff878..ad0ad53 100644
33839 --- a/drivers/pci/hotplug/cpci_hotplug.h
33840 +++ b/drivers/pci/hotplug/cpci_hotplug.h
33841 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
33842 int (*hardware_test) (struct slot* slot, u32 value);
33843 u8 (*get_power) (struct slot* slot);
33844 int (*set_power) (struct slot* slot, int value);
33848 struct cpci_hp_controller {
33850 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
33851 index 76ba8a1..20ca857 100644
33852 --- a/drivers/pci/hotplug/cpqphp_nvram.c
33853 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
33854 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
33856 void compaq_nvram_init (void __iomem *rom_start)
33859 +#ifndef CONFIG_PAX_KERNEXEC
33861 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
33865 dbg("int15 entry = %p\n", compaq_int15_entry_point);
33867 /* initialize our int15 lock */
33868 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
33869 index 1cfbf22..be96487 100644
33870 --- a/drivers/pci/pcie/aspm.c
33871 +++ b/drivers/pci/pcie/aspm.c
33873 #define MODULE_PARAM_PREFIX "pcie_aspm."
33875 /* Note: those are not register definitions */
33876 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
33877 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
33878 -#define ASPM_STATE_L1 (4) /* L1 state */
33879 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
33880 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
33881 +#define ASPM_STATE_L1 (4U) /* L1 state */
33882 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
33883 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
33885 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
33886 index dfee1b3..a454fb6 100644
33887 --- a/drivers/pci/probe.c
33888 +++ b/drivers/pci/probe.c
33889 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
33893 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
33894 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
33896 if (!dev->mmio_always_on) {
33897 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
33898 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
33899 index 27911b5..5b6db88 100644
33900 --- a/drivers/pci/proc.c
33901 +++ b/drivers/pci/proc.c
33902 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
33903 static int __init pci_proc_init(void)
33905 struct pci_dev *dev = NULL;
33907 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33908 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33909 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
33910 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33911 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
33914 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
33916 proc_create("devices", 0, proc_bus_pci_dir,
33917 &proc_bus_pci_dev_operations);
33918 proc_initialized = 1;
33919 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
33920 index 7b82868..b9344c9 100644
33921 --- a/drivers/platform/x86/thinkpad_acpi.c
33922 +++ b/drivers/platform/x86/thinkpad_acpi.c
33923 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
33927 -void static hotkey_mask_warn_incomplete_mask(void)
33928 +static void hotkey_mask_warn_incomplete_mask(void)
33930 /* log only what the user can fix... */
33931 const u32 wantedmask = hotkey_driver_mask &
33932 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
33936 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33937 - struct tp_nvram_state *newn,
33938 - const u32 event_mask)
33941 #define TPACPI_COMPARE_KEY(__scancode, __member) \
33943 if ((event_mask & (1 << __scancode)) && \
33944 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33945 tpacpi_hotkey_send_key(__scancode); \
33948 - void issue_volchange(const unsigned int oldvol,
33949 - const unsigned int newvol)
33951 - unsigned int i = oldvol;
33952 +static void issue_volchange(const unsigned int oldvol,
33953 + const unsigned int newvol,
33954 + const u32 event_mask)
33956 + unsigned int i = oldvol;
33958 - while (i > newvol) {
33959 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33962 - while (i < newvol) {
33963 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33966 + while (i > newvol) {
33967 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33970 + while (i < newvol) {
33971 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33976 - void issue_brightnesschange(const unsigned int oldbrt,
33977 - const unsigned int newbrt)
33979 - unsigned int i = oldbrt;
33980 +static void issue_brightnesschange(const unsigned int oldbrt,
33981 + const unsigned int newbrt,
33982 + const u32 event_mask)
33984 + unsigned int i = oldbrt;
33986 - while (i > newbrt) {
33987 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33990 - while (i < newbrt) {
33991 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33994 + while (i > newbrt) {
33995 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33998 + while (i < newbrt) {
33999 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
34004 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34005 + struct tp_nvram_state *newn,
34006 + const u32 event_mask)
34008 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
34009 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
34010 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
34011 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34012 oldn->volume_level != newn->volume_level) {
34013 /* recently muted, or repeated mute keypress, or
34014 * multiple presses ending in mute */
34015 - issue_volchange(oldn->volume_level, newn->volume_level);
34016 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
34017 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
34020 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34021 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
34023 if (oldn->volume_level != newn->volume_level) {
34024 - issue_volchange(oldn->volume_level, newn->volume_level);
34025 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
34026 } else if (oldn->volume_toggle != newn->volume_toggle) {
34027 /* repeated vol up/down keypress at end of scale ? */
34028 if (newn->volume_level == 0)
34029 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34030 /* handle brightness */
34031 if (oldn->brightness_level != newn->brightness_level) {
34032 issue_brightnesschange(oldn->brightness_level,
34033 - newn->brightness_level);
34034 + newn->brightness_level,
34036 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
34037 /* repeated key presses that didn't change state */
34038 if (newn->brightness_level == 0)
34039 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
34040 && !tp_features.bright_unkfw)
34041 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
34045 #undef TPACPI_COMPARE_KEY
34046 #undef TPACPI_MAY_SEND_KEY
34051 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
34052 index b859d16..5cc6b1a 100644
34053 --- a/drivers/pnp/pnpbios/bioscalls.c
34054 +++ b/drivers/pnp/pnpbios/bioscalls.c
34055 @@ -59,7 +59,7 @@ do { \
34056 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
34059 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
34060 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
34061 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
34064 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
34067 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
34069 + pax_open_kernel();
34070 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
34071 + pax_close_kernel();
34073 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
34074 spin_lock_irqsave(&pnp_bios_lock, flags);
34075 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
34077 spin_unlock_irqrestore(&pnp_bios_lock, flags);
34079 + pax_open_kernel();
34080 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
34081 + pax_close_kernel();
34085 /* If we get here and this is set then the PnP BIOS faulted on us. */
34086 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
34090 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
34091 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
34095 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
34096 pnp_bios_callpoint.offset = header->fields.pm16offset;
34097 pnp_bios_callpoint.segment = PNP_CS16;
34099 + pax_open_kernel();
34101 for_each_possible_cpu(i) {
34102 struct desc_struct *gdt = get_cpu_gdt_table(i);
34104 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
34105 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
34106 (unsigned long)__va(header->fields.pm16dseg));
34109 + pax_close_kernel();
34111 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
34112 index b0ecacb..7c9da2e 100644
34113 --- a/drivers/pnp/resource.c
34114 +++ b/drivers/pnp/resource.c
34115 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
34118 /* check if the resource is valid */
34119 - if (*irq < 0 || *irq > 15)
34123 /* check if the resource is reserved */
34124 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
34127 /* check if the resource is valid */
34128 - if (*dma < 0 || *dma == 4 || *dma > 7)
34129 + if (*dma == 4 || *dma > 7)
34132 /* check if the resource is reserved */
34133 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
34134 index bb16f5b..c751eef 100644
34135 --- a/drivers/power/bq27x00_battery.c
34136 +++ b/drivers/power/bq27x00_battery.c
34138 struct bq27x00_device_info;
34139 struct bq27x00_access_methods {
34140 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
34144 enum bq27x00_chip { BQ27000, BQ27500 };
34146 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
34147 index 33f5d9a..d957d3f 100644
34148 --- a/drivers/regulator/max8660.c
34149 +++ b/drivers/regulator/max8660.c
34150 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
34151 max8660->shadow_regs[MAX8660_OVER1] = 5;
34153 /* Otherwise devices can be toggled via software */
34154 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
34155 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
34156 + pax_open_kernel();
34157 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
34158 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
34159 + pax_close_kernel();
34163 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
34164 index 023d17d..74ef35b 100644
34165 --- a/drivers/regulator/mc13892-regulator.c
34166 +++ b/drivers/regulator/mc13892-regulator.c
34167 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
34169 mc13xxx_unlock(mc13892);
34171 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
34172 + pax_open_kernel();
34173 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
34174 = mc13892_vcam_set_mode;
34175 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
34176 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
34177 = mc13892_vcam_get_mode;
34178 + pax_close_kernel();
34179 for (i = 0; i < pdata->num_regulators; i++) {
34180 init_data = &pdata->regulators[i];
34181 priv->regulators[i] = regulator_register(
34182 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
34183 index cace6d3..f623fda 100644
34184 --- a/drivers/rtc/rtc-dev.c
34185 +++ b/drivers/rtc/rtc-dev.c
34187 #include <linux/module.h>
34188 #include <linux/rtc.h>
34189 #include <linux/sched.h>
34190 +#include <linux/grsecurity.h>
34191 #include "rtc-core.h"
34193 static dev_t rtc_devt;
34194 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
34195 if (copy_from_user(&tm, uarg, sizeof(tm)))
34198 + gr_log_timechange();
34200 return rtc_set_time(rtc, &tm);
34203 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
34204 index ffb5878..e6d785c 100644
34205 --- a/drivers/scsi/aacraid/aacraid.h
34206 +++ b/drivers/scsi/aacraid/aacraid.h
34207 @@ -492,7 +492,7 @@ struct adapter_ops
34208 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
34209 /* Administrative operations */
34210 int (*adapter_comm)(struct aac_dev * dev, int comm);
34215 * Define which interrupt handler needs to be installed
34216 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
34217 index 705e13e..91c873c 100644
34218 --- a/drivers/scsi/aacraid/linit.c
34219 +++ b/drivers/scsi/aacraid/linit.c
34220 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
34221 #elif defined(__devinitconst)
34222 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
34224 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
34225 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
34227 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
34228 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
34229 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
34230 index d5ff142..49c0ebb 100644
34231 --- a/drivers/scsi/aic94xx/aic94xx_init.c
34232 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
34233 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
34234 .lldd_control_phy = asd_control_phy,
34237 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
34238 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
34239 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
34240 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
34241 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
34242 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
34243 index a796de9..1ef20e1 100644
34244 --- a/drivers/scsi/bfa/bfa.h
34245 +++ b/drivers/scsi/bfa/bfa.h
34246 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
34252 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
34254 struct bfa_faa_cbfn_s {
34255 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
34256 index e07bd47..cd1bbbb 100644
34257 --- a/drivers/scsi/bfa/bfa_fcpim.c
34258 +++ b/drivers/scsi/bfa/bfa_fcpim.c
34259 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
34261 bfa_iotag_attach(fcp);
34263 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
34264 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
34265 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
34266 (fcp->num_itns * sizeof(struct bfa_itn_s));
34267 memset(fcp->itn_arr, 0,
34268 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34269 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
34271 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
34272 - struct bfa_itn_s *itn;
34273 + bfa_itn_s_no_const *itn;
34275 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
34277 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
34278 index 1080bcb..a3b39e3 100644
34279 --- a/drivers/scsi/bfa/bfa_fcpim.h
34280 +++ b/drivers/scsi/bfa/bfa_fcpim.h
34281 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
34283 bfa_isr_func_t isr;
34285 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
34287 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34288 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
34289 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
34290 struct list_head iotag_tio_free_q; /* free IO resources */
34291 struct list_head iotag_unused_q; /* unused IO resources*/
34292 struct bfa_iotag_s *iotag_arr;
34293 - struct bfa_itn_s *itn_arr;
34294 + bfa_itn_s_no_const *itn_arr;
34296 int num_fwtio_reqs;
34298 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
34299 index 546d46b..642fa5b 100644
34300 --- a/drivers/scsi/bfa/bfa_ioc.h
34301 +++ b/drivers/scsi/bfa/bfa_ioc.h
34302 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
34303 bfa_ioc_disable_cbfn_t disable_cbfn;
34304 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
34305 bfa_ioc_reset_cbfn_t reset_cbfn;
34310 * IOC event notification mechanism.
34311 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
34312 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
34313 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
34314 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
34319 * Queue element to wait for room in request queue. FIFO order is
34320 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
34321 index 351dc0b..951dc32 100644
34322 --- a/drivers/scsi/hosts.c
34323 +++ b/drivers/scsi/hosts.c
34325 #include "scsi_logging.h"
34328 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
34329 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
34332 static void scsi_host_cls_release(struct device *dev)
34333 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
34334 * subtract one because we increment first then return, but we need to
34335 * know what the next host number was before increment
34337 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
34338 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
34339 shost->dma_channel = 0xff;
34341 /* These three are default values which can be overridden */
34342 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
34343 index 865d452..e9b7fa7 100644
34344 --- a/drivers/scsi/hpsa.c
34345 +++ b/drivers/scsi/hpsa.c
34346 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
34349 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
34350 - return h->access.command_completed(h);
34351 + return h->access->command_completed(h);
34353 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
34354 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
34355 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
34356 while (!list_empty(&h->reqQ)) {
34357 c = list_entry(h->reqQ.next, struct CommandList, list);
34358 /* can't do anything if fifo is full */
34359 - if ((h->access.fifo_full(h))) {
34360 + if ((h->access->fifo_full(h))) {
34361 dev_warn(&h->pdev->dev, "fifo full\n");
34364 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
34367 /* Tell the controller execute command */
34368 - h->access.submit_command(h, c);
34369 + h->access->submit_command(h, c);
34371 /* Put job onto the completed Q */
34373 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
34375 static inline unsigned long get_next_completion(struct ctlr_info *h)
34377 - return h->access.command_completed(h);
34378 + return h->access->command_completed(h);
34381 static inline bool interrupt_pending(struct ctlr_info *h)
34383 - return h->access.intr_pending(h);
34384 + return h->access->intr_pending(h);
34387 static inline long interrupt_not_for_us(struct ctlr_info *h)
34389 - return (h->access.intr_pending(h) == 0) ||
34390 + return (h->access->intr_pending(h) == 0) ||
34391 (h->interrupts_enabled == 0);
34394 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
34395 if (prod_index < 0)
34397 h->product_name = products[prod_index].product_name;
34398 - h->access = *(products[prod_index].access);
34399 + h->access = products[prod_index].access;
34401 if (hpsa_board_disabled(h->pdev)) {
34402 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
34403 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
34405 assert_spin_locked(&lockup_detector_lock);
34406 remove_ctlr_from_lockup_detector_list(h);
34407 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34408 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34409 spin_lock_irqsave(&h->lock, flags);
34410 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
34411 spin_unlock_irqrestore(&h->lock, flags);
34412 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
34415 /* make sure the board interrupts are off */
34416 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34417 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34419 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
34421 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
34422 * fake ones to scoop up any residual completions.
34424 spin_lock_irqsave(&h->lock, flags);
34425 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34426 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34427 spin_unlock_irqrestore(&h->lock, flags);
34428 free_irq(h->intr[h->intr_mode], h);
34429 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
34430 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
34431 dev_info(&h->pdev->dev, "Board READY.\n");
34432 dev_info(&h->pdev->dev,
34433 "Waiting for stale completions to drain.\n");
34434 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34435 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34437 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34438 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34440 rc = controller_reset_failed(h->cfgtable);
34442 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
34445 /* Turn the interrupts on so we can service requests */
34446 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34447 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34449 hpsa_hba_inquiry(h);
34450 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
34451 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
34452 * To write all data in the battery backed cache to disks
34454 hpsa_flush_cache(h);
34455 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34456 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34457 free_irq(h->intr[h->intr_mode], h);
34458 #ifdef CONFIG_PCI_MSI
34459 if (h->msix_vector)
34460 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
34463 /* Change the access methods to the performant access methods */
34464 - h->access = SA5_performant_access;
34465 + h->access = &SA5_performant_access;
34466 h->transMethod = CFGTBL_Trans_Performant;
34469 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
34470 index 91edafb..a9b88ec 100644
34471 --- a/drivers/scsi/hpsa.h
34472 +++ b/drivers/scsi/hpsa.h
34473 @@ -73,7 +73,7 @@ struct ctlr_info {
34474 unsigned int msix_vector;
34475 unsigned int msi_vector;
34476 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
34477 - struct access_method access;
34478 + struct access_method *access;
34480 /* queue and queue Info */
34481 struct list_head reqQ;
34482 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
34483 index f2df059..a3a9930 100644
34484 --- a/drivers/scsi/ips.h
34485 +++ b/drivers/scsi/ips.h
34486 @@ -1027,7 +1027,7 @@ typedef struct {
34487 int (*intr)(struct ips_ha *);
34488 void (*enableint)(struct ips_ha *);
34489 uint32_t (*statupd)(struct ips_ha *);
34491 +} __no_const ips_hw_func_t;
34493 typedef struct ips_ha {
34494 uint8_t ha_id[IPS_MAX_CHANNELS+1];
34495 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
34496 index 9de9db2..1e09660 100644
34497 --- a/drivers/scsi/libfc/fc_exch.c
34498 +++ b/drivers/scsi/libfc/fc_exch.c
34499 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
34500 * all together if not used XXX
34503 - atomic_t no_free_exch;
34504 - atomic_t no_free_exch_xid;
34505 - atomic_t xid_not_found;
34506 - atomic_t xid_busy;
34507 - atomic_t seq_not_found;
34508 - atomic_t non_bls_resp;
34509 + atomic_unchecked_t no_free_exch;
34510 + atomic_unchecked_t no_free_exch_xid;
34511 + atomic_unchecked_t xid_not_found;
34512 + atomic_unchecked_t xid_busy;
34513 + atomic_unchecked_t seq_not_found;
34514 + atomic_unchecked_t non_bls_resp;
34518 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
34519 /* allocate memory for exchange */
34520 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
34522 - atomic_inc(&mp->stats.no_free_exch);
34523 + atomic_inc_unchecked(&mp->stats.no_free_exch);
34526 memset(ep, 0, sizeof(*ep));
34527 @@ -780,7 +780,7 @@ out:
34530 spin_unlock_bh(&pool->lock);
34531 - atomic_inc(&mp->stats.no_free_exch_xid);
34532 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
34533 mempool_free(ep, mp->ep_pool);
34536 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34537 xid = ntohs(fh->fh_ox_id); /* we originated exch */
34538 ep = fc_exch_find(mp, xid);
34540 - atomic_inc(&mp->stats.xid_not_found);
34541 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34542 reject = FC_RJT_OX_ID;
34545 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34546 ep = fc_exch_find(mp, xid);
34547 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
34549 - atomic_inc(&mp->stats.xid_busy);
34550 + atomic_inc_unchecked(&mp->stats.xid_busy);
34551 reject = FC_RJT_RX_ID;
34554 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34556 xid = ep->xid; /* get our XID */
34558 - atomic_inc(&mp->stats.xid_not_found);
34559 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34560 reject = FC_RJT_RX_ID; /* XID not found */
34563 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34566 if (sp->id != fh->fh_seq_id) {
34567 - atomic_inc(&mp->stats.seq_not_found);
34568 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34569 if (f_ctl & FC_FC_END_SEQ) {
34571 * Update sequence_id based on incoming last
34572 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34574 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
34576 - atomic_inc(&mp->stats.xid_not_found);
34577 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34580 if (ep->esb_stat & ESB_ST_COMPLETE) {
34581 - atomic_inc(&mp->stats.xid_not_found);
34582 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34585 if (ep->rxid == FC_XID_UNKNOWN)
34586 ep->rxid = ntohs(fh->fh_rx_id);
34587 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
34588 - atomic_inc(&mp->stats.xid_not_found);
34589 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34592 if (ep->did != ntoh24(fh->fh_s_id) &&
34593 ep->did != FC_FID_FLOGI) {
34594 - atomic_inc(&mp->stats.xid_not_found);
34595 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34599 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34600 sp->ssb_stat |= SSB_ST_RESP;
34601 sp->id = fh->fh_seq_id;
34602 } else if (sp->id != fh->fh_seq_id) {
34603 - atomic_inc(&mp->stats.seq_not_found);
34604 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34608 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34609 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
34612 - atomic_inc(&mp->stats.xid_not_found);
34613 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34615 - atomic_inc(&mp->stats.non_bls_resp);
34616 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
34620 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
34621 index db9238f..4378ed2 100644
34622 --- a/drivers/scsi/libsas/sas_ata.c
34623 +++ b/drivers/scsi/libsas/sas_ata.c
34624 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
34625 .postreset = ata_std_postreset,
34626 .error_handler = ata_std_error_handler,
34627 .post_internal_cmd = sas_ata_post_internal,
34628 - .qc_defer = ata_std_qc_defer,
34629 + .qc_defer = ata_std_qc_defer,
34630 .qc_prep = ata_noop_qc_prep,
34631 .qc_issue = sas_ata_qc_issue,
34632 .qc_fill_rtf = sas_ata_qc_fill_rtf,
34633 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
34634 index bb4c8e0..f33d849 100644
34635 --- a/drivers/scsi/lpfc/lpfc.h
34636 +++ b/drivers/scsi/lpfc/lpfc.h
34637 @@ -425,7 +425,7 @@ struct lpfc_vport {
34638 struct dentry *debug_nodelist;
34639 struct dentry *vport_debugfs_root;
34640 struct lpfc_debugfs_trc *disc_trc;
34641 - atomic_t disc_trc_cnt;
34642 + atomic_unchecked_t disc_trc_cnt;
34644 uint8_t stat_data_enabled;
34645 uint8_t stat_data_blocked;
34646 @@ -835,8 +835,8 @@ struct lpfc_hba {
34647 struct timer_list fabric_block_timer;
34648 unsigned long bit_flags;
34649 #define FABRIC_COMANDS_BLOCKED 0
34650 - atomic_t num_rsrc_err;
34651 - atomic_t num_cmd_success;
34652 + atomic_unchecked_t num_rsrc_err;
34653 + atomic_unchecked_t num_cmd_success;
34654 unsigned long last_rsrc_error_time;
34655 unsigned long last_ramp_down_time;
34656 unsigned long last_ramp_up_time;
34657 @@ -866,7 +866,7 @@ struct lpfc_hba {
34659 struct dentry *debug_slow_ring_trc;
34660 struct lpfc_debugfs_trc *slow_ring_trc;
34661 - atomic_t slow_ring_trc_cnt;
34662 + atomic_unchecked_t slow_ring_trc_cnt;
34663 /* iDiag debugfs sub-directory */
34664 struct dentry *idiag_root;
34665 struct dentry *idiag_pci_cfg;
34666 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
34667 index 2838259..a07cfb5 100644
34668 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
34669 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
34670 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
34672 #include <linux/debugfs.h>
34674 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34675 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34676 static unsigned long lpfc_debugfs_start_time = 0L;
34679 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
34680 lpfc_debugfs_enable = 0;
34683 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
34684 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
34685 (lpfc_debugfs_max_disc_trc - 1);
34686 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
34687 dtp = vport->disc_trc + i;
34688 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
34689 lpfc_debugfs_enable = 0;
34692 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
34693 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
34694 (lpfc_debugfs_max_slow_ring_trc - 1);
34695 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
34696 dtp = phba->slow_ring_trc + i;
34697 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
34698 !vport || !vport->disc_trc)
34701 - index = atomic_inc_return(&vport->disc_trc_cnt) &
34702 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
34703 (lpfc_debugfs_max_disc_trc - 1);
34704 dtp = vport->disc_trc + index;
34706 dtp->data1 = data1;
34707 dtp->data2 = data2;
34708 dtp->data3 = data3;
34709 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34710 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34711 dtp->jif = jiffies;
34714 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
34715 !phba || !phba->slow_ring_trc)
34718 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
34719 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
34720 (lpfc_debugfs_max_slow_ring_trc - 1);
34721 dtp = phba->slow_ring_trc + index;
34723 dtp->data1 = data1;
34724 dtp->data2 = data2;
34725 dtp->data3 = data3;
34726 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34727 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34728 dtp->jif = jiffies;
34731 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34732 "slow_ring buffer\n");
34735 - atomic_set(&phba->slow_ring_trc_cnt, 0);
34736 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
34737 memset(phba->slow_ring_trc, 0,
34738 (sizeof(struct lpfc_debugfs_trc) *
34739 lpfc_debugfs_max_slow_ring_trc));
34740 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34744 - atomic_set(&vport->disc_trc_cnt, 0);
34745 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
34747 snprintf(name, sizeof(name), "discovery_trace");
34748 vport->debug_disc_trc =
34749 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
34750 index 55bc4fc..a2a109c 100644
34751 --- a/drivers/scsi/lpfc/lpfc_init.c
34752 +++ b/drivers/scsi/lpfc/lpfc_init.c
34753 @@ -10027,8 +10027,10 @@ lpfc_init(void)
34754 printk(LPFC_COPYRIGHT "\n");
34756 if (lpfc_enable_npiv) {
34757 - lpfc_transport_functions.vport_create = lpfc_vport_create;
34758 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34759 + pax_open_kernel();
34760 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
34761 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34762 + pax_close_kernel();
34764 lpfc_transport_template =
34765 fc_attach_transport(&lpfc_transport_functions);
34766 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
34767 index 2e1e54e..1af0a0d 100644
34768 --- a/drivers/scsi/lpfc/lpfc_scsi.c
34769 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
34770 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
34771 uint32_t evt_posted;
34773 spin_lock_irqsave(&phba->hbalock, flags);
34774 - atomic_inc(&phba->num_rsrc_err);
34775 + atomic_inc_unchecked(&phba->num_rsrc_err);
34776 phba->last_rsrc_error_time = jiffies;
34778 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
34779 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
34780 unsigned long flags;
34781 struct lpfc_hba *phba = vport->phba;
34782 uint32_t evt_posted;
34783 - atomic_inc(&phba->num_cmd_success);
34784 + atomic_inc_unchecked(&phba->num_cmd_success);
34786 if (vport->cfg_lun_queue_depth <= queue_depth)
34788 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34789 unsigned long num_rsrc_err, num_cmd_success;
34792 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
34793 - num_cmd_success = atomic_read(&phba->num_cmd_success);
34794 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
34795 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
34797 vports = lpfc_create_vport_work_array(phba);
34798 if (vports != NULL)
34799 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34802 lpfc_destroy_vport_work_array(phba, vports);
34803 - atomic_set(&phba->num_rsrc_err, 0);
34804 - atomic_set(&phba->num_cmd_success, 0);
34805 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34806 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34810 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
34813 lpfc_destroy_vport_work_array(phba, vports);
34814 - atomic_set(&phba->num_rsrc_err, 0);
34815 - atomic_set(&phba->num_cmd_success, 0);
34816 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34817 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34821 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
34822 index 5163edb..7b142bc 100644
34823 --- a/drivers/scsi/pmcraid.c
34824 +++ b/drivers/scsi/pmcraid.c
34825 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
34826 res->scsi_dev = scsi_dev;
34827 scsi_dev->hostdata = res;
34828 res->change_detected = 0;
34829 - atomic_set(&res->read_failures, 0);
34830 - atomic_set(&res->write_failures, 0);
34831 + atomic_set_unchecked(&res->read_failures, 0);
34832 + atomic_set_unchecked(&res->write_failures, 0);
34835 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
34836 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
34838 /* If this was a SCSI read/write command keep count of errors */
34839 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
34840 - atomic_inc(&res->read_failures);
34841 + atomic_inc_unchecked(&res->read_failures);
34842 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
34843 - atomic_inc(&res->write_failures);
34844 + atomic_inc_unchecked(&res->write_failures);
34846 if (!RES_IS_GSCSI(res->cfg_entry) &&
34847 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
34848 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
34849 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34850 * hrrq_id assigned here in queuecommand
34852 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34853 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34854 pinstance->num_hrrq;
34855 cmd->cmd_done = pmcraid_io_done;
34857 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
34858 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34859 * hrrq_id assigned here in queuecommand
34861 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34862 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34863 pinstance->num_hrrq;
34865 if (request_size) {
34866 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
34868 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
34869 /* add resources only after host is added into system */
34870 - if (!atomic_read(&pinstance->expose_resources))
34871 + if (!atomic_read_unchecked(&pinstance->expose_resources))
34874 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
34875 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
34876 init_waitqueue_head(&pinstance->reset_wait_q);
34878 atomic_set(&pinstance->outstanding_cmds, 0);
34879 - atomic_set(&pinstance->last_message_id, 0);
34880 - atomic_set(&pinstance->expose_resources, 0);
34881 + atomic_set_unchecked(&pinstance->last_message_id, 0);
34882 + atomic_set_unchecked(&pinstance->expose_resources, 0);
34884 INIT_LIST_HEAD(&pinstance->free_res_q);
34885 INIT_LIST_HEAD(&pinstance->used_res_q);
34886 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
34887 /* Schedule worker thread to handle CCN and take care of adding and
34888 * removing devices to OS
34890 - atomic_set(&pinstance->expose_resources, 1);
34891 + atomic_set_unchecked(&pinstance->expose_resources, 1);
34892 schedule_work(&pinstance->worker_q);
34895 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
34896 index ca496c7..9c791d5 100644
34897 --- a/drivers/scsi/pmcraid.h
34898 +++ b/drivers/scsi/pmcraid.h
34899 @@ -748,7 +748,7 @@ struct pmcraid_instance {
34900 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
34902 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
34903 - atomic_t last_message_id;
34904 + atomic_unchecked_t last_message_id;
34906 /* configuration table */
34907 struct pmcraid_config_table *cfg_table;
34908 @@ -777,7 +777,7 @@ struct pmcraid_instance {
34909 atomic_t outstanding_cmds;
34911 /* should add/delete resources to mid-layer now ?*/
34912 - atomic_t expose_resources;
34913 + atomic_unchecked_t expose_resources;
34917 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
34918 struct pmcraid_config_table_entry_ext cfg_entry_ext;
34920 struct scsi_device *scsi_dev; /* Link scsi_device structure */
34921 - atomic_t read_failures; /* count of failed READ commands */
34922 - atomic_t write_failures; /* count of failed WRITE commands */
34923 + atomic_unchecked_t read_failures; /* count of failed READ commands */
34924 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
34926 /* To indicate add/delete/modify during CCN */
34927 u8 change_detected;
34928 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
34929 index fcf052c..a8025a4 100644
34930 --- a/drivers/scsi/qla2xxx/qla_def.h
34931 +++ b/drivers/scsi/qla2xxx/qla_def.h
34932 @@ -2244,7 +2244,7 @@ struct isp_operations {
34933 int (*get_flash_version) (struct scsi_qla_host *, void *);
34934 int (*start_scsi) (srb_t *);
34935 int (*abort_isp) (struct scsi_qla_host *);
34939 /* MSI-X Support *************************************************************/
34941 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
34942 index fd5edc6..4906148 100644
34943 --- a/drivers/scsi/qla4xxx/ql4_def.h
34944 +++ b/drivers/scsi/qla4xxx/ql4_def.h
34945 @@ -258,7 +258,7 @@ struct ddb_entry {
34947 atomic_t relogin_timer; /* Max Time to wait for
34948 * relogin to complete */
34949 - atomic_t relogin_retry_count; /* Num of times relogin has been
34950 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
34952 uint32_t default_time2wait; /* Default Min time between
34953 * relogins (+aens) */
34954 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
34955 index 4169c8b..a8b896b 100644
34956 --- a/drivers/scsi/qla4xxx/ql4_os.c
34957 +++ b/drivers/scsi/qla4xxx/ql4_os.c
34958 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
34960 if (!iscsi_is_session_online(cls_sess)) {
34961 /* Reset retry relogin timer */
34962 - atomic_inc(&ddb_entry->relogin_retry_count);
34963 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
34964 DEBUG2(ql4_printk(KERN_INFO, ha,
34965 "%s: index[%d] relogin timed out-retrying"
34966 " relogin (%d), retry (%d)\n", __func__,
34967 ddb_entry->fw_ddb_index,
34968 - atomic_read(&ddb_entry->relogin_retry_count),
34969 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
34970 ddb_entry->default_time2wait + 4));
34971 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
34972 atomic_set(&ddb_entry->retry_relogin_timer,
34973 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
34975 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
34976 atomic_set(&ddb_entry->relogin_timer, 0);
34977 - atomic_set(&ddb_entry->relogin_retry_count, 0);
34978 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
34980 ddb_entry->default_relogin_timeout =
34981 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
34982 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
34983 index 2aeb2e9..46e3925 100644
34984 --- a/drivers/scsi/scsi.c
34985 +++ b/drivers/scsi/scsi.c
34986 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
34987 unsigned long timeout;
34990 - atomic_inc(&cmd->device->iorequest_cnt);
34991 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34993 /* check if the device is still usable */
34994 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
34995 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
34996 index f85cfa6..a57c9e8 100644
34997 --- a/drivers/scsi/scsi_lib.c
34998 +++ b/drivers/scsi/scsi_lib.c
34999 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
35000 shost = sdev->host;
35001 scsi_init_cmd_errh(cmd);
35002 cmd->result = DID_NO_CONNECT << 16;
35003 - atomic_inc(&cmd->device->iorequest_cnt);
35004 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
35007 * SCSI request completion path will do scsi_device_unbusy(),
35008 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
35010 INIT_LIST_HEAD(&cmd->eh_entry);
35012 - atomic_inc(&cmd->device->iodone_cnt);
35013 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
35015 - atomic_inc(&cmd->device->ioerr_cnt);
35016 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
35018 disposition = scsi_decide_disposition(cmd);
35019 if (disposition != SUCCESS &&
35020 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
35021 index 04c2a27..9d8bd66 100644
35022 --- a/drivers/scsi/scsi_sysfs.c
35023 +++ b/drivers/scsi/scsi_sysfs.c
35024 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
35027 struct scsi_device *sdev = to_scsi_device(dev); \
35028 - unsigned long long count = atomic_read(&sdev->field); \
35029 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
35030 return snprintf(buf, 20, "0x%llx\n", count); \
35032 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
35033 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
35034 index 84a1fdf..693b0d6 100644
35035 --- a/drivers/scsi/scsi_tgt_lib.c
35036 +++ b/drivers/scsi/scsi_tgt_lib.c
35037 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
35040 dprintk("%lx %u\n", uaddr, len);
35041 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
35042 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
35045 * TODO: need to fixup sg_tablesize, max_segment_size,
35046 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
35047 index 1b21491..1b7f60e 100644
35048 --- a/drivers/scsi/scsi_transport_fc.c
35049 +++ b/drivers/scsi/scsi_transport_fc.c
35050 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
35051 * Netlink Infrastructure
35054 -static atomic_t fc_event_seq;
35055 +static atomic_unchecked_t fc_event_seq;
35058 * fc_get_event_number - Obtain the next sequential FC event number
35059 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
35061 fc_get_event_number(void)
35063 - return atomic_add_return(1, &fc_event_seq);
35064 + return atomic_add_return_unchecked(1, &fc_event_seq);
35066 EXPORT_SYMBOL(fc_get_event_number);
35068 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
35072 - atomic_set(&fc_event_seq, 0);
35073 + atomic_set_unchecked(&fc_event_seq, 0);
35075 error = transport_class_register(&fc_host_class);
35077 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
35080 *val = simple_strtoul(buf, &cp, 0);
35081 - if ((*cp && (*cp != '\n')) || (*val < 0))
35082 + if (*cp && (*cp != '\n'))
35085 * Check for overflow; dev_loss_tmo is u32
35086 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
35087 index 96029e6..4d77fa0 100644
35088 --- a/drivers/scsi/scsi_transport_iscsi.c
35089 +++ b/drivers/scsi/scsi_transport_iscsi.c
35090 @@ -79,7 +79,7 @@ struct iscsi_internal {
35091 struct transport_container session_cont;
35094 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
35095 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
35096 static struct workqueue_struct *iscsi_eh_timer_workq;
35098 static DEFINE_IDA(iscsi_sess_ida);
35099 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
35102 ihost = shost->shost_data;
35103 - session->sid = atomic_add_return(1, &iscsi_session_nr);
35104 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
35106 if (target_id == ISCSI_MAX_TARGET) {
35107 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
35108 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
35109 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
35110 ISCSI_TRANSPORT_VERSION);
35112 - atomic_set(&iscsi_session_nr, 0);
35113 + atomic_set_unchecked(&iscsi_session_nr, 0);
35115 err = class_register(&iscsi_transport_class);
35117 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
35118 index 21a045e..ec89e03 100644
35119 --- a/drivers/scsi/scsi_transport_srp.c
35120 +++ b/drivers/scsi/scsi_transport_srp.c
35122 #include "scsi_transport_srp_internal.h"
35124 struct srp_host_attrs {
35125 - atomic_t next_port_id;
35126 + atomic_unchecked_t next_port_id;
35128 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
35130 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
35131 struct Scsi_Host *shost = dev_to_shost(dev);
35132 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
35134 - atomic_set(&srp_host->next_port_id, 0);
35135 + atomic_set_unchecked(&srp_host->next_port_id, 0);
35139 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
35140 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
35141 rport->roles = ids->roles;
35143 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
35144 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
35145 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
35147 transport_setup_device(&rport->dev);
35148 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
35149 index 441a1c5..07cece7 100644
35150 --- a/drivers/scsi/sg.c
35151 +++ b/drivers/scsi/sg.c
35152 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
35153 sdp->disk->disk_name,
35154 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
35157 + (char __user *)arg);
35158 case BLKTRACESTART:
35159 return blk_trace_startstop(sdp->device->request_queue, 1);
35161 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
35162 const struct file_operations * fops;
35165 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
35166 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
35167 {"allow_dio", &adio_fops},
35168 {"debug", &debug_fops},
35169 {"def_reserved_size", &dressz_fops},
35170 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
35173 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
35174 - struct sg_proc_leaf * leaf;
35175 + const struct sg_proc_leaf * leaf;
35177 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
35179 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
35180 index f64250e..1ee3049 100644
35181 --- a/drivers/spi/spi-dw-pci.c
35182 +++ b/drivers/spi/spi-dw-pci.c
35183 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
35184 #define spi_resume NULL
35187 -static const struct pci_device_id pci_ids[] __devinitdata = {
35188 +static const struct pci_device_id pci_ids[] __devinitconst = {
35189 /* Intel MID platform SPI controller 0 */
35190 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
35192 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
35193 index 77eae99..b7cdcc9 100644
35194 --- a/drivers/spi/spi.c
35195 +++ b/drivers/spi/spi.c
35196 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
35197 EXPORT_SYMBOL_GPL(spi_bus_unlock);
35199 /* portable code must never pass more than 32 bytes */
35200 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
35201 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
35205 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
35206 index 436fe97..4082570 100644
35207 --- a/drivers/staging/gma500/power.c
35208 +++ b/drivers/staging/gma500/power.c
35209 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
35210 ret = gma_resume_pci(dev->pdev);
35212 /* FIXME: we want to defer this for Medfield/Oaktrail */
35213 - gma_resume_display(dev);
35214 + gma_resume_display(dev->pdev);
35215 psb_irq_preinstall(dev);
35216 psb_irq_postinstall(dev);
35217 pm_runtime_get(&dev->pdev->dev);
35218 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
35219 index bafccb3..e3ac78d 100644
35220 --- a/drivers/staging/hv/rndis_filter.c
35221 +++ b/drivers/staging/hv/rndis_filter.c
35222 @@ -42,7 +42,7 @@ struct rndis_device {
35224 enum rndis_device_state state;
35226 - atomic_t new_req_id;
35227 + atomic_unchecked_t new_req_id;
35229 spinlock_t request_lock;
35230 struct list_head req_list;
35231 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35234 set = &rndis_msg->msg.set_req;
35235 - set->req_id = atomic_inc_return(&dev->new_req_id);
35236 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35238 /* Add to the request list */
35239 spin_lock_irqsave(&dev->request_lock, flags);
35240 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35242 /* Setup the rndis set */
35243 halt = &request->request_msg.msg.halt_req;
35244 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35245 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35247 /* Ignore return since this msg is optional. */
35248 rndis_filter_send_request(dev, request);
35249 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
35250 index 9e8f010..af9efb56 100644
35251 --- a/drivers/staging/iio/buffer_generic.h
35252 +++ b/drivers/staging/iio/buffer_generic.h
35253 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
35255 int (*is_enabled)(struct iio_buffer *buffer);
35256 int (*enable)(struct iio_buffer *buffer);
35261 * struct iio_buffer_setup_ops - buffer setup related callbacks
35262 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
35263 index 8b307b4..a97ac91 100644
35264 --- a/drivers/staging/octeon/ethernet-rx.c
35265 +++ b/drivers/staging/octeon/ethernet-rx.c
35266 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
35267 /* Increment RX stats for virtual ports */
35268 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
35269 #ifdef CONFIG_64BIT
35270 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
35271 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
35272 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
35273 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
35275 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
35276 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
35277 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
35278 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
35281 netif_receive_skb(skb);
35282 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
35285 #ifdef CONFIG_64BIT
35286 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
35287 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35289 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
35290 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
35292 dev_kfree_skb_irq(skb);
35294 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
35295 index 076f866..2308070 100644
35296 --- a/drivers/staging/octeon/ethernet.c
35297 +++ b/drivers/staging/octeon/ethernet.c
35298 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
35299 * since the RX tasklet also increments it.
35301 #ifdef CONFIG_64BIT
35302 - atomic64_add(rx_status.dropped_packets,
35303 - (atomic64_t *)&priv->stats.rx_dropped);
35304 + atomic64_add_unchecked(rx_status.dropped_packets,
35305 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35307 - atomic_add(rx_status.dropped_packets,
35308 - (atomic_t *)&priv->stats.rx_dropped);
35309 + atomic_add_unchecked(rx_status.dropped_packets,
35310 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
35314 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
35315 index 7a19555..466456d 100644
35316 --- a/drivers/staging/pohmelfs/inode.c
35317 +++ b/drivers/staging/pohmelfs/inode.c
35318 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35319 mutex_init(&psb->mcache_lock);
35320 psb->mcache_root = RB_ROOT;
35321 psb->mcache_timeout = msecs_to_jiffies(5000);
35322 - atomic_long_set(&psb->mcache_gen, 0);
35323 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
35325 psb->trans_max_pages = 100;
35327 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35328 INIT_LIST_HEAD(&psb->crypto_ready_list);
35329 INIT_LIST_HEAD(&psb->crypto_active_list);
35331 - atomic_set(&psb->trans_gen, 1);
35332 + atomic_set_unchecked(&psb->trans_gen, 1);
35333 atomic_long_set(&psb->total_inodes, 0);
35335 mutex_init(&psb->state_lock);
35336 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
35337 index e22665c..a2a9390 100644
35338 --- a/drivers/staging/pohmelfs/mcache.c
35339 +++ b/drivers/staging/pohmelfs/mcache.c
35340 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
35344 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
35345 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
35347 mutex_lock(&psb->mcache_lock);
35348 err = pohmelfs_mcache_insert(psb, m);
35349 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
35350 index 985b6b7..7699e05 100644
35351 --- a/drivers/staging/pohmelfs/netfs.h
35352 +++ b/drivers/staging/pohmelfs/netfs.h
35353 @@ -571,14 +571,14 @@ struct pohmelfs_config;
35354 struct pohmelfs_sb {
35355 struct rb_root mcache_root;
35356 struct mutex mcache_lock;
35357 - atomic_long_t mcache_gen;
35358 + atomic_long_unchecked_t mcache_gen;
35359 unsigned long mcache_timeout;
35363 unsigned int trans_retries;
35365 - atomic_t trans_gen;
35366 + atomic_unchecked_t trans_gen;
35368 unsigned int crypto_attached_size;
35369 unsigned int crypto_align_size;
35370 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
35371 index 06c1a74..866eebc 100644
35372 --- a/drivers/staging/pohmelfs/trans.c
35373 +++ b/drivers/staging/pohmelfs/trans.c
35374 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
35376 struct netfs_cmd *cmd = t->iovec.iov_base;
35378 - t->gen = atomic_inc_return(&psb->trans_gen);
35379 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
35381 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
35382 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
35383 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
35384 index 86308a0..feaa925 100644
35385 --- a/drivers/staging/rtl8712/rtl871x_io.h
35386 +++ b/drivers/staging/rtl8712/rtl871x_io.h
35387 @@ -108,7 +108,7 @@ struct _io_ops {
35389 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
35395 struct list_head list;
35396 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
35397 index c7b5e8b..783d6cb 100644
35398 --- a/drivers/staging/sbe-2t3e3/netdev.c
35399 +++ b/drivers/staging/sbe-2t3e3/netdev.c
35400 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35401 t3e3_if_config(sc, cmd_2t3e3, (char *)¶m, &resp, &rlen);
35404 - if (copy_to_user(data, &resp, rlen))
35405 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
35409 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
35410 index be21617..0954e45 100644
35411 --- a/drivers/staging/usbip/usbip_common.h
35412 +++ b/drivers/staging/usbip/usbip_common.h
35413 @@ -289,7 +289,7 @@ struct usbip_device {
35414 void (*shutdown)(struct usbip_device *);
35415 void (*reset)(struct usbip_device *);
35416 void (*unusable)(struct usbip_device *);
35418 + } __no_const eh_ops;
35422 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
35423 index 88b3298..3783eee 100644
35424 --- a/drivers/staging/usbip/vhci.h
35425 +++ b/drivers/staging/usbip/vhci.h
35426 @@ -88,7 +88,7 @@ struct vhci_hcd {
35427 unsigned resuming:1;
35428 unsigned long re_timeout;
35431 + atomic_unchecked_t seqnum;
35435 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
35436 index 2ee97e2..0420b86 100644
35437 --- a/drivers/staging/usbip/vhci_hcd.c
35438 +++ b/drivers/staging/usbip/vhci_hcd.c
35439 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
35443 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
35444 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35445 if (priv->seqnum == 0xffff)
35446 dev_info(&urb->dev->dev, "seqnum max\n");
35448 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
35452 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
35453 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35454 if (unlink->seqnum == 0xffff)
35455 pr_info("seqnum max\n");
35457 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
35458 vdev->rhport = rhport;
35461 - atomic_set(&vhci->seqnum, 0);
35462 + atomic_set_unchecked(&vhci->seqnum, 0);
35463 spin_lock_init(&vhci->lock);
35465 hcd->power_budget = 0; /* no limit */
35466 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
35467 index 3872b8c..fe6d2f4 100644
35468 --- a/drivers/staging/usbip/vhci_rx.c
35469 +++ b/drivers/staging/usbip/vhci_rx.c
35470 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
35472 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
35473 pr_info("max seqnum %d\n",
35474 - atomic_read(&the_controller->seqnum));
35475 + atomic_read_unchecked(&the_controller->seqnum));
35476 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
35479 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
35480 index 7735027..30eed13 100644
35481 --- a/drivers/staging/vt6655/hostap.c
35482 +++ b/drivers/staging/vt6655/hostap.c
35483 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
35487 +static net_device_ops_no_const apdev_netdev_ops;
35489 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35491 PSDevice apdev_priv;
35492 struct net_device *dev = pDevice->dev;
35494 - const struct net_device_ops apdev_netdev_ops = {
35495 - .ndo_start_xmit = pDevice->tx_80211,
35498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35500 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35501 *apdev_priv = *pDevice;
35502 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35504 + /* only half broken now */
35505 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35506 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35508 pDevice->apdev->type = ARPHRD_IEEE80211;
35509 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
35510 index 51b5adf..098e320 100644
35511 --- a/drivers/staging/vt6656/hostap.c
35512 +++ b/drivers/staging/vt6656/hostap.c
35513 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
35517 +static net_device_ops_no_const apdev_netdev_ops;
35519 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35521 PSDevice apdev_priv;
35522 struct net_device *dev = pDevice->dev;
35524 - const struct net_device_ops apdev_netdev_ops = {
35525 - .ndo_start_xmit = pDevice->tx_80211,
35528 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35530 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35531 *apdev_priv = *pDevice;
35532 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35534 + /* only half broken now */
35535 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35536 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35538 pDevice->apdev->type = ARPHRD_IEEE80211;
35539 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
35540 index 7843dfd..3db105f 100644
35541 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
35542 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
35543 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
35545 struct usbctlx_completor {
35546 int (*complete) (struct usbctlx_completor *);
35551 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
35552 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
35553 index 1ca66ea..76f1343 100644
35554 --- a/drivers/staging/zcache/tmem.c
35555 +++ b/drivers/staging/zcache/tmem.c
35557 * A tmem host implementation must use this function to register callbacks
35558 * for memory allocation.
35560 -static struct tmem_hostops tmem_hostops;
35561 +static tmem_hostops_no_const tmem_hostops;
35563 static void tmem_objnode_tree_init(void);
35565 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
35566 * A tmem host implementation must use this function to register
35567 * callbacks for a page-accessible memory (PAM) implementation
35569 -static struct tmem_pamops tmem_pamops;
35570 +static tmem_pamops_no_const tmem_pamops;
35572 void tmem_register_pamops(struct tmem_pamops *m)
35574 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
35575 index ed147c4..94fc3c6 100644
35576 --- a/drivers/staging/zcache/tmem.h
35577 +++ b/drivers/staging/zcache/tmem.h
35578 @@ -180,6 +180,7 @@ struct tmem_pamops {
35579 void (*new_obj)(struct tmem_obj *);
35580 int (*replace_in_obj)(void *, struct tmem_obj *);
35582 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
35583 extern void tmem_register_pamops(struct tmem_pamops *m);
35585 /* memory allocation methods provided by the host implementation */
35586 @@ -189,6 +190,7 @@ struct tmem_hostops {
35587 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
35588 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
35590 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
35591 extern void tmem_register_hostops(struct tmem_hostops *m);
35593 /* core tmem accessor functions */
35594 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
35595 index 0c1d5c73..88e90a8 100644
35596 --- a/drivers/target/iscsi/iscsi_target.c
35597 +++ b/drivers/target/iscsi/iscsi_target.c
35598 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
35599 * outstanding_r2ts reaches zero, go ahead and send the delayed
35600 * TASK_ABORTED status.
35602 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
35603 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
35604 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
35605 if (--cmd->outstanding_r2ts < 1) {
35606 iscsit_stop_dataout_timer(cmd);
35607 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
35608 index 6845228..df77141 100644
35609 --- a/drivers/target/target_core_tmr.c
35610 +++ b/drivers/target/target_core_tmr.c
35611 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
35612 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
35613 cmd->t_task_list_num,
35614 atomic_read(&cmd->t_task_cdbs_left),
35615 - atomic_read(&cmd->t_task_cdbs_sent),
35616 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35617 atomic_read(&cmd->t_transport_active),
35618 atomic_read(&cmd->t_transport_stop),
35619 atomic_read(&cmd->t_transport_sent));
35620 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
35621 pr_debug("LUN_RESET: got t_transport_active = 1 for"
35622 " task: %p, t_fe_count: %d dev: %p\n", task,
35624 - atomic_set(&cmd->t_transport_aborted, 1);
35625 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35626 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35628 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35629 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
35631 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
35632 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
35633 - atomic_set(&cmd->t_transport_aborted, 1);
35634 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35635 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35637 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35638 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
35639 index e4ddb93..2fc6e0f 100644
35640 --- a/drivers/target/target_core_transport.c
35641 +++ b/drivers/target/target_core_transport.c
35642 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
35644 dev->queue_depth = dev_limits->queue_depth;
35645 atomic_set(&dev->depth_left, dev->queue_depth);
35646 - atomic_set(&dev->dev_ordered_id, 0);
35647 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
35649 se_dev_set_default_attribs(dev, dev_limits);
35651 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
35652 * Used to determine when ORDERED commands should go from
35653 * Dormant to Active status.
35655 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
35656 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
35657 smp_mb__after_atomic_inc();
35658 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
35659 cmd->se_ordered_id, cmd->sam_task_attr,
35660 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
35661 " t_transport_active: %d t_transport_stop: %d"
35662 " t_transport_sent: %d\n", cmd->t_task_list_num,
35663 atomic_read(&cmd->t_task_cdbs_left),
35664 - atomic_read(&cmd->t_task_cdbs_sent),
35665 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35666 atomic_read(&cmd->t_task_cdbs_ex_left),
35667 atomic_read(&cmd->t_transport_active),
35668 atomic_read(&cmd->t_transport_stop),
35669 @@ -2089,9 +2089,9 @@ check_depth:
35671 spin_lock_irqsave(&cmd->t_state_lock, flags);
35672 task->task_flags |= (TF_ACTIVE | TF_SENT);
35673 - atomic_inc(&cmd->t_task_cdbs_sent);
35674 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
35676 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
35677 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
35678 cmd->t_task_list_num)
35679 atomic_set(&cmd->t_transport_sent, 1);
35681 @@ -4296,7 +4296,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
35682 atomic_set(&cmd->transport_lun_stop, 0);
35684 if (!atomic_read(&cmd->t_transport_active) ||
35685 - atomic_read(&cmd->t_transport_aborted)) {
35686 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
35687 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35690 @@ -4545,7 +4545,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
35694 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
35695 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
35696 if (!send_status ||
35697 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
35699 @@ -4582,7 +4582,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
35701 if (cmd->data_direction == DMA_TO_DEVICE) {
35702 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
35703 - atomic_inc(&cmd->t_transport_aborted);
35704 + atomic_inc_unchecked(&cmd->t_transport_aborted);
35705 smp_mb__after_atomic_inc();
35708 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
35709 index b9040be..e3f5aab 100644
35710 --- a/drivers/tty/hvc/hvcs.c
35711 +++ b/drivers/tty/hvc/hvcs.c
35713 #include <asm/hvcserver.h>
35714 #include <asm/uaccess.h>
35715 #include <asm/vio.h>
35716 +#include <asm/local.h>
35719 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
35720 @@ -270,7 +271,7 @@ struct hvcs_struct {
35721 unsigned int index;
35723 struct tty_struct *tty;
35725 + local_t open_count;
35728 * Used to tell the driver kernel_thread what operations need to take
35729 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
35731 spin_lock_irqsave(&hvcsd->lock, flags);
35733 - if (hvcsd->open_count > 0) {
35734 + if (local_read(&hvcsd->open_count) > 0) {
35735 spin_unlock_irqrestore(&hvcsd->lock, flags);
35736 printk(KERN_INFO "HVCS: vterm state unchanged. "
35737 "The hvcs device node is still in use.\n");
35738 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
35739 if ((retval = hvcs_partner_connect(hvcsd)))
35740 goto error_release;
35742 - hvcsd->open_count = 1;
35743 + local_set(&hvcsd->open_count, 1);
35745 tty->driver_data = hvcsd;
35747 @@ -1179,7 +1180,7 @@ fast_open:
35749 spin_lock_irqsave(&hvcsd->lock, flags);
35750 kref_get(&hvcsd->kref);
35751 - hvcsd->open_count++;
35752 + local_inc(&hvcsd->open_count);
35753 hvcsd->todo_mask |= HVCS_SCHED_READ;
35754 spin_unlock_irqrestore(&hvcsd->lock, flags);
35756 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35757 hvcsd = tty->driver_data;
35759 spin_lock_irqsave(&hvcsd->lock, flags);
35760 - if (--hvcsd->open_count == 0) {
35761 + if (local_dec_and_test(&hvcsd->open_count)) {
35763 vio_disable_interrupts(hvcsd->vdev);
35765 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35766 free_irq(irq, hvcsd);
35767 kref_put(&hvcsd->kref, destroy_hvcs_struct);
35769 - } else if (hvcsd->open_count < 0) {
35770 + } else if (local_read(&hvcsd->open_count) < 0) {
35771 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
35772 " is missmanaged.\n",
35773 - hvcsd->vdev->unit_address, hvcsd->open_count);
35774 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
35777 spin_unlock_irqrestore(&hvcsd->lock, flags);
35778 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35780 spin_lock_irqsave(&hvcsd->lock, flags);
35781 /* Preserve this so that we know how many kref refs to put */
35782 - temp_open_count = hvcsd->open_count;
35783 + temp_open_count = local_read(&hvcsd->open_count);
35786 * Don't kref put inside the spinlock because the destruction
35787 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35788 hvcsd->tty->driver_data = NULL;
35791 - hvcsd->open_count = 0;
35792 + local_set(&hvcsd->open_count, 0);
35794 /* This will drop any buffered data on the floor which is OK in a hangup
35796 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
35797 * the middle of a write operation? This is a crummy place to do this
35798 * but we want to keep it all in the spinlock.
35800 - if (hvcsd->open_count <= 0) {
35801 + if (local_read(&hvcsd->open_count) <= 0) {
35802 spin_unlock_irqrestore(&hvcsd->lock, flags);
35805 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
35807 struct hvcs_struct *hvcsd = tty->driver_data;
35809 - if (!hvcsd || hvcsd->open_count <= 0)
35810 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
35813 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
35814 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
35815 index ef92869..f4ebd88 100644
35816 --- a/drivers/tty/ipwireless/tty.c
35817 +++ b/drivers/tty/ipwireless/tty.c
35819 #include <linux/tty_driver.h>
35820 #include <linux/tty_flip.h>
35821 #include <linux/uaccess.h>
35822 +#include <asm/local.h>
35825 #include "network.h"
35826 @@ -51,7 +52,7 @@ struct ipw_tty {
35828 struct ipw_network *network;
35829 struct tty_struct *linux_tty;
35831 + local_t open_count;
35832 unsigned int control_lines;
35833 struct mutex ipw_tty_mutex;
35834 int tx_bytes_queued;
35835 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35836 mutex_unlock(&tty->ipw_tty_mutex);
35839 - if (tty->open_count == 0)
35840 + if (local_read(&tty->open_count) == 0)
35841 tty->tx_bytes_queued = 0;
35843 - tty->open_count++;
35844 + local_inc(&tty->open_count);
35846 tty->linux_tty = linux_tty;
35847 linux_tty->driver_data = tty;
35848 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35850 static void do_ipw_close(struct ipw_tty *tty)
35852 - tty->open_count--;
35854 - if (tty->open_count == 0) {
35855 + if (local_dec_return(&tty->open_count) == 0) {
35856 struct tty_struct *linux_tty = tty->linux_tty;
35858 if (linux_tty != NULL) {
35859 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
35862 mutex_lock(&tty->ipw_tty_mutex);
35863 - if (tty->open_count == 0) {
35864 + if (local_read(&tty->open_count) == 0) {
35865 mutex_unlock(&tty->ipw_tty_mutex);
35868 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
35872 - if (!tty->open_count) {
35873 + if (!local_read(&tty->open_count)) {
35874 mutex_unlock(&tty->ipw_tty_mutex);
35877 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
35880 mutex_lock(&tty->ipw_tty_mutex);
35881 - if (!tty->open_count) {
35882 + if (!local_read(&tty->open_count)) {
35883 mutex_unlock(&tty->ipw_tty_mutex);
35886 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
35890 - if (!tty->open_count)
35891 + if (!local_read(&tty->open_count))
35894 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
35895 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
35899 - if (!tty->open_count)
35900 + if (!local_read(&tty->open_count))
35903 return tty->tx_bytes_queued;
35904 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
35908 - if (!tty->open_count)
35909 + if (!local_read(&tty->open_count))
35912 return get_control_lines(tty);
35913 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
35917 - if (!tty->open_count)
35918 + if (!local_read(&tty->open_count))
35921 return set_control_lines(tty, set, clear);
35922 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
35926 - if (!tty->open_count)
35927 + if (!local_read(&tty->open_count))
35930 /* FIXME: Exactly how is the tty object locked here .. */
35931 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
35932 against a parallel ioctl etc */
35933 mutex_lock(&ttyj->ipw_tty_mutex);
35935 - while (ttyj->open_count)
35936 + while (local_read(&ttyj->open_count))
35937 do_ipw_close(ttyj);
35938 ipwireless_disassociate_network_ttys(network,
35939 ttyj->channel_idx);
35940 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
35941 index fc7bbba..9527e93 100644
35942 --- a/drivers/tty/n_gsm.c
35943 +++ b/drivers/tty/n_gsm.c
35944 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
35945 kref_init(&dlci->ref);
35946 mutex_init(&dlci->mutex);
35947 dlci->fifo = &dlci->_fifo;
35948 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
35949 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
35953 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
35954 index 39d6ab6..eb97f41 100644
35955 --- a/drivers/tty/n_tty.c
35956 +++ b/drivers/tty/n_tty.c
35957 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
35959 *ops = tty_ldisc_N_TTY;
35961 - ops->refcount = ops->flags = 0;
35962 + atomic_set(&ops->refcount, 0);
35965 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
35966 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
35967 index e18604b..a7d5a11 100644
35968 --- a/drivers/tty/pty.c
35969 +++ b/drivers/tty/pty.c
35970 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
35971 register_sysctl_table(pty_root_table);
35973 /* Now create the /dev/ptmx special device */
35974 + pax_open_kernel();
35975 tty_default_fops(&ptmx_fops);
35976 - ptmx_fops.open = ptmx_open;
35977 + *(void **)&ptmx_fops.open = ptmx_open;
35978 + pax_close_kernel();
35980 cdev_init(&ptmx_cdev, &ptmx_fops);
35981 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
35982 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
35983 index 2b42a01..32a2ed3 100644
35984 --- a/drivers/tty/serial/kgdboc.c
35985 +++ b/drivers/tty/serial/kgdboc.c
35987 #define MAX_CONFIG_LEN 40
35989 static struct kgdb_io kgdboc_io_ops;
35990 +static struct kgdb_io kgdboc_io_ops_console;
35992 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
35993 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
35994 static int configured = -1;
35996 static char config[MAX_CONFIG_LEN];
35997 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
35998 kgdboc_unregister_kbd();
35999 if (configured == 1)
36000 kgdb_unregister_io_module(&kgdboc_io_ops);
36001 + else if (configured == 2)
36002 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
36005 static int configure_kgdboc(void)
36006 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
36008 char *cptr = config;
36009 struct console *cons;
36010 + int is_console = 0;
36012 err = kgdboc_option_setup(config);
36013 if (err || !strlen(config) || isspace(config[0]))
36017 - kgdboc_io_ops.is_console = 0;
36018 kgdb_tty_driver = NULL;
36020 kgdboc_use_kms = 0;
36021 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
36023 if (cons->device && cons->device(cons, &idx) == p &&
36025 - kgdboc_io_ops.is_console = 1;
36030 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
36031 kgdb_tty_line = tty_line;
36034 - err = kgdb_register_io_module(&kgdboc_io_ops);
36035 + if (is_console) {
36036 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
36039 + err = kgdb_register_io_module(&kgdboc_io_ops);
36050 @@ -213,7 +220,7 @@ noconfig:
36051 static int __init init_kgdboc(void)
36053 /* Already configured? */
36054 - if (configured == 1)
36055 + if (configured >= 1)
36058 return configure_kgdboc();
36059 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
36060 if (config[len - 1] == '\n')
36061 config[len - 1] = '\0';
36063 - if (configured == 1)
36064 + if (configured >= 1)
36067 /* Go and configure with the new params. */
36068 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
36069 .post_exception = kgdboc_post_exp_handler,
36072 +static struct kgdb_io kgdboc_io_ops_console = {
36073 + .name = "kgdboc",
36074 + .read_char = kgdboc_get_char,
36075 + .write_char = kgdboc_put_char,
36076 + .pre_exception = kgdboc_pre_exp_handler,
36077 + .post_exception = kgdboc_post_exp_handler,
36081 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
36082 /* This is only available if kgdboc is a built in for early debugging */
36083 static int __init kgdboc_early_init(char *opt)
36084 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
36085 index 05085be..67eadb0 100644
36086 --- a/drivers/tty/tty_io.c
36087 +++ b/drivers/tty/tty_io.c
36088 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
36090 void tty_default_fops(struct file_operations *fops)
36092 - *fops = tty_fops;
36093 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
36097 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
36098 index 8e0924f..4204eb4 100644
36099 --- a/drivers/tty/tty_ldisc.c
36100 +++ b/drivers/tty/tty_ldisc.c
36101 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
36102 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
36103 struct tty_ldisc_ops *ldo = ld->ops;
36106 + atomic_dec(&ldo->refcount);
36107 module_put(ldo->owner);
36108 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
36110 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
36111 spin_lock_irqsave(&tty_ldisc_lock, flags);
36112 tty_ldiscs[disc] = new_ldisc;
36113 new_ldisc->num = disc;
36114 - new_ldisc->refcount = 0;
36115 + atomic_set(&new_ldisc->refcount, 0);
36116 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
36119 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
36122 spin_lock_irqsave(&tty_ldisc_lock, flags);
36123 - if (tty_ldiscs[disc]->refcount)
36124 + if (atomic_read(&tty_ldiscs[disc]->refcount))
36127 tty_ldiscs[disc] = NULL;
36128 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
36130 ret = ERR_PTR(-EAGAIN);
36131 if (try_module_get(ldops->owner)) {
36132 - ldops->refcount++;
36133 + atomic_inc(&ldops->refcount);
36137 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
36138 unsigned long flags;
36140 spin_lock_irqsave(&tty_ldisc_lock, flags);
36141 - ldops->refcount--;
36142 + atomic_dec(&ldops->refcount);
36143 module_put(ldops->owner);
36144 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
36146 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
36147 index a605549..6bd3c96 100644
36148 --- a/drivers/tty/vt/keyboard.c
36149 +++ b/drivers/tty/vt/keyboard.c
36150 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
36151 kbd->kbdmode == VC_OFF) &&
36152 value != KVAL(K_SAK))
36153 return; /* SAK is allowed even in raw mode */
36155 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
36157 + void *func = fn_handler[value];
36158 + if (func == fn_show_state || func == fn_show_ptregs ||
36159 + func == fn_show_mem)
36164 fn_handler[value](vc);
36167 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
36168 index 65447c5..0526f0a 100644
36169 --- a/drivers/tty/vt/vt_ioctl.c
36170 +++ b/drivers/tty/vt/vt_ioctl.c
36171 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
36172 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
36175 - if (!capable(CAP_SYS_TTY_CONFIG))
36180 key_map = key_maps[s];
36181 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
36182 val = (i ? K_HOLE : K_NOSUCHMAP);
36183 return put_user(val, &user_kbe->kb_value);
36185 + if (!capable(CAP_SYS_TTY_CONFIG))
36190 if (!i && v == K_NOSUCHMAP) {
36191 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
36195 - if (!capable(CAP_SYS_TTY_CONFIG))
36198 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
36201 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
36203 return ((p && *p) ? -EOVERFLOW : 0);
36205 + if (!capable(CAP_SYS_TTY_CONFIG))
36211 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
36212 index a783d53..cb30d94 100644
36213 --- a/drivers/uio/uio.c
36214 +++ b/drivers/uio/uio.c
36216 #include <linux/kobject.h>
36217 #include <linux/cdev.h>
36218 #include <linux/uio_driver.h>
36219 +#include <asm/local.h>
36221 #define UIO_MAX_DEVICES (1U << MINORBITS)
36223 @@ -32,10 +33,10 @@ struct uio_device {
36224 struct module *owner;
36225 struct device *dev;
36228 + atomic_unchecked_t event;
36229 struct fasync_struct *async_queue;
36230 wait_queue_head_t wait;
36232 + local_t vma_count;
36233 struct uio_info *info;
36234 struct kobject *map_dir;
36235 struct kobject *portio_dir;
36236 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
36237 struct device_attribute *attr, char *buf)
36239 struct uio_device *idev = dev_get_drvdata(dev);
36240 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
36241 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
36244 static struct device_attribute uio_class_attributes[] = {
36245 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
36247 struct uio_device *idev = info->uio_dev;
36249 - atomic_inc(&idev->event);
36250 + atomic_inc_unchecked(&idev->event);
36251 wake_up_interruptible(&idev->wait);
36252 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
36254 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
36257 listener->dev = idev;
36258 - listener->event_count = atomic_read(&idev->event);
36259 + listener->event_count = atomic_read_unchecked(&idev->event);
36260 filep->private_data = listener;
36262 if (idev->info->open) {
36263 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
36266 poll_wait(filep, &idev->wait, wait);
36267 - if (listener->event_count != atomic_read(&idev->event))
36268 + if (listener->event_count != atomic_read_unchecked(&idev->event))
36269 return POLLIN | POLLRDNORM;
36272 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
36274 set_current_state(TASK_INTERRUPTIBLE);
36276 - event_count = atomic_read(&idev->event);
36277 + event_count = atomic_read_unchecked(&idev->event);
36278 if (event_count != listener->event_count) {
36279 if (copy_to_user(buf, &event_count, count))
36281 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
36282 static void uio_vma_open(struct vm_area_struct *vma)
36284 struct uio_device *idev = vma->vm_private_data;
36285 - idev->vma_count++;
36286 + local_inc(&idev->vma_count);
36289 static void uio_vma_close(struct vm_area_struct *vma)
36291 struct uio_device *idev = vma->vm_private_data;
36292 - idev->vma_count--;
36293 + local_dec(&idev->vma_count);
36296 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36297 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
36298 idev->owner = owner;
36300 init_waitqueue_head(&idev->wait);
36301 - atomic_set(&idev->event, 0);
36302 + atomic_set_unchecked(&idev->event, 0);
36304 ret = uio_get_minor(idev);
36306 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
36307 index a845f8b..4f54072 100644
36308 --- a/drivers/usb/atm/cxacru.c
36309 +++ b/drivers/usb/atm/cxacru.c
36310 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
36311 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
36314 - if (index < 0 || index > 0x7f)
36315 + if (index > 0x7f)
36319 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
36320 index d3448ca..d2864ca 100644
36321 --- a/drivers/usb/atm/usbatm.c
36322 +++ b/drivers/usb/atm/usbatm.c
36323 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36324 if (printk_ratelimit())
36325 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
36326 __func__, vpi, vci);
36327 - atomic_inc(&vcc->stats->rx_err);
36328 + atomic_inc_unchecked(&vcc->stats->rx_err);
36332 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36333 if (length > ATM_MAX_AAL5_PDU) {
36334 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
36335 __func__, length, vcc);
36336 - atomic_inc(&vcc->stats->rx_err);
36337 + atomic_inc_unchecked(&vcc->stats->rx_err);
36341 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36342 if (sarb->len < pdu_length) {
36343 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
36344 __func__, pdu_length, sarb->len, vcc);
36345 - atomic_inc(&vcc->stats->rx_err);
36346 + atomic_inc_unchecked(&vcc->stats->rx_err);
36350 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
36351 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
36353 - atomic_inc(&vcc->stats->rx_err);
36354 + atomic_inc_unchecked(&vcc->stats->rx_err);
36358 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36359 if (printk_ratelimit())
36360 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
36362 - atomic_inc(&vcc->stats->rx_drop);
36363 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36367 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36369 vcc->push(vcc, skb);
36371 - atomic_inc(&vcc->stats->rx);
36372 + atomic_inc_unchecked(&vcc->stats->rx);
36376 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
36377 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
36379 usbatm_pop(vcc, skb);
36380 - atomic_inc(&vcc->stats->tx);
36381 + atomic_inc_unchecked(&vcc->stats->tx);
36383 skb = skb_dequeue(&instance->sndqueue);
36385 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
36387 return sprintf(page,
36388 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
36389 - atomic_read(&atm_dev->stats.aal5.tx),
36390 - atomic_read(&atm_dev->stats.aal5.tx_err),
36391 - atomic_read(&atm_dev->stats.aal5.rx),
36392 - atomic_read(&atm_dev->stats.aal5.rx_err),
36393 - atomic_read(&atm_dev->stats.aal5.rx_drop));
36394 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
36395 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
36396 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
36397 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
36398 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
36401 if (instance->disconnected)
36402 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
36403 index d956965..4179a77 100644
36404 --- a/drivers/usb/core/devices.c
36405 +++ b/drivers/usb/core/devices.c
36406 @@ -126,7 +126,7 @@ static const char format_endpt[] =
36407 * time it gets called.
36409 static struct device_connect_event {
36411 + atomic_unchecked_t count;
36412 wait_queue_head_t wait;
36414 .count = ATOMIC_INIT(1),
36415 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
36417 void usbfs_conn_disc_event(void)
36419 - atomic_add(2, &device_event.count);
36420 + atomic_add_unchecked(2, &device_event.count);
36421 wake_up(&device_event.wait);
36424 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
36426 poll_wait(file, &device_event.wait, wait);
36428 - event_count = atomic_read(&device_event.count);
36429 + event_count = atomic_read_unchecked(&device_event.count);
36430 if (file->f_version != event_count) {
36431 file->f_version = event_count;
36432 return POLLIN | POLLRDNORM;
36433 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
36434 index b3bdfed..a9460e0 100644
36435 --- a/drivers/usb/core/message.c
36436 +++ b/drivers/usb/core/message.c
36437 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
36438 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
36440 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
36442 - smallbuf = kmalloc(++len, GFP_NOIO);
36444 + smallbuf = kmalloc(len, GFP_NOIO);
36447 memcpy(smallbuf, buf, len);
36448 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
36449 index 1fc8f12..20647c1 100644
36450 --- a/drivers/usb/early/ehci-dbgp.c
36451 +++ b/drivers/usb/early/ehci-dbgp.c
36452 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
36455 static struct kgdb_io kgdbdbgp_io_ops;
36456 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
36457 +static struct kgdb_io kgdbdbgp_io_ops_console;
36458 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
36460 #define dbgp_kgdb_mode (0)
36462 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
36463 .write_char = kgdbdbgp_write_char,
36466 +static struct kgdb_io kgdbdbgp_io_ops_console = {
36467 + .name = "kgdbdbgp",
36468 + .read_char = kgdbdbgp_read_char,
36469 + .write_char = kgdbdbgp_write_char,
36473 static int kgdbdbgp_wait_time;
36475 static int __init kgdbdbgp_parse_config(char *str)
36476 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
36478 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
36480 - kgdb_register_io_module(&kgdbdbgp_io_ops);
36481 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
36482 + if (early_dbgp_console.index != -1)
36483 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
36485 + kgdb_register_io_module(&kgdbdbgp_io_ops);
36489 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
36490 index d6bea3e..60b250e 100644
36491 --- a/drivers/usb/wusbcore/wa-hc.h
36492 +++ b/drivers/usb/wusbcore/wa-hc.h
36493 @@ -192,7 +192,7 @@ struct wahc {
36494 struct list_head xfer_delayed_list;
36495 spinlock_t xfer_list_lock;
36496 struct work_struct xfer_work;
36497 - atomic_t xfer_id_count;
36498 + atomic_unchecked_t xfer_id_count;
36502 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
36503 INIT_LIST_HEAD(&wa->xfer_delayed_list);
36504 spin_lock_init(&wa->xfer_list_lock);
36505 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
36506 - atomic_set(&wa->xfer_id_count, 1);
36507 + atomic_set_unchecked(&wa->xfer_id_count, 1);
36511 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
36512 index 57c01ab..8a05959 100644
36513 --- a/drivers/usb/wusbcore/wa-xfer.c
36514 +++ b/drivers/usb/wusbcore/wa-xfer.c
36515 @@ -296,7 +296,7 @@ out:
36517 static void wa_xfer_id_init(struct wa_xfer *xfer)
36519 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
36520 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
36524 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
36525 index c14c42b..f955cc2 100644
36526 --- a/drivers/vhost/vhost.c
36527 +++ b/drivers/vhost/vhost.c
36528 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
36532 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
36533 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
36535 struct file *eventfp, *filep = NULL,
36536 *pollstart = NULL, *pollstop = NULL;
36537 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
36538 index b0b2ac3..89a4399 100644
36539 --- a/drivers/video/aty/aty128fb.c
36540 +++ b/drivers/video/aty/aty128fb.c
36541 @@ -148,7 +148,7 @@ enum {
36544 /* Must match above enum */
36545 -static const char *r128_family[] __devinitdata = {
36546 +static const char *r128_family[] __devinitconst = {
36550 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
36551 index 5c3960d..15cf8fc 100644
36552 --- a/drivers/video/fbcmap.c
36553 +++ b/drivers/video/fbcmap.c
36554 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
36558 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
36559 - !info->fbops->fb_setcmap)) {
36560 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
36564 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
36565 index ad93629..e020fc3 100644
36566 --- a/drivers/video/fbmem.c
36567 +++ b/drivers/video/fbmem.c
36568 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36569 image->dx += image->width + 8;
36571 } else if (rotate == FB_ROTATE_UD) {
36572 - for (x = 0; x < num && image->dx >= 0; x++) {
36573 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
36574 info->fbops->fb_imageblit(info, image);
36575 image->dx -= image->width + 8;
36577 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36578 image->dy += image->height + 8;
36580 } else if (rotate == FB_ROTATE_CCW) {
36581 - for (x = 0; x < num && image->dy >= 0; x++) {
36582 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
36583 info->fbops->fb_imageblit(info, image);
36584 image->dy -= image->height + 8;
36586 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
36588 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
36590 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
36591 + if (con2fb.framebuffer >= FB_MAX)
36593 if (!registered_fb[con2fb.framebuffer])
36594 request_module("fb%d", con2fb.framebuffer);
36595 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
36596 index 5a5d092..265c5ed 100644
36597 --- a/drivers/video/geode/gx1fb_core.c
36598 +++ b/drivers/video/geode/gx1fb_core.c
36599 @@ -29,7 +29,7 @@ static int crt_option = 1;
36600 static char panel_option[32] = "";
36602 /* Modes relevant to the GX1 (taken from modedb.c) */
36603 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
36604 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
36605 /* 640x480-60 VESA */
36606 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
36607 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36608 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
36609 index 0fad23f..0e9afa4 100644
36610 --- a/drivers/video/gxt4500.c
36611 +++ b/drivers/video/gxt4500.c
36612 @@ -156,7 +156,7 @@ struct gxt4500_par {
36613 static char *mode_option;
36615 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
36616 -static const struct fb_videomode defaultmode __devinitdata = {
36617 +static const struct fb_videomode defaultmode __devinitconst = {
36621 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
36625 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
36626 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
36627 .id = "IBM GXT4500P",
36628 .type = FB_TYPE_PACKED_PIXELS,
36629 .visual = FB_VISUAL_PSEUDOCOLOR,
36630 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
36631 index 7672d2e..b56437f 100644
36632 --- a/drivers/video/i810/i810_accel.c
36633 +++ b/drivers/video/i810/i810_accel.c
36634 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
36637 printk("ringbuffer lockup!!!\n");
36638 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
36639 i810_report_error(mmio);
36640 par->dev_flags |= LOCKUP;
36641 info->pixmap.scan_align = 1;
36642 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
36643 index 318f6fb..9a389c1 100644
36644 --- a/drivers/video/i810/i810_main.c
36645 +++ b/drivers/video/i810/i810_main.c
36646 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
36647 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
36650 -static const char *i810_pci_list[] __devinitdata = {
36651 +static const char *i810_pci_list[] __devinitconst = {
36652 "Intel(R) 810 Framebuffer Device" ,
36653 "Intel(R) 810-DC100 Framebuffer Device" ,
36654 "Intel(R) 810E Framebuffer Device" ,
36655 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
36656 index de36693..3c63fc2 100644
36657 --- a/drivers/video/jz4740_fb.c
36658 +++ b/drivers/video/jz4740_fb.c
36659 @@ -136,7 +136,7 @@ struct jzfb {
36660 uint32_t pseudo_palette[16];
36663 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
36664 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
36666 .type = FB_TYPE_PACKED_PIXELS,
36667 .visual = FB_VISUAL_TRUECOLOR,
36668 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
36669 index 3c14e43..eafa544 100644
36670 --- a/drivers/video/logo/logo_linux_clut224.ppm
36671 +++ b/drivers/video/logo/logo_linux_clut224.ppm
36672 @@ -1,1604 +1,1123 @@
36674 -# Standard 224-color Linux logo
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 0 0 0 0 0 0
36682 - 0 0 0 0 0 0 0 0 0 0 0 0
36683 - 0 0 0 0 0 0 0 0 0 0 0 0
36684 - 0 0 0 0 0 0 0 0 0 0 0 0
36685 - 0 0 0 0 0 0 0 0 0 0 0 0
36686 - 6 6 6 6 6 6 10 10 10 10 10 10
36687 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
36702 - 0 0 0 0 0 0 0 0 0 0 0 0
36703 - 0 0 0 0 0 0 0 0 0 0 0 0
36704 - 0 0 0 0 0 0 0 0 0 0 0 0
36705 - 0 0 0 6 6 6 10 10 10 14 14 14
36706 - 22 22 22 26 26 26 30 30 30 34 34 34
36707 - 30 30 30 30 30 30 26 26 26 18 18 18
36708 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 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 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
36722 - 0 0 0 0 0 0 0 0 0 0 0 0
36723 - 0 0 0 0 0 0 0 0 0 0 0 0
36724 - 0 0 0 0 0 0 0 0 0 0 0 0
36725 - 6 6 6 14 14 14 26 26 26 42 42 42
36726 - 54 54 54 66 66 66 78 78 78 78 78 78
36727 - 78 78 78 74 74 74 66 66 66 54 54 54
36728 - 42 42 42 26 26 26 18 18 18 10 10 10
36729 - 6 6 6 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 0 0 0 0 0 0 0 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 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
36742 - 0 0 0 0 0 0 0 0 0 0 0 0
36743 - 0 0 0 0 0 0 0 0 0 0 0 0
36744 - 0 0 0 0 0 0 0 0 0 10 10 10
36745 - 22 22 22 42 42 42 66 66 66 86 86 86
36746 - 66 66 66 38 38 38 38 38 38 22 22 22
36747 - 26 26 26 34 34 34 54 54 54 66 66 66
36748 - 86 86 86 70 70 70 46 46 46 26 26 26
36749 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
36762 - 0 0 0 0 0 0 0 0 0 0 0 0
36763 - 0 0 0 0 0 0 0 0 0 0 0 0
36764 - 0 0 0 0 0 0 10 10 10 26 26 26
36765 - 50 50 50 82 82 82 58 58 58 6 6 6
36766 - 2 2 6 2 2 6 2 2 6 2 2 6
36767 - 2 2 6 2 2 6 2 2 6 2 2 6
36768 - 6 6 6 54 54 54 86 86 86 66 66 66
36769 - 38 38 38 18 18 18 6 6 6 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 0 0 0
36781 - 0 0 0 0 0 0 0 0 0 0 0 0
36782 - 0 0 0 0 0 0 0 0 0 0 0 0
36783 - 0 0 0 0 0 0 0 0 0 0 0 0
36784 - 0 0 0 6 6 6 22 22 22 50 50 50
36785 - 78 78 78 34 34 34 2 2 6 2 2 6
36786 - 2 2 6 2 2 6 2 2 6 2 2 6
36787 - 2 2 6 2 2 6 2 2 6 2 2 6
36788 - 2 2 6 2 2 6 6 6 6 70 70 70
36789 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0
36801 - 0 0 0 0 0 0 0 0 0 0 0 0
36802 - 0 0 0 0 0 0 0 0 0 0 0 0
36803 - 0 0 0 0 0 0 0 0 0 0 0 0
36804 - 6 6 6 18 18 18 42 42 42 82 82 82
36805 - 26 26 26 2 2 6 2 2 6 2 2 6
36806 - 2 2 6 2 2 6 2 2 6 2 2 6
36807 - 2 2 6 2 2 6 2 2 6 14 14 14
36808 - 46 46 46 34 34 34 6 6 6 2 2 6
36809 - 42 42 42 78 78 78 42 42 42 18 18 18
36810 - 6 6 6 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 0 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 1 0 0 0 0 0 1 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 0 0 0
36821 - 0 0 0 0 0 0 0 0 0 0 0 0
36822 - 0 0 0 0 0 0 0 0 0 0 0 0
36823 - 0 0 0 0 0 0 0 0 0 0 0 0
36824 - 10 10 10 30 30 30 66 66 66 58 58 58
36825 - 2 2 6 2 2 6 2 2 6 2 2 6
36826 - 2 2 6 2 2 6 2 2 6 2 2 6
36827 - 2 2 6 2 2 6 2 2 6 26 26 26
36828 - 86 86 86 101 101 101 46 46 46 10 10 10
36829 - 2 2 6 58 58 58 70 70 70 34 34 34
36830 - 10 10 10 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 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0
36841 - 0 0 0 0 0 0 0 0 0 0 0 0
36842 - 0 0 0 0 0 0 0 0 0 0 0 0
36843 - 0 0 0 0 0 0 0 0 0 0 0 0
36844 - 14 14 14 42 42 42 86 86 86 10 10 10
36845 - 2 2 6 2 2 6 2 2 6 2 2 6
36846 - 2 2 6 2 2 6 2 2 6 2 2 6
36847 - 2 2 6 2 2 6 2 2 6 30 30 30
36848 - 94 94 94 94 94 94 58 58 58 26 26 26
36849 - 2 2 6 6 6 6 78 78 78 54 54 54
36850 - 22 22 22 6 6 6 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 0 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 0 0 0
36861 - 0 0 0 0 0 0 0 0 0 0 0 0
36862 - 0 0 0 0 0 0 0 0 0 0 0 0
36863 - 0 0 0 0 0 0 0 0 0 6 6 6
36864 - 22 22 22 62 62 62 62 62 62 2 2 6
36865 - 2 2 6 2 2 6 2 2 6 2 2 6
36866 - 2 2 6 2 2 6 2 2 6 2 2 6
36867 - 2 2 6 2 2 6 2 2 6 26 26 26
36868 - 54 54 54 38 38 38 18 18 18 10 10 10
36869 - 2 2 6 2 2 6 34 34 34 82 82 82
36870 - 38 38 38 14 14 14 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 0 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0
36881 - 0 0 0 0 0 0 0 0 0 0 0 0
36882 - 0 0 0 0 0 0 0 0 0 0 0 0
36883 - 0 0 0 0 0 0 0 0 0 6 6 6
36884 - 30 30 30 78 78 78 30 30 30 2 2 6
36885 - 2 2 6 2 2 6 2 2 6 2 2 6
36886 - 2 2 6 2 2 6 2 2 6 2 2 6
36887 - 2 2 6 2 2 6 2 2 6 10 10 10
36888 - 10 10 10 2 2 6 2 2 6 2 2 6
36889 - 2 2 6 2 2 6 2 2 6 78 78 78
36890 - 50 50 50 18 18 18 6 6 6 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 1 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 0 0 0
36901 - 0 0 0 0 0 0 0 0 0 0 0 0
36902 - 0 0 0 0 0 0 0 0 0 0 0 0
36903 - 0 0 0 0 0 0 0 0 0 10 10 10
36904 - 38 38 38 86 86 86 14 14 14 2 2 6
36905 - 2 2 6 2 2 6 2 2 6 2 2 6
36906 - 2 2 6 2 2 6 2 2 6 2 2 6
36907 - 2 2 6 2 2 6 2 2 6 2 2 6
36908 - 2 2 6 2 2 6 2 2 6 2 2 6
36909 - 2 2 6 2 2 6 2 2 6 54 54 54
36910 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0
36915 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0
36921 - 0 0 0 0 0 0 0 0 0 0 0 0
36922 - 0 0 0 0 0 0 0 0 0 0 0 0
36923 - 0 0 0 0 0 0 0 0 0 14 14 14
36924 - 42 42 42 82 82 82 2 2 6 2 2 6
36925 - 2 2 6 6 6 6 10 10 10 2 2 6
36926 - 2 2 6 2 2 6 2 2 6 2 2 6
36927 - 2 2 6 2 2 6 2 2 6 6 6 6
36928 - 14 14 14 10 10 10 2 2 6 2 2 6
36929 - 2 2 6 2 2 6 2 2 6 18 18 18
36930 - 82 82 82 34 34 34 10 10 10 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 1 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 0 0 0
36941 - 0 0 0 0 0 0 0 0 0 0 0 0
36942 - 0 0 0 0 0 0 0 0 0 0 0 0
36943 - 0 0 0 0 0 0 0 0 0 14 14 14
36944 - 46 46 46 86 86 86 2 2 6 2 2 6
36945 - 6 6 6 6 6 6 22 22 22 34 34 34
36946 - 6 6 6 2 2 6 2 2 6 2 2 6
36947 - 2 2 6 2 2 6 18 18 18 34 34 34
36948 - 10 10 10 50 50 50 22 22 22 2 2 6
36949 - 2 2 6 2 2 6 2 2 6 10 10 10
36950 - 86 86 86 42 42 42 14 14 14 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 0 0 0 0
36955 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0
36961 - 0 0 0 0 0 0 0 0 0 0 0 0
36962 - 0 0 0 0 0 0 0 0 0 0 0 0
36963 - 0 0 0 0 0 0 0 0 0 14 14 14
36964 - 46 46 46 86 86 86 2 2 6 2 2 6
36965 - 38 38 38 116 116 116 94 94 94 22 22 22
36966 - 22 22 22 2 2 6 2 2 6 2 2 6
36967 - 14 14 14 86 86 86 138 138 138 162 162 162
36968 -154 154 154 38 38 38 26 26 26 6 6 6
36969 - 2 2 6 2 2 6 2 2 6 2 2 6
36970 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0
36975 - 0 0 0 0 0 0 0 0 0 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 0 0 0
36981 - 0 0 0 0 0 0 0 0 0 0 0 0
36982 - 0 0 0 0 0 0 0 0 0 0 0 0
36983 - 0 0 0 0 0 0 0 0 0 14 14 14
36984 - 46 46 46 86 86 86 2 2 6 14 14 14
36985 -134 134 134 198 198 198 195 195 195 116 116 116
36986 - 10 10 10 2 2 6 2 2 6 6 6 6
36987 -101 98 89 187 187 187 210 210 210 218 218 218
36988 -214 214 214 134 134 134 14 14 14 6 6 6
36989 - 2 2 6 2 2 6 2 2 6 2 2 6
36990 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0
36995 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
36998 - 0 0 1 0 0 1 0 0 1 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 0 0 0
37001 - 0 0 0 0 0 0 0 0 0 0 0 0
37002 - 0 0 0 0 0 0 0 0 0 0 0 0
37003 - 0 0 0 0 0 0 0 0 0 14 14 14
37004 - 46 46 46 86 86 86 2 2 6 54 54 54
37005 -218 218 218 195 195 195 226 226 226 246 246 246
37006 - 58 58 58 2 2 6 2 2 6 30 30 30
37007 -210 210 210 253 253 253 174 174 174 123 123 123
37008 -221 221 221 234 234 234 74 74 74 2 2 6
37009 - 2 2 6 2 2 6 2 2 6 2 2 6
37010 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
37021 - 0 0 0 0 0 0 0 0 0 0 0 0
37022 - 0 0 0 0 0 0 0 0 0 0 0 0
37023 - 0 0 0 0 0 0 0 0 0 14 14 14
37024 - 46 46 46 82 82 82 2 2 6 106 106 106
37025 -170 170 170 26 26 26 86 86 86 226 226 226
37026 -123 123 123 10 10 10 14 14 14 46 46 46
37027 -231 231 231 190 190 190 6 6 6 70 70 70
37028 - 90 90 90 238 238 238 158 158 158 2 2 6
37029 - 2 2 6 2 2 6 2 2 6 2 2 6
37030 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
37038 - 0 0 1 0 0 1 0 0 1 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 0 0 0
37041 - 0 0 0 0 0 0 0 0 0 0 0 0
37042 - 0 0 0 0 0 0 0 0 0 0 0 0
37043 - 0 0 0 0 0 0 0 0 0 14 14 14
37044 - 42 42 42 86 86 86 6 6 6 116 116 116
37045 -106 106 106 6 6 6 70 70 70 149 149 149
37046 -128 128 128 18 18 18 38 38 38 54 54 54
37047 -221 221 221 106 106 106 2 2 6 14 14 14
37048 - 46 46 46 190 190 190 198 198 198 2 2 6
37049 - 2 2 6 2 2 6 2 2 6 2 2 6
37050 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
37058 - 0 0 1 0 0 0 0 0 1 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 0 0 0
37061 - 0 0 0 0 0 0 0 0 0 0 0 0
37062 - 0 0 0 0 0 0 0 0 0 0 0 0
37063 - 0 0 0 0 0 0 0 0 0 14 14 14
37064 - 42 42 42 94 94 94 14 14 14 101 101 101
37065 -128 128 128 2 2 6 18 18 18 116 116 116
37066 -118 98 46 121 92 8 121 92 8 98 78 10
37067 -162 162 162 106 106 106 2 2 6 2 2 6
37068 - 2 2 6 195 195 195 195 195 195 6 6 6
37069 - 2 2 6 2 2 6 2 2 6 2 2 6
37070 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
37078 - 0 0 1 0 0 0 0 0 1 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 0 0 0
37081 - 0 0 0 0 0 0 0 0 0 0 0 0
37082 - 0 0 0 0 0 0 0 0 0 0 0 0
37083 - 0 0 0 0 0 0 0 0 0 10 10 10
37084 - 38 38 38 90 90 90 14 14 14 58 58 58
37085 -210 210 210 26 26 26 54 38 6 154 114 10
37086 -226 170 11 236 186 11 225 175 15 184 144 12
37087 -215 174 15 175 146 61 37 26 9 2 2 6
37088 - 70 70 70 246 246 246 138 138 138 2 2 6
37089 - 2 2 6 2 2 6 2 2 6 2 2 6
37090 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
37101 - 0 0 0 0 0 0 0 0 0 0 0 0
37102 - 0 0 0 0 0 0 0 0 0 0 0 0
37103 - 0 0 0 0 0 0 0 0 0 10 10 10
37104 - 38 38 38 86 86 86 14 14 14 10 10 10
37105 -195 195 195 188 164 115 192 133 9 225 175 15
37106 -239 182 13 234 190 10 232 195 16 232 200 30
37107 -245 207 45 241 208 19 232 195 16 184 144 12
37108 -218 194 134 211 206 186 42 42 42 2 2 6
37109 - 2 2 6 2 2 6 2 2 6 2 2 6
37110 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
37121 - 0 0 0 0 0 0 0 0 0 0 0 0
37122 - 0 0 0 0 0 0 0 0 0 0 0 0
37123 - 0 0 0 0 0 0 0 0 0 10 10 10
37124 - 34 34 34 86 86 86 14 14 14 2 2 6
37125 -121 87 25 192 133 9 219 162 10 239 182 13
37126 -236 186 11 232 195 16 241 208 19 244 214 54
37127 -246 218 60 246 218 38 246 215 20 241 208 19
37128 -241 208 19 226 184 13 121 87 25 2 2 6
37129 - 2 2 6 2 2 6 2 2 6 2 2 6
37130 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
37141 - 0 0 0 0 0 0 0 0 0 0 0 0
37142 - 0 0 0 0 0 0 0 0 0 0 0 0
37143 - 0 0 0 0 0 0 0 0 0 10 10 10
37144 - 34 34 34 82 82 82 30 30 30 61 42 6
37145 -180 123 7 206 145 10 230 174 11 239 182 13
37146 -234 190 10 238 202 15 241 208 19 246 218 74
37147 -246 218 38 246 215 20 246 215 20 246 215 20
37148 -226 184 13 215 174 15 184 144 12 6 6 6
37149 - 2 2 6 2 2 6 2 2 6 2 2 6
37150 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0
37161 - 0 0 0 0 0 0 0 0 0 0 0 0
37162 - 0 0 0 0 0 0 0 0 0 0 0 0
37163 - 0 0 0 0 0 0 0 0 0 10 10 10
37164 - 30 30 30 78 78 78 50 50 50 104 69 6
37165 -192 133 9 216 158 10 236 178 12 236 186 11
37166 -232 195 16 241 208 19 244 214 54 245 215 43
37167 -246 215 20 246 215 20 241 208 19 198 155 10
37168 -200 144 11 216 158 10 156 118 10 2 2 6
37169 - 2 2 6 2 2 6 2 2 6 2 2 6
37170 - 6 6 6 90 90 90 54 54 54 18 18 18
37171 - 6 6 6 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 0 0 0 0 0 0
37181 - 0 0 0 0 0 0 0 0 0 0 0 0
37182 - 0 0 0 0 0 0 0 0 0 0 0 0
37183 - 0 0 0 0 0 0 0 0 0 10 10 10
37184 - 30 30 30 78 78 78 46 46 46 22 22 22
37185 -137 92 6 210 162 10 239 182 13 238 190 10
37186 -238 202 15 241 208 19 246 215 20 246 215 20
37187 -241 208 19 203 166 17 185 133 11 210 150 10
37188 -216 158 10 210 150 10 102 78 10 2 2 6
37189 - 6 6 6 54 54 54 14 14 14 2 2 6
37190 - 2 2 6 62 62 62 74 74 74 30 30 30
37191 - 10 10 10 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 0 0 0 0 0 0 0 0 0
37201 - 0 0 0 0 0 0 0 0 0 0 0 0
37202 - 0 0 0 0 0 0 0 0 0 0 0 0
37203 - 0 0 0 0 0 0 0 0 0 10 10 10
37204 - 34 34 34 78 78 78 50 50 50 6 6 6
37205 - 94 70 30 139 102 15 190 146 13 226 184 13
37206 -232 200 30 232 195 16 215 174 15 190 146 13
37207 -168 122 10 192 133 9 210 150 10 213 154 11
37208 -202 150 34 182 157 106 101 98 89 2 2 6
37209 - 2 2 6 78 78 78 116 116 116 58 58 58
37210 - 2 2 6 22 22 22 90 90 90 46 46 46
37211 - 18 18 18 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
37221 - 0 0 0 0 0 0 0 0 0 0 0 0
37222 - 0 0 0 0 0 0 0 0 0 0 0 0
37223 - 0 0 0 0 0 0 0 0 0 10 10 10
37224 - 38 38 38 86 86 86 50 50 50 6 6 6
37225 -128 128 128 174 154 114 156 107 11 168 122 10
37226 -198 155 10 184 144 12 197 138 11 200 144 11
37227 -206 145 10 206 145 10 197 138 11 188 164 115
37228 -195 195 195 198 198 198 174 174 174 14 14 14
37229 - 2 2 6 22 22 22 116 116 116 116 116 116
37230 - 22 22 22 2 2 6 74 74 74 70 70 70
37231 - 30 30 30 10 10 10 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 0 0 0
37240 - 0 0 0 0 0 0 0 0 0 0 0 0
37241 - 0 0 0 0 0 0 0 0 0 0 0 0
37242 - 0 0 0 0 0 0 0 0 0 0 0 0
37243 - 0 0 0 0 0 0 6 6 6 18 18 18
37244 - 50 50 50 101 101 101 26 26 26 10 10 10
37245 -138 138 138 190 190 190 174 154 114 156 107 11
37246 -197 138 11 200 144 11 197 138 11 192 133 9
37247 -180 123 7 190 142 34 190 178 144 187 187 187
37248 -202 202 202 221 221 221 214 214 214 66 66 66
37249 - 2 2 6 2 2 6 50 50 50 62 62 62
37250 - 6 6 6 2 2 6 10 10 10 90 90 90
37251 - 50 50 50 18 18 18 6 6 6 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 0 0 0
37260 - 0 0 0 0 0 0 0 0 0 0 0 0
37261 - 0 0 0 0 0 0 0 0 0 0 0 0
37262 - 0 0 0 0 0 0 0 0 0 0 0 0
37263 - 0 0 0 0 0 0 10 10 10 34 34 34
37264 - 74 74 74 74 74 74 2 2 6 6 6 6
37265 -144 144 144 198 198 198 190 190 190 178 166 146
37266 -154 121 60 156 107 11 156 107 11 168 124 44
37267 -174 154 114 187 187 187 190 190 190 210 210 210
37268 -246 246 246 253 253 253 253 253 253 182 182 182
37269 - 6 6 6 2 2 6 2 2 6 2 2 6
37270 - 2 2 6 2 2 6 2 2 6 62 62 62
37271 - 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0
37280 - 0 0 0 0 0 0 0 0 0 0 0 0
37281 - 0 0 0 0 0 0 0 0 0 0 0 0
37282 - 0 0 0 0 0 0 0 0 0 0 0 0
37283 - 0 0 0 10 10 10 22 22 22 54 54 54
37284 - 94 94 94 18 18 18 2 2 6 46 46 46
37285 -234 234 234 221 221 221 190 190 190 190 190 190
37286 -190 190 190 187 187 187 187 187 187 190 190 190
37287 -190 190 190 195 195 195 214 214 214 242 242 242
37288 -253 253 253 253 253 253 253 253 253 253 253 253
37289 - 82 82 82 2 2 6 2 2 6 2 2 6
37290 - 2 2 6 2 2 6 2 2 6 14 14 14
37291 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
37300 - 0 0 0 0 0 0 0 0 0 0 0 0
37301 - 0 0 0 0 0 0 0 0 0 0 0 0
37302 - 0 0 0 0 0 0 0 0 0 0 0 0
37303 - 6 6 6 18 18 18 46 46 46 90 90 90
37304 - 46 46 46 18 18 18 6 6 6 182 182 182
37305 -253 253 253 246 246 246 206 206 206 190 190 190
37306 -190 190 190 190 190 190 190 190 190 190 190 190
37307 -206 206 206 231 231 231 250 250 250 253 253 253
37308 -253 253 253 253 253 253 253 253 253 253 253 253
37309 -202 202 202 14 14 14 2 2 6 2 2 6
37310 - 2 2 6 2 2 6 2 2 6 2 2 6
37311 - 42 42 42 86 86 86 42 42 42 18 18 18
37312 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
37320 - 0 0 0 0 0 0 0 0 0 0 0 0
37321 - 0 0 0 0 0 0 0 0 0 0 0 0
37322 - 0 0 0 0 0 0 0 0 0 6 6 6
37323 - 14 14 14 38 38 38 74 74 74 66 66 66
37324 - 2 2 6 6 6 6 90 90 90 250 250 250
37325 -253 253 253 253 253 253 238 238 238 198 198 198
37326 -190 190 190 190 190 190 195 195 195 221 221 221
37327 -246 246 246 253 253 253 253 253 253 253 253 253
37328 -253 253 253 253 253 253 253 253 253 253 253 253
37329 -253 253 253 82 82 82 2 2 6 2 2 6
37330 - 2 2 6 2 2 6 2 2 6 2 2 6
37331 - 2 2 6 78 78 78 70 70 70 34 34 34
37332 - 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
37340 - 0 0 0 0 0 0 0 0 0 0 0 0
37341 - 0 0 0 0 0 0 0 0 0 0 0 0
37342 - 0 0 0 0 0 0 0 0 0 14 14 14
37343 - 34 34 34 66 66 66 78 78 78 6 6 6
37344 - 2 2 6 18 18 18 218 218 218 253 253 253
37345 -253 253 253 253 253 253 253 253 253 246 246 246
37346 -226 226 226 231 231 231 246 246 246 253 253 253
37347 -253 253 253 253 253 253 253 253 253 253 253 253
37348 -253 253 253 253 253 253 253 253 253 253 253 253
37349 -253 253 253 178 178 178 2 2 6 2 2 6
37350 - 2 2 6 2 2 6 2 2 6 2 2 6
37351 - 2 2 6 18 18 18 90 90 90 62 62 62
37352 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
37360 - 0 0 0 0 0 0 0 0 0 0 0 0
37361 - 0 0 0 0 0 0 0 0 0 0 0 0
37362 - 0 0 0 0 0 0 10 10 10 26 26 26
37363 - 58 58 58 90 90 90 18 18 18 2 2 6
37364 - 2 2 6 110 110 110 253 253 253 253 253 253
37365 -253 253 253 253 253 253 253 253 253 253 253 253
37366 -250 250 250 253 253 253 253 253 253 253 253 253
37367 -253 253 253 253 253 253 253 253 253 253 253 253
37368 -253 253 253 253 253 253 253 253 253 253 253 253
37369 -253 253 253 231 231 231 18 18 18 2 2 6
37370 - 2 2 6 2 2 6 2 2 6 2 2 6
37371 - 2 2 6 2 2 6 18 18 18 94 94 94
37372 - 54 54 54 26 26 26 10 10 10 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 0 0 0
37379 - 0 0 0 0 0 0 0 0 0 0 0 0
37380 - 0 0 0 0 0 0 0 0 0 0 0 0
37381 - 0 0 0 0 0 0 0 0 0 0 0 0
37382 - 0 0 0 6 6 6 22 22 22 50 50 50
37383 - 90 90 90 26 26 26 2 2 6 2 2 6
37384 - 14 14 14 195 195 195 250 250 250 253 253 253
37385 -253 253 253 253 253 253 253 253 253 253 253 253
37386 -253 253 253 253 253 253 253 253 253 253 253 253
37387 -253 253 253 253 253 253 253 253 253 253 253 253
37388 -253 253 253 253 253 253 253 253 253 253 253 253
37389 -250 250 250 242 242 242 54 54 54 2 2 6
37390 - 2 2 6 2 2 6 2 2 6 2 2 6
37391 - 2 2 6 2 2 6 2 2 6 38 38 38
37392 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0
37399 - 0 0 0 0 0 0 0 0 0 0 0 0
37400 - 0 0 0 0 0 0 0 0 0 0 0 0
37401 - 0 0 0 0 0 0 0 0 0 0 0 0
37402 - 6 6 6 14 14 14 38 38 38 82 82 82
37403 - 34 34 34 2 2 6 2 2 6 2 2 6
37404 - 42 42 42 195 195 195 246 246 246 253 253 253
37405 -253 253 253 253 253 253 253 253 253 250 250 250
37406 -242 242 242 242 242 242 250 250 250 253 253 253
37407 -253 253 253 253 253 253 253 253 253 253 253 253
37408 -253 253 253 250 250 250 246 246 246 238 238 238
37409 -226 226 226 231 231 231 101 101 101 6 6 6
37410 - 2 2 6 2 2 6 2 2 6 2 2 6
37411 - 2 2 6 2 2 6 2 2 6 2 2 6
37412 - 38 38 38 82 82 82 42 42 42 14 14 14
37413 - 6 6 6 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 0 0 0
37419 - 0 0 0 0 0 0 0 0 0 0 0 0
37420 - 0 0 0 0 0 0 0 0 0 0 0 0
37421 - 0 0 0 0 0 0 0 0 0 0 0 0
37422 - 10 10 10 26 26 26 62 62 62 66 66 66
37423 - 2 2 6 2 2 6 2 2 6 6 6 6
37424 - 70 70 70 170 170 170 206 206 206 234 234 234
37425 -246 246 246 250 250 250 250 250 250 238 238 238
37426 -226 226 226 231 231 231 238 238 238 250 250 250
37427 -250 250 250 250 250 250 246 246 246 231 231 231
37428 -214 214 214 206 206 206 202 202 202 202 202 202
37429 -198 198 198 202 202 202 182 182 182 18 18 18
37430 - 2 2 6 2 2 6 2 2 6 2 2 6
37431 - 2 2 6 2 2 6 2 2 6 2 2 6
37432 - 2 2 6 62 62 62 66 66 66 30 30 30
37433 - 10 10 10 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 0 0 0 0 0 0
37439 - 0 0 0 0 0 0 0 0 0 0 0 0
37440 - 0 0 0 0 0 0 0 0 0 0 0 0
37441 - 0 0 0 0 0 0 0 0 0 0 0 0
37442 - 14 14 14 42 42 42 82 82 82 18 18 18
37443 - 2 2 6 2 2 6 2 2 6 10 10 10
37444 - 94 94 94 182 182 182 218 218 218 242 242 242
37445 -250 250 250 253 253 253 253 253 253 250 250 250
37446 -234 234 234 253 253 253 253 253 253 253 253 253
37447 -253 253 253 253 253 253 253 253 253 246 246 246
37448 -238 238 238 226 226 226 210 210 210 202 202 202
37449 -195 195 195 195 195 195 210 210 210 158 158 158
37450 - 6 6 6 14 14 14 50 50 50 14 14 14
37451 - 2 2 6 2 2 6 2 2 6 2 2 6
37452 - 2 2 6 6 6 6 86 86 86 46 46 46
37453 - 18 18 18 6 6 6 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 0 0 0 0 0 0
37459 - 0 0 0 0 0 0 0 0 0 0 0 0
37460 - 0 0 0 0 0 0 0 0 0 0 0 0
37461 - 0 0 0 0 0 0 0 0 0 6 6 6
37462 - 22 22 22 54 54 54 70 70 70 2 2 6
37463 - 2 2 6 10 10 10 2 2 6 22 22 22
37464 -166 166 166 231 231 231 250 250 250 253 253 253
37465 -253 253 253 253 253 253 253 253 253 250 250 250
37466 -242 242 242 253 253 253 253 253 253 253 253 253
37467 -253 253 253 253 253 253 253 253 253 253 253 253
37468 -253 253 253 253 253 253 253 253 253 246 246 246
37469 -231 231 231 206 206 206 198 198 198 226 226 226
37470 - 94 94 94 2 2 6 6 6 6 38 38 38
37471 - 30 30 30 2 2 6 2 2 6 2 2 6
37472 - 2 2 6 2 2 6 62 62 62 66 66 66
37473 - 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0
37479 - 0 0 0 0 0 0 0 0 0 0 0 0
37480 - 0 0 0 0 0 0 0 0 0 0 0 0
37481 - 0 0 0 0 0 0 0 0 0 10 10 10
37482 - 30 30 30 74 74 74 50 50 50 2 2 6
37483 - 26 26 26 26 26 26 2 2 6 106 106 106
37484 -238 238 238 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 253 253 253 253 253 253
37488 -253 253 253 253 253 253 253 253 253 253 253 253
37489 -253 253 253 246 246 246 218 218 218 202 202 202
37490 -210 210 210 14 14 14 2 2 6 2 2 6
37491 - 30 30 30 22 22 22 2 2 6 2 2 6
37492 - 2 2 6 2 2 6 18 18 18 86 86 86
37493 - 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0
37499 - 0 0 0 0 0 0 0 0 0 0 0 0
37500 - 0 0 0 0 0 0 0 0 0 0 0 0
37501 - 0 0 0 0 0 0 0 0 0 14 14 14
37502 - 42 42 42 90 90 90 22 22 22 2 2 6
37503 - 42 42 42 2 2 6 18 18 18 218 218 218
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 253 253 253 253 253 253
37508 -253 253 253 253 253 253 253 253 253 253 253 253
37509 -253 253 253 253 253 253 250 250 250 221 221 221
37510 -218 218 218 101 101 101 2 2 6 14 14 14
37511 - 18 18 18 38 38 38 10 10 10 2 2 6
37512 - 2 2 6 2 2 6 2 2 6 78 78 78
37513 - 58 58 58 22 22 22 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
37519 - 0 0 0 0 0 0 0 0 0 0 0 0
37520 - 0 0 0 0 0 0 0 0 0 0 0 0
37521 - 0 0 0 0 0 0 6 6 6 18 18 18
37522 - 54 54 54 82 82 82 2 2 6 26 26 26
37523 - 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253
37528 -253 253 253 253 253 253 253 253 253 253 253 253
37529 -253 253 253 253 253 253 253 253 253 250 250 250
37530 -238 238 238 198 198 198 6 6 6 38 38 38
37531 - 58 58 58 26 26 26 38 38 38 2 2 6
37532 - 2 2 6 2 2 6 2 2 6 46 46 46
37533 - 78 78 78 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
37539 - 0 0 0 0 0 0 0 0 0 0 0 0
37540 - 0 0 0 0 0 0 0 0 0 0 0 0
37541 - 0 0 0 0 0 0 10 10 10 30 30 30
37542 - 74 74 74 58 58 58 2 2 6 42 42 42
37543 - 2 2 6 22 22 22 231 231 231 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 250 250 250
37546 -253 253 253 253 253 253 253 253 253 253 253 253
37547 -253 253 253 253 253 253 253 253 253 253 253 253
37548 -253 253 253 253 253 253 253 253 253 253 253 253
37549 -253 253 253 253 253 253 253 253 253 253 253 253
37550 -253 253 253 246 246 246 46 46 46 38 38 38
37551 - 42 42 42 14 14 14 38 38 38 14 14 14
37552 - 2 2 6 2 2 6 2 2 6 6 6 6
37553 - 86 86 86 46 46 46 14 14 14 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 0 0 0
37558 - 0 0 0 0 0 0 0 0 0 0 0 0
37559 - 0 0 0 0 0 0 0 0 0 0 0 0
37560 - 0 0 0 0 0 0 0 0 0 0 0 0
37561 - 0 0 0 6 6 6 14 14 14 42 42 42
37562 - 90 90 90 18 18 18 18 18 18 26 26 26
37563 - 2 2 6 116 116 116 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 250 250 250 238 238 238
37566 -253 253 253 253 253 253 253 253 253 253 253 253
37567 -253 253 253 253 253 253 253 253 253 253 253 253
37568 -253 253 253 253 253 253 253 253 253 253 253 253
37569 -253 253 253 253 253 253 253 253 253 253 253 253
37570 -253 253 253 253 253 253 94 94 94 6 6 6
37571 - 2 2 6 2 2 6 10 10 10 34 34 34
37572 - 2 2 6 2 2 6 2 2 6 2 2 6
37573 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
37578 - 0 0 0 0 0 0 0 0 0 0 0 0
37579 - 0 0 0 0 0 0 0 0 0 0 0 0
37580 - 0 0 0 0 0 0 0 0 0 0 0 0
37581 - 0 0 0 10 10 10 26 26 26 66 66 66
37582 - 82 82 82 2 2 6 38 38 38 6 6 6
37583 - 14 14 14 210 210 210 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 246 246 246 242 242 242
37586 -253 253 253 253 253 253 253 253 253 253 253 253
37587 -253 253 253 253 253 253 253 253 253 253 253 253
37588 -253 253 253 253 253 253 253 253 253 253 253 253
37589 -253 253 253 253 253 253 253 253 253 253 253 253
37590 -253 253 253 253 253 253 144 144 144 2 2 6
37591 - 2 2 6 2 2 6 2 2 6 46 46 46
37592 - 2 2 6 2 2 6 2 2 6 2 2 6
37593 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
37598 - 0 0 0 0 0 0 0 0 0 0 0 0
37599 - 0 0 0 0 0 0 0 0 0 0 0 0
37600 - 0 0 0 0 0 0 0 0 0 0 0 0
37601 - 6 6 6 14 14 14 42 42 42 90 90 90
37602 - 26 26 26 6 6 6 42 42 42 2 2 6
37603 - 74 74 74 250 250 250 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 242 242 242 242 242 242
37606 -253 253 253 253 253 253 253 253 253 253 253 253
37607 -253 253 253 253 253 253 253 253 253 253 253 253
37608 -253 253 253 253 253 253 253 253 253 253 253 253
37609 -253 253 253 253 253 253 253 253 253 253 253 253
37610 -253 253 253 253 253 253 182 182 182 2 2 6
37611 - 2 2 6 2 2 6 2 2 6 46 46 46
37612 - 2 2 6 2 2 6 2 2 6 2 2 6
37613 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0
37618 - 0 0 0 0 0 0 0 0 0 0 0 0
37619 - 0 0 0 0 0 0 0 0 0 0 0 0
37620 - 0 0 0 0 0 0 0 0 0 0 0 0
37621 - 10 10 10 26 26 26 66 66 66 82 82 82
37622 - 2 2 6 22 22 22 18 18 18 2 2 6
37623 -149 149 149 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 234 234 234 242 242 242
37626 -253 253 253 253 253 253 253 253 253 253 253 253
37627 -253 253 253 253 253 253 253 253 253 253 253 253
37628 -253 253 253 253 253 253 253 253 253 253 253 253
37629 -253 253 253 253 253 253 253 253 253 253 253 253
37630 -253 253 253 253 253 253 206 206 206 2 2 6
37631 - 2 2 6 2 2 6 2 2 6 38 38 38
37632 - 2 2 6 2 2 6 2 2 6 2 2 6
37633 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
37638 - 0 0 0 0 0 0 0 0 0 0 0 0
37639 - 0 0 0 0 0 0 0 0 0 0 0 0
37640 - 0 0 0 0 0 0 0 0 0 6 6 6
37641 - 18 18 18 46 46 46 86 86 86 18 18 18
37642 - 2 2 6 34 34 34 10 10 10 6 6 6
37643 -210 210 210 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 234 234 234 242 242 242
37646 -253 253 253 253 253 253 253 253 253 253 253 253
37647 -253 253 253 253 253 253 253 253 253 253 253 253
37648 -253 253 253 253 253 253 253 253 253 253 253 253
37649 -253 253 253 253 253 253 253 253 253 253 253 253
37650 -253 253 253 253 253 253 221 221 221 6 6 6
37651 - 2 2 6 2 2 6 6 6 6 30 30 30
37652 - 2 2 6 2 2 6 2 2 6 2 2 6
37653 - 2 2 6 82 82 82 54 54 54 18 18 18
37654 - 6 6 6 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 0 0 0 0 0 0
37658 - 0 0 0 0 0 0 0 0 0 0 0 0
37659 - 0 0 0 0 0 0 0 0 0 0 0 0
37660 - 0 0 0 0 0 0 0 0 0 10 10 10
37661 - 26 26 26 66 66 66 62 62 62 2 2 6
37662 - 2 2 6 38 38 38 10 10 10 26 26 26
37663 -238 238 238 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 231 231 231 238 238 238
37666 -253 253 253 253 253 253 253 253 253 253 253 253
37667 -253 253 253 253 253 253 253 253 253 253 253 253
37668 -253 253 253 253 253 253 253 253 253 253 253 253
37669 -253 253 253 253 253 253 253 253 253 253 253 253
37670 -253 253 253 253 253 253 231 231 231 6 6 6
37671 - 2 2 6 2 2 6 10 10 10 30 30 30
37672 - 2 2 6 2 2 6 2 2 6 2 2 6
37673 - 2 2 6 66 66 66 58 58 58 22 22 22
37674 - 6 6 6 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 0 0 0 0 0 0
37678 - 0 0 0 0 0 0 0 0 0 0 0 0
37679 - 0 0 0 0 0 0 0 0 0 0 0 0
37680 - 0 0 0 0 0 0 0 0 0 10 10 10
37681 - 38 38 38 78 78 78 6 6 6 2 2 6
37682 - 2 2 6 46 46 46 14 14 14 42 42 42
37683 -246 246 246 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 231 231 231 242 242 242
37686 -253 253 253 253 253 253 253 253 253 253 253 253
37687 -253 253 253 253 253 253 253 253 253 253 253 253
37688 -253 253 253 253 253 253 253 253 253 253 253 253
37689 -253 253 253 253 253 253 253 253 253 253 253 253
37690 -253 253 253 253 253 253 234 234 234 10 10 10
37691 - 2 2 6 2 2 6 22 22 22 14 14 14
37692 - 2 2 6 2 2 6 2 2 6 2 2 6
37693 - 2 2 6 66 66 66 62 62 62 22 22 22
37694 - 6 6 6 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 0 0 0
37697 - 0 0 0 0 0 0 0 0 0 0 0 0
37698 - 0 0 0 0 0 0 0 0 0 0 0 0
37699 - 0 0 0 0 0 0 0 0 0 0 0 0
37700 - 0 0 0 0 0 0 6 6 6 18 18 18
37701 - 50 50 50 74 74 74 2 2 6 2 2 6
37702 - 14 14 14 70 70 70 34 34 34 62 62 62
37703 -250 250 250 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 231 231 231 246 246 246
37706 -253 253 253 253 253 253 253 253 253 253 253 253
37707 -253 253 253 253 253 253 253 253 253 253 253 253
37708 -253 253 253 253 253 253 253 253 253 253 253 253
37709 -253 253 253 253 253 253 253 253 253 253 253 253
37710 -253 253 253 253 253 253 234 234 234 14 14 14
37711 - 2 2 6 2 2 6 30 30 30 2 2 6
37712 - 2 2 6 2 2 6 2 2 6 2 2 6
37713 - 2 2 6 66 66 66 62 62 62 22 22 22
37714 - 6 6 6 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 0 0 0 0 0 0 0 0 0
37717 - 0 0 0 0 0 0 0 0 0 0 0 0
37718 - 0 0 0 0 0 0 0 0 0 0 0 0
37719 - 0 0 0 0 0 0 0 0 0 0 0 0
37720 - 0 0 0 0 0 0 6 6 6 18 18 18
37721 - 54 54 54 62 62 62 2 2 6 2 2 6
37722 - 2 2 6 30 30 30 46 46 46 70 70 70
37723 -250 250 250 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 231 231 231 246 246 246
37726 -253 253 253 253 253 253 253 253 253 253 253 253
37727 -253 253 253 253 253 253 253 253 253 253 253 253
37728 -253 253 253 253 253 253 253 253 253 253 253 253
37729 -253 253 253 253 253 253 253 253 253 253 253 253
37730 -253 253 253 253 253 253 226 226 226 10 10 10
37731 - 2 2 6 6 6 6 30 30 30 2 2 6
37732 - 2 2 6 2 2 6 2 2 6 2 2 6
37733 - 2 2 6 66 66 66 58 58 58 22 22 22
37734 - 6 6 6 0 0 0 0 0 0 0 0 0
37735 - 0 0 0 0 0 0 0 0 0 0 0 0
37736 - 0 0 0 0 0 0 0 0 0 0 0 0
37737 - 0 0 0 0 0 0 0 0 0 0 0 0
37738 - 0 0 0 0 0 0 0 0 0 0 0 0
37739 - 0 0 0 0 0 0 0 0 0 0 0 0
37740 - 0 0 0 0 0 0 6 6 6 22 22 22
37741 - 58 58 58 62 62 62 2 2 6 2 2 6
37742 - 2 2 6 2 2 6 30 30 30 78 78 78
37743 -250 250 250 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 231 231 231 246 246 246
37746 -253 253 253 253 253 253 253 253 253 253 253 253
37747 -253 253 253 253 253 253 253 253 253 253 253 253
37748 -253 253 253 253 253 253 253 253 253 253 253 253
37749 -253 253 253 253 253 253 253 253 253 253 253 253
37750 -253 253 253 253 253 253 206 206 206 2 2 6
37751 - 22 22 22 34 34 34 18 14 6 22 22 22
37752 - 26 26 26 18 18 18 6 6 6 2 2 6
37753 - 2 2 6 82 82 82 54 54 54 18 18 18
37754 - 6 6 6 0 0 0 0 0 0 0 0 0
37755 - 0 0 0 0 0 0 0 0 0 0 0 0
37756 - 0 0 0 0 0 0 0 0 0 0 0 0
37757 - 0 0 0 0 0 0 0 0 0 0 0 0
37758 - 0 0 0 0 0 0 0 0 0 0 0 0
37759 - 0 0 0 0 0 0 0 0 0 0 0 0
37760 - 0 0 0 0 0 0 6 6 6 26 26 26
37761 - 62 62 62 106 106 106 74 54 14 185 133 11
37762 -210 162 10 121 92 8 6 6 6 62 62 62
37763 -238 238 238 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 231 231 231 246 246 246
37766 -253 253 253 253 253 253 253 253 253 253 253 253
37767 -253 253 253 253 253 253 253 253 253 253 253 253
37768 -253 253 253 253 253 253 253 253 253 253 253 253
37769 -253 253 253 253 253 253 253 253 253 253 253 253
37770 -253 253 253 253 253 253 158 158 158 18 18 18
37771 - 14 14 14 2 2 6 2 2 6 2 2 6
37772 - 6 6 6 18 18 18 66 66 66 38 38 38
37773 - 6 6 6 94 94 94 50 50 50 18 18 18
37774 - 6 6 6 0 0 0 0 0 0 0 0 0
37775 - 0 0 0 0 0 0 0 0 0 0 0 0
37776 - 0 0 0 0 0 0 0 0 0 0 0 0
37777 - 0 0 0 0 0 0 0 0 0 0 0 0
37778 - 0 0 0 0 0 0 0 0 0 0 0 0
37779 - 0 0 0 0 0 0 0 0 0 6 6 6
37780 - 10 10 10 10 10 10 18 18 18 38 38 38
37781 - 78 78 78 142 134 106 216 158 10 242 186 14
37782 -246 190 14 246 190 14 156 118 10 10 10 10
37783 - 90 90 90 238 238 238 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 231 231 231 250 250 250
37786 -253 253 253 253 253 253 253 253 253 253 253 253
37787 -253 253 253 253 253 253 253 253 253 253 253 253
37788 -253 253 253 253 253 253 253 253 253 253 253 253
37789 -253 253 253 253 253 253 253 253 253 246 230 190
37790 -238 204 91 238 204 91 181 142 44 37 26 9
37791 - 2 2 6 2 2 6 2 2 6 2 2 6
37792 - 2 2 6 2 2 6 38 38 38 46 46 46
37793 - 26 26 26 106 106 106 54 54 54 18 18 18
37794 - 6 6 6 0 0 0 0 0 0 0 0 0
37795 - 0 0 0 0 0 0 0 0 0 0 0 0
37796 - 0 0 0 0 0 0 0 0 0 0 0 0
37797 - 0 0 0 0 0 0 0 0 0 0 0 0
37798 - 0 0 0 0 0 0 0 0 0 0 0 0
37799 - 0 0 0 6 6 6 14 14 14 22 22 22
37800 - 30 30 30 38 38 38 50 50 50 70 70 70
37801 -106 106 106 190 142 34 226 170 11 242 186 14
37802 -246 190 14 246 190 14 246 190 14 154 114 10
37803 - 6 6 6 74 74 74 226 226 226 253 253 253
37804 -253 253 253 253 253 253 253 253 253 253 253 253
37805 -253 253 253 253 253 253 231 231 231 250 250 250
37806 -253 253 253 253 253 253 253 253 253 253 253 253
37807 -253 253 253 253 253 253 253 253 253 253 253 253
37808 -253 253 253 253 253 253 253 253 253 253 253 253
37809 -253 253 253 253 253 253 253 253 253 228 184 62
37810 -241 196 14 241 208 19 232 195 16 38 30 10
37811 - 2 2 6 2 2 6 2 2 6 2 2 6
37812 - 2 2 6 6 6 6 30 30 30 26 26 26
37813 -203 166 17 154 142 90 66 66 66 26 26 26
37814 - 6 6 6 0 0 0 0 0 0 0 0 0
37815 - 0 0 0 0 0 0 0 0 0 0 0 0
37816 - 0 0 0 0 0 0 0 0 0 0 0 0
37817 - 0 0 0 0 0 0 0 0 0 0 0 0
37818 - 0 0 0 0 0 0 0 0 0 0 0 0
37819 - 6 6 6 18 18 18 38 38 38 58 58 58
37820 - 78 78 78 86 86 86 101 101 101 123 123 123
37821 -175 146 61 210 150 10 234 174 13 246 186 14
37822 -246 190 14 246 190 14 246 190 14 238 190 10
37823 -102 78 10 2 2 6 46 46 46 198 198 198
37824 -253 253 253 253 253 253 253 253 253 253 253 253
37825 -253 253 253 253 253 253 234 234 234 242 242 242
37826 -253 253 253 253 253 253 253 253 253 253 253 253
37827 -253 253 253 253 253 253 253 253 253 253 253 253
37828 -253 253 253 253 253 253 253 253 253 253 253 253
37829 -253 253 253 253 253 253 253 253 253 224 178 62
37830 -242 186 14 241 196 14 210 166 10 22 18 6
37831 - 2 2 6 2 2 6 2 2 6 2 2 6
37832 - 2 2 6 2 2 6 6 6 6 121 92 8
37833 -238 202 15 232 195 16 82 82 82 34 34 34
37834 - 10 10 10 0 0 0 0 0 0 0 0 0
37835 - 0 0 0 0 0 0 0 0 0 0 0 0
37836 - 0 0 0 0 0 0 0 0 0 0 0 0
37837 - 0 0 0 0 0 0 0 0 0 0 0 0
37838 - 0 0 0 0 0 0 0 0 0 0 0 0
37839 - 14 14 14 38 38 38 70 70 70 154 122 46
37840 -190 142 34 200 144 11 197 138 11 197 138 11
37841 -213 154 11 226 170 11 242 186 14 246 190 14
37842 -246 190 14 246 190 14 246 190 14 246 190 14
37843 -225 175 15 46 32 6 2 2 6 22 22 22
37844 -158 158 158 250 250 250 253 253 253 253 253 253
37845 -253 253 253 253 253 253 253 253 253 253 253 253
37846 -253 253 253 253 253 253 253 253 253 253 253 253
37847 -253 253 253 253 253 253 253 253 253 253 253 253
37848 -253 253 253 253 253 253 253 253 253 253 253 253
37849 -253 253 253 250 250 250 242 242 242 224 178 62
37850 -239 182 13 236 186 11 213 154 11 46 32 6
37851 - 2 2 6 2 2 6 2 2 6 2 2 6
37852 - 2 2 6 2 2 6 61 42 6 225 175 15
37853 -238 190 10 236 186 11 112 100 78 42 42 42
37854 - 14 14 14 0 0 0 0 0 0 0 0 0
37855 - 0 0 0 0 0 0 0 0 0 0 0 0
37856 - 0 0 0 0 0 0 0 0 0 0 0 0
37857 - 0 0 0 0 0 0 0 0 0 0 0 0
37858 - 0 0 0 0 0 0 0 0 0 6 6 6
37859 - 22 22 22 54 54 54 154 122 46 213 154 11
37860 -226 170 11 230 174 11 226 170 11 226 170 11
37861 -236 178 12 242 186 14 246 190 14 246 190 14
37862 -246 190 14 246 190 14 246 190 14 246 190 14
37863 -241 196 14 184 144 12 10 10 10 2 2 6
37864 - 6 6 6 116 116 116 242 242 242 253 253 253
37865 -253 253 253 253 253 253 253 253 253 253 253 253
37866 -253 253 253 253 253 253 253 253 253 253 253 253
37867 -253 253 253 253 253 253 253 253 253 253 253 253
37868 -253 253 253 253 253 253 253 253 253 253 253 253
37869 -253 253 253 231 231 231 198 198 198 214 170 54
37870 -236 178 12 236 178 12 210 150 10 137 92 6
37871 - 18 14 6 2 2 6 2 2 6 2 2 6
37872 - 6 6 6 70 47 6 200 144 11 236 178 12
37873 -239 182 13 239 182 13 124 112 88 58 58 58
37874 - 22 22 22 6 6 6 0 0 0 0 0 0
37875 - 0 0 0 0 0 0 0 0 0 0 0 0
37876 - 0 0 0 0 0 0 0 0 0 0 0 0
37877 - 0 0 0 0 0 0 0 0 0 0 0 0
37878 - 0 0 0 0 0 0 0 0 0 10 10 10
37879 - 30 30 30 70 70 70 180 133 36 226 170 11
37880 -239 182 13 242 186 14 242 186 14 246 186 14
37881 -246 190 14 246 190 14 246 190 14 246 190 14
37882 -246 190 14 246 190 14 246 190 14 246 190 14
37883 -246 190 14 232 195 16 98 70 6 2 2 6
37884 - 2 2 6 2 2 6 66 66 66 221 221 221
37885 -253 253 253 253 253 253 253 253 253 253 253 253
37886 -253 253 253 253 253 253 253 253 253 253 253 253
37887 -253 253 253 253 253 253 253 253 253 253 253 253
37888 -253 253 253 253 253 253 253 253 253 253 253 253
37889 -253 253 253 206 206 206 198 198 198 214 166 58
37890 -230 174 11 230 174 11 216 158 10 192 133 9
37891 -163 110 8 116 81 8 102 78 10 116 81 8
37892 -167 114 7 197 138 11 226 170 11 239 182 13
37893 -242 186 14 242 186 14 162 146 94 78 78 78
37894 - 34 34 34 14 14 14 6 6 6 0 0 0
37895 - 0 0 0 0 0 0 0 0 0 0 0 0
37896 - 0 0 0 0 0 0 0 0 0 0 0 0
37897 - 0 0 0 0 0 0 0 0 0 0 0 0
37898 - 0 0 0 0 0 0 0 0 0 6 6 6
37899 - 30 30 30 78 78 78 190 142 34 226 170 11
37900 -239 182 13 246 190 14 246 190 14 246 190 14
37901 -246 190 14 246 190 14 246 190 14 246 190 14
37902 -246 190 14 246 190 14 246 190 14 246 190 14
37903 -246 190 14 241 196 14 203 166 17 22 18 6
37904 - 2 2 6 2 2 6 2 2 6 38 38 38
37905 -218 218 218 253 253 253 253 253 253 253 253 253
37906 -253 253 253 253 253 253 253 253 253 253 253 253
37907 -253 253 253 253 253 253 253 253 253 253 253 253
37908 -253 253 253 253 253 253 253 253 253 253 253 253
37909 -250 250 250 206 206 206 198 198 198 202 162 69
37910 -226 170 11 236 178 12 224 166 10 210 150 10
37911 -200 144 11 197 138 11 192 133 9 197 138 11
37912 -210 150 10 226 170 11 242 186 14 246 190 14
37913 -246 190 14 246 186 14 225 175 15 124 112 88
37914 - 62 62 62 30 30 30 14 14 14 6 6 6
37915 - 0 0 0 0 0 0 0 0 0 0 0 0
37916 - 0 0 0 0 0 0 0 0 0 0 0 0
37917 - 0 0 0 0 0 0 0 0 0 0 0 0
37918 - 0 0 0 0 0 0 0 0 0 10 10 10
37919 - 30 30 30 78 78 78 174 135 50 224 166 10
37920 -239 182 13 246 190 14 246 190 14 246 190 14
37921 -246 190 14 246 190 14 246 190 14 246 190 14
37922 -246 190 14 246 190 14 246 190 14 246 190 14
37923 -246 190 14 246 190 14 241 196 14 139 102 15
37924 - 2 2 6 2 2 6 2 2 6 2 2 6
37925 - 78 78 78 250 250 250 253 253 253 253 253 253
37926 -253 253 253 253 253 253 253 253 253 253 253 253
37927 -253 253 253 253 253 253 253 253 253 253 253 253
37928 -253 253 253 253 253 253 253 253 253 253 253 253
37929 -250 250 250 214 214 214 198 198 198 190 150 46
37930 -219 162 10 236 178 12 234 174 13 224 166 10
37931 -216 158 10 213 154 11 213 154 11 216 158 10
37932 -226 170 11 239 182 13 246 190 14 246 190 14
37933 -246 190 14 246 190 14 242 186 14 206 162 42
37934 -101 101 101 58 58 58 30 30 30 14 14 14
37935 - 6 6 6 0 0 0 0 0 0 0 0 0
37936 - 0 0 0 0 0 0 0 0 0 0 0 0
37937 - 0 0 0 0 0 0 0 0 0 0 0 0
37938 - 0 0 0 0 0 0 0 0 0 10 10 10
37939 - 30 30 30 74 74 74 174 135 50 216 158 10
37940 -236 178 12 246 190 14 246 190 14 246 190 14
37941 -246 190 14 246 190 14 246 190 14 246 190 14
37942 -246 190 14 246 190 14 246 190 14 246 190 14
37943 -246 190 14 246 190 14 241 196 14 226 184 13
37944 - 61 42 6 2 2 6 2 2 6 2 2 6
37945 - 22 22 22 238 238 238 253 253 253 253 253 253
37946 -253 253 253 253 253 253 253 253 253 253 253 253
37947 -253 253 253 253 253 253 253 253 253 253 253 253
37948 -253 253 253 253 253 253 253 253 253 253 253 253
37949 -253 253 253 226 226 226 187 187 187 180 133 36
37950 -216 158 10 236 178 12 239 182 13 236 178 12
37951 -230 174 11 226 170 11 226 170 11 230 174 11
37952 -236 178 12 242 186 14 246 190 14 246 190 14
37953 -246 190 14 246 190 14 246 186 14 239 182 13
37954 -206 162 42 106 106 106 66 66 66 34 34 34
37955 - 14 14 14 6 6 6 0 0 0 0 0 0
37956 - 0 0 0 0 0 0 0 0 0 0 0 0
37957 - 0 0 0 0 0 0 0 0 0 0 0 0
37958 - 0 0 0 0 0 0 0 0 0 6 6 6
37959 - 26 26 26 70 70 70 163 133 67 213 154 11
37960 -236 178 12 246 190 14 246 190 14 246 190 14
37961 -246 190 14 246 190 14 246 190 14 246 190 14
37962 -246 190 14 246 190 14 246 190 14 246 190 14
37963 -246 190 14 246 190 14 246 190 14 241 196 14
37964 -190 146 13 18 14 6 2 2 6 2 2 6
37965 - 46 46 46 246 246 246 253 253 253 253 253 253
37966 -253 253 253 253 253 253 253 253 253 253 253 253
37967 -253 253 253 253 253 253 253 253 253 253 253 253
37968 -253 253 253 253 253 253 253 253 253 253 253 253
37969 -253 253 253 221 221 221 86 86 86 156 107 11
37970 -216 158 10 236 178 12 242 186 14 246 186 14
37971 -242 186 14 239 182 13 239 182 13 242 186 14
37972 -242 186 14 246 186 14 246 190 14 246 190 14
37973 -246 190 14 246 190 14 246 190 14 246 190 14
37974 -242 186 14 225 175 15 142 122 72 66 66 66
37975 - 30 30 30 10 10 10 0 0 0 0 0 0
37976 - 0 0 0 0 0 0 0 0 0 0 0 0
37977 - 0 0 0 0 0 0 0 0 0 0 0 0
37978 - 0 0 0 0 0 0 0 0 0 6 6 6
37979 - 26 26 26 70 70 70 163 133 67 210 150 10
37980 -236 178 12 246 190 14 246 190 14 246 190 14
37981 -246 190 14 246 190 14 246 190 14 246 190 14
37982 -246 190 14 246 190 14 246 190 14 246 190 14
37983 -246 190 14 246 190 14 246 190 14 246 190 14
37984 -232 195 16 121 92 8 34 34 34 106 106 106
37985 -221 221 221 253 253 253 253 253 253 253 253 253
37986 -253 253 253 253 253 253 253 253 253 253 253 253
37987 -253 253 253 253 253 253 253 253 253 253 253 253
37988 -253 253 253 253 253 253 253 253 253 253 253 253
37989 -242 242 242 82 82 82 18 14 6 163 110 8
37990 -216 158 10 236 178 12 242 186 14 246 190 14
37991 -246 190 14 246 190 14 246 190 14 246 190 14
37992 -246 190 14 246 190 14 246 190 14 246 190 14
37993 -246 190 14 246 190 14 246 190 14 246 190 14
37994 -246 190 14 246 190 14 242 186 14 163 133 67
37995 - 46 46 46 18 18 18 6 6 6 0 0 0
37996 - 0 0 0 0 0 0 0 0 0 0 0 0
37997 - 0 0 0 0 0 0 0 0 0 0 0 0
37998 - 0 0 0 0 0 0 0 0 0 10 10 10
37999 - 30 30 30 78 78 78 163 133 67 210 150 10
38000 -236 178 12 246 186 14 246 190 14 246 190 14
38001 -246 190 14 246 190 14 246 190 14 246 190 14
38002 -246 190 14 246 190 14 246 190 14 246 190 14
38003 -246 190 14 246 190 14 246 190 14 246 190 14
38004 -241 196 14 215 174 15 190 178 144 253 253 253
38005 -253 253 253 253 253 253 253 253 253 253 253 253
38006 -253 253 253 253 253 253 253 253 253 253 253 253
38007 -253 253 253 253 253 253 253 253 253 253 253 253
38008 -253 253 253 253 253 253 253 253 253 218 218 218
38009 - 58 58 58 2 2 6 22 18 6 167 114 7
38010 -216 158 10 236 178 12 246 186 14 246 190 14
38011 -246 190 14 246 190 14 246 190 14 246 190 14
38012 -246 190 14 246 190 14 246 190 14 246 190 14
38013 -246 190 14 246 190 14 246 190 14 246 190 14
38014 -246 190 14 246 186 14 242 186 14 190 150 46
38015 - 54 54 54 22 22 22 6 6 6 0 0 0
38016 - 0 0 0 0 0 0 0 0 0 0 0 0
38017 - 0 0 0 0 0 0 0 0 0 0 0 0
38018 - 0 0 0 0 0 0 0 0 0 14 14 14
38019 - 38 38 38 86 86 86 180 133 36 213 154 11
38020 -236 178 12 246 186 14 246 190 14 246 190 14
38021 -246 190 14 246 190 14 246 190 14 246 190 14
38022 -246 190 14 246 190 14 246 190 14 246 190 14
38023 -246 190 14 246 190 14 246 190 14 246 190 14
38024 -246 190 14 232 195 16 190 146 13 214 214 214
38025 -253 253 253 253 253 253 253 253 253 253 253 253
38026 -253 253 253 253 253 253 253 253 253 253 253 253
38027 -253 253 253 253 253 253 253 253 253 253 253 253
38028 -253 253 253 250 250 250 170 170 170 26 26 26
38029 - 2 2 6 2 2 6 37 26 9 163 110 8
38030 -219 162 10 239 182 13 246 186 14 246 190 14
38031 -246 190 14 246 190 14 246 190 14 246 190 14
38032 -246 190 14 246 190 14 246 190 14 246 190 14
38033 -246 190 14 246 190 14 246 190 14 246 190 14
38034 -246 186 14 236 178 12 224 166 10 142 122 72
38035 - 46 46 46 18 18 18 6 6 6 0 0 0
38036 - 0 0 0 0 0 0 0 0 0 0 0 0
38037 - 0 0 0 0 0 0 0 0 0 0 0 0
38038 - 0 0 0 0 0 0 6 6 6 18 18 18
38039 - 50 50 50 109 106 95 192 133 9 224 166 10
38040 -242 186 14 246 190 14 246 190 14 246 190 14
38041 -246 190 14 246 190 14 246 190 14 246 190 14
38042 -246 190 14 246 190 14 246 190 14 246 190 14
38043 -246 190 14 246 190 14 246 190 14 246 190 14
38044 -242 186 14 226 184 13 210 162 10 142 110 46
38045 -226 226 226 253 253 253 253 253 253 253 253 253
38046 -253 253 253 253 253 253 253 253 253 253 253 253
38047 -253 253 253 253 253 253 253 253 253 253 253 253
38048 -198 198 198 66 66 66 2 2 6 2 2 6
38049 - 2 2 6 2 2 6 50 34 6 156 107 11
38050 -219 162 10 239 182 13 246 186 14 246 190 14
38051 -246 190 14 246 190 14 246 190 14 246 190 14
38052 -246 190 14 246 190 14 246 190 14 246 190 14
38053 -246 190 14 246 190 14 246 190 14 242 186 14
38054 -234 174 13 213 154 11 154 122 46 66 66 66
38055 - 30 30 30 10 10 10 0 0 0 0 0 0
38056 - 0 0 0 0 0 0 0 0 0 0 0 0
38057 - 0 0 0 0 0 0 0 0 0 0 0 0
38058 - 0 0 0 0 0 0 6 6 6 22 22 22
38059 - 58 58 58 154 121 60 206 145 10 234 174 13
38060 -242 186 14 246 186 14 246 190 14 246 190 14
38061 -246 190 14 246 190 14 246 190 14 246 190 14
38062 -246 190 14 246 190 14 246 190 14 246 190 14
38063 -246 190 14 246 190 14 246 190 14 246 190 14
38064 -246 186 14 236 178 12 210 162 10 163 110 8
38065 - 61 42 6 138 138 138 218 218 218 250 250 250
38066 -253 253 253 253 253 253 253 253 253 250 250 250
38067 -242 242 242 210 210 210 144 144 144 66 66 66
38068 - 6 6 6 2 2 6 2 2 6 2 2 6
38069 - 2 2 6 2 2 6 61 42 6 163 110 8
38070 -216 158 10 236 178 12 246 190 14 246 190 14
38071 -246 190 14 246 190 14 246 190 14 246 190 14
38072 -246 190 14 246 190 14 246 190 14 246 190 14
38073 -246 190 14 239 182 13 230 174 11 216 158 10
38074 -190 142 34 124 112 88 70 70 70 38 38 38
38075 - 18 18 18 6 6 6 0 0 0 0 0 0
38076 - 0 0 0 0 0 0 0 0 0 0 0 0
38077 - 0 0 0 0 0 0 0 0 0 0 0 0
38078 - 0 0 0 0 0 0 6 6 6 22 22 22
38079 - 62 62 62 168 124 44 206 145 10 224 166 10
38080 -236 178 12 239 182 13 242 186 14 242 186 14
38081 -246 186 14 246 190 14 246 190 14 246 190 14
38082 -246 190 14 246 190 14 246 190 14 246 190 14
38083 -246 190 14 246 190 14 246 190 14 246 190 14
38084 -246 190 14 236 178 12 216 158 10 175 118 6
38085 - 80 54 7 2 2 6 6 6 6 30 30 30
38086 - 54 54 54 62 62 62 50 50 50 38 38 38
38087 - 14 14 14 2 2 6 2 2 6 2 2 6
38088 - 2 2 6 2 2 6 2 2 6 2 2 6
38089 - 2 2 6 6 6 6 80 54 7 167 114 7
38090 -213 154 11 236 178 12 246 190 14 246 190 14
38091 -246 190 14 246 190 14 246 190 14 246 190 14
38092 -246 190 14 242 186 14 239 182 13 239 182 13
38093 -230 174 11 210 150 10 174 135 50 124 112 88
38094 - 82 82 82 54 54 54 34 34 34 18 18 18
38095 - 6 6 6 0 0 0 0 0 0 0 0 0
38096 - 0 0 0 0 0 0 0 0 0 0 0 0
38097 - 0 0 0 0 0 0 0 0 0 0 0 0
38098 - 0 0 0 0 0 0 6 6 6 18 18 18
38099 - 50 50 50 158 118 36 192 133 9 200 144 11
38100 -216 158 10 219 162 10 224 166 10 226 170 11
38101 -230 174 11 236 178 12 239 182 13 239 182 13
38102 -242 186 14 246 186 14 246 190 14 246 190 14
38103 -246 190 14 246 190 14 246 190 14 246 190 14
38104 -246 186 14 230 174 11 210 150 10 163 110 8
38105 -104 69 6 10 10 10 2 2 6 2 2 6
38106 - 2 2 6 2 2 6 2 2 6 2 2 6
38107 - 2 2 6 2 2 6 2 2 6 2 2 6
38108 - 2 2 6 2 2 6 2 2 6 2 2 6
38109 - 2 2 6 6 6 6 91 60 6 167 114 7
38110 -206 145 10 230 174 11 242 186 14 246 190 14
38111 -246 190 14 246 190 14 246 186 14 242 186 14
38112 -239 182 13 230 174 11 224 166 10 213 154 11
38113 -180 133 36 124 112 88 86 86 86 58 58 58
38114 - 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0 0 0 0 0 0 0
38118 - 0 0 0 0 0 0 0 0 0 14 14 14
38119 - 34 34 34 70 70 70 138 110 50 158 118 36
38120 -167 114 7 180 123 7 192 133 9 197 138 11
38121 -200 144 11 206 145 10 213 154 11 219 162 10
38122 -224 166 10 230 174 11 239 182 13 242 186 14
38123 -246 186 14 246 186 14 246 186 14 246 186 14
38124 -239 182 13 216 158 10 185 133 11 152 99 6
38125 -104 69 6 18 14 6 2 2 6 2 2 6
38126 - 2 2 6 2 2 6 2 2 6 2 2 6
38127 - 2 2 6 2 2 6 2 2 6 2 2 6
38128 - 2 2 6 2 2 6 2 2 6 2 2 6
38129 - 2 2 6 6 6 6 80 54 7 152 99 6
38130 -192 133 9 219 162 10 236 178 12 239 182 13
38131 -246 186 14 242 186 14 239 182 13 236 178 12
38132 -224 166 10 206 145 10 192 133 9 154 121 60
38133 - 94 94 94 62 62 62 42 42 42 22 22 22
38134 - 14 14 14 6 6 6 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 0 0 0 0 0 0 6 6 6
38139 - 18 18 18 34 34 34 58 58 58 78 78 78
38140 -101 98 89 124 112 88 142 110 46 156 107 11
38141 -163 110 8 167 114 7 175 118 6 180 123 7
38142 -185 133 11 197 138 11 210 150 10 219 162 10
38143 -226 170 11 236 178 12 236 178 12 234 174 13
38144 -219 162 10 197 138 11 163 110 8 130 83 6
38145 - 91 60 6 10 10 10 2 2 6 2 2 6
38146 - 18 18 18 38 38 38 38 38 38 38 38 38
38147 - 38 38 38 38 38 38 38 38 38 38 38 38
38148 - 38 38 38 38 38 38 26 26 26 2 2 6
38149 - 2 2 6 6 6 6 70 47 6 137 92 6
38150 -175 118 6 200 144 11 219 162 10 230 174 11
38151 -234 174 13 230 174 11 219 162 10 210 150 10
38152 -192 133 9 163 110 8 124 112 88 82 82 82
38153 - 50 50 50 30 30 30 14 14 14 6 6 6
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 14 14 14 22 22 22 34 34 34
38160 - 42 42 42 58 58 58 74 74 74 86 86 86
38161 -101 98 89 122 102 70 130 98 46 121 87 25
38162 -137 92 6 152 99 6 163 110 8 180 123 7
38163 -185 133 11 197 138 11 206 145 10 200 144 11
38164 -180 123 7 156 107 11 130 83 6 104 69 6
38165 - 50 34 6 54 54 54 110 110 110 101 98 89
38166 - 86 86 86 82 82 82 78 78 78 78 78 78
38167 - 78 78 78 78 78 78 78 78 78 78 78 78
38168 - 78 78 78 82 82 82 86 86 86 94 94 94
38169 -106 106 106 101 101 101 86 66 34 124 80 6
38170 -156 107 11 180 123 7 192 133 9 200 144 11
38171 -206 145 10 200 144 11 192 133 9 175 118 6
38172 -139 102 15 109 106 95 70 70 70 42 42 42
38173 - 22 22 22 10 10 10 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 6 6 6 10 10 10
38180 - 14 14 14 22 22 22 30 30 30 38 38 38
38181 - 50 50 50 62 62 62 74 74 74 90 90 90
38182 -101 98 89 112 100 78 121 87 25 124 80 6
38183 -137 92 6 152 99 6 152 99 6 152 99 6
38184 -138 86 6 124 80 6 98 70 6 86 66 30
38185 -101 98 89 82 82 82 58 58 58 46 46 46
38186 - 38 38 38 34 34 34 34 34 34 34 34 34
38187 - 34 34 34 34 34 34 34 34 34 34 34 34
38188 - 34 34 34 34 34 34 38 38 38 42 42 42
38189 - 54 54 54 82 82 82 94 86 76 91 60 6
38190 -134 86 6 156 107 11 167 114 7 175 118 6
38191 -175 118 6 167 114 7 152 99 6 121 87 25
38192 -101 98 89 62 62 62 34 34 34 18 18 18
38193 - 6 6 6 0 0 0 0 0 0 0 0 0
38194 - 0 0 0 0 0 0 0 0 0 0 0 0
38195 - 0 0 0 0 0 0 0 0 0 0 0 0
38196 - 0 0 0 0 0 0 0 0 0 0 0 0
38197 - 0 0 0 0 0 0 0 0 0 0 0 0
38198 - 0 0 0 0 0 0 0 0 0 0 0 0
38199 - 0 0 0 0 0 0 0 0 0 0 0 0
38200 - 0 0 0 6 6 6 6 6 6 10 10 10
38201 - 18 18 18 22 22 22 30 30 30 42 42 42
38202 - 50 50 50 66 66 66 86 86 86 101 98 89
38203 -106 86 58 98 70 6 104 69 6 104 69 6
38204 -104 69 6 91 60 6 82 62 34 90 90 90
38205 - 62 62 62 38 38 38 22 22 22 14 14 14
38206 - 10 10 10 10 10 10 10 10 10 10 10 10
38207 - 10 10 10 10 10 10 6 6 6 10 10 10
38208 - 10 10 10 10 10 10 10 10 10 14 14 14
38209 - 22 22 22 42 42 42 70 70 70 89 81 66
38210 - 80 54 7 104 69 6 124 80 6 137 92 6
38211 -134 86 6 116 81 8 100 82 52 86 86 86
38212 - 58 58 58 30 30 30 14 14 14 6 6 6
38213 - 0 0 0 0 0 0 0 0 0 0 0 0
38214 - 0 0 0 0 0 0 0 0 0 0 0 0
38215 - 0 0 0 0 0 0 0 0 0 0 0 0
38216 - 0 0 0 0 0 0 0 0 0 0 0 0
38217 - 0 0 0 0 0 0 0 0 0 0 0 0
38218 - 0 0 0 0 0 0 0 0 0 0 0 0
38219 - 0 0 0 0 0 0 0 0 0 0 0 0
38220 - 0 0 0 0 0 0 0 0 0 0 0 0
38221 - 0 0 0 6 6 6 10 10 10 14 14 14
38222 - 18 18 18 26 26 26 38 38 38 54 54 54
38223 - 70 70 70 86 86 86 94 86 76 89 81 66
38224 - 89 81 66 86 86 86 74 74 74 50 50 50
38225 - 30 30 30 14 14 14 6 6 6 0 0 0
38226 - 0 0 0 0 0 0 0 0 0 0 0 0
38227 - 0 0 0 0 0 0 0 0 0 0 0 0
38228 - 0 0 0 0 0 0 0 0 0 0 0 0
38229 - 6 6 6 18 18 18 34 34 34 58 58 58
38230 - 82 82 82 89 81 66 89 81 66 89 81 66
38231 - 94 86 66 94 86 76 74 74 74 50 50 50
38232 - 26 26 26 14 14 14 6 6 6 0 0 0
38233 - 0 0 0 0 0 0 0 0 0 0 0 0
38234 - 0 0 0 0 0 0 0 0 0 0 0 0
38235 - 0 0 0 0 0 0 0 0 0 0 0 0
38236 - 0 0 0 0 0 0 0 0 0 0 0 0
38237 - 0 0 0 0 0 0 0 0 0 0 0 0
38238 - 0 0 0 0 0 0 0 0 0 0 0 0
38239 - 0 0 0 0 0 0 0 0 0 0 0 0
38240 - 0 0 0 0 0 0 0 0 0 0 0 0
38241 - 0 0 0 0 0 0 0 0 0 0 0 0
38242 - 6 6 6 6 6 6 14 14 14 18 18 18
38243 - 30 30 30 38 38 38 46 46 46 54 54 54
38244 - 50 50 50 42 42 42 30 30 30 18 18 18
38245 - 10 10 10 0 0 0 0 0 0 0 0 0
38246 - 0 0 0 0 0 0 0 0 0 0 0 0
38247 - 0 0 0 0 0 0 0 0 0 0 0 0
38248 - 0 0 0 0 0 0 0 0 0 0 0 0
38249 - 0 0 0 6 6 6 14 14 14 26 26 26
38250 - 38 38 38 50 50 50 58 58 58 58 58 58
38251 - 54 54 54 42 42 42 30 30 30 18 18 18
38252 - 10 10 10 0 0 0 0 0 0 0 0 0
38253 - 0 0 0 0 0 0 0 0 0 0 0 0
38254 - 0 0 0 0 0 0 0 0 0 0 0 0
38255 - 0 0 0 0 0 0 0 0 0 0 0 0
38256 - 0 0 0 0 0 0 0 0 0 0 0 0
38257 - 0 0 0 0 0 0 0 0 0 0 0 0
38258 - 0 0 0 0 0 0 0 0 0 0 0 0
38259 - 0 0 0 0 0 0 0 0 0 0 0 0
38260 - 0 0 0 0 0 0 0 0 0 0 0 0
38261 - 0 0 0 0 0 0 0 0 0 0 0 0
38262 - 0 0 0 0 0 0 0 0 0 6 6 6
38263 - 6 6 6 10 10 10 14 14 14 18 18 18
38264 - 18 18 18 14 14 14 10 10 10 6 6 6
38265 - 0 0 0 0 0 0 0 0 0 0 0 0
38266 - 0 0 0 0 0 0 0 0 0 0 0 0
38267 - 0 0 0 0 0 0 0 0 0 0 0 0
38268 - 0 0 0 0 0 0 0 0 0 0 0 0
38269 - 0 0 0 0 0 0 0 0 0 6 6 6
38270 - 14 14 14 18 18 18 22 22 22 22 22 22
38271 - 18 18 18 14 14 14 10 10 10 6 6 6
38272 - 0 0 0 0 0 0 0 0 0 0 0 0
38273 - 0 0 0 0 0 0 0 0 0 0 0 0
38274 - 0 0 0 0 0 0 0 0 0 0 0 0
38275 - 0 0 0 0 0 0 0 0 0 0 0 0
38276 - 0 0 0 0 0 0 0 0 0 0 0 0
38277 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
38283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
38288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38289 +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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38298 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38305 +4 4 4 4 4 4 4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38312 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38319 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
38324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
38329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38333 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38347 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
38351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38361 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
38365 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
38366 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
38367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38370 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
38371 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38372 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
38373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38375 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
38379 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
38380 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
38381 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38384 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
38385 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
38386 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
38387 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38389 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38393 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
38394 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
38395 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38398 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
38399 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
38400 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
38401 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
38403 +4 4 4 4 4 4 4 4 4 4 4 4 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 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
38407 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
38408 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
38409 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
38410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38411 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38412 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
38413 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
38414 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
38415 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
38417 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
38420 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
38421 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
38422 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
38423 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
38424 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38425 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
38426 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
38427 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
38428 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
38429 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
38431 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
38434 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
38435 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
38436 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
38437 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
38438 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
38439 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
38440 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
38441 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
38442 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
38443 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
38445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38447 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
38448 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
38449 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
38450 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
38451 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
38452 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
38453 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
38454 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
38455 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
38456 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
38457 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
38459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38461 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
38462 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
38463 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
38464 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
38465 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
38466 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
38467 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
38468 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
38469 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
38470 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
38471 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
38473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38475 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
38476 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
38477 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
38478 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
38479 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
38480 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
38481 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
38482 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
38483 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
38484 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
38485 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38489 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
38490 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
38491 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
38492 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
38493 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
38494 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
38495 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
38496 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
38497 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
38498 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
38499 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
38501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38502 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
38503 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
38504 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
38505 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
38506 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
38507 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
38508 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
38509 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
38510 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
38511 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
38512 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
38513 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
38515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38516 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
38517 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
38518 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
38519 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
38520 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
38521 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
38522 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
38523 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
38524 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
38525 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
38526 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
38527 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
38529 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38530 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
38531 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
38532 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
38533 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
38534 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
38535 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
38536 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
38537 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
38538 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
38539 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
38540 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
38541 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
38543 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
38544 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
38545 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
38546 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
38547 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
38548 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
38549 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
38550 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
38551 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
38552 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
38553 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
38554 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
38555 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
38557 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38558 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
38559 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
38560 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
38561 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
38562 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
38563 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
38564 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
38565 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
38566 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
38567 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
38568 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
38569 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
38571 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
38572 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
38573 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
38574 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
38575 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
38576 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
38577 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
38578 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
38579 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
38580 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
38581 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
38582 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
38583 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
38585 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
38586 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
38587 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
38588 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
38589 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
38590 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
38591 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
38592 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
38593 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
38594 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
38595 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
38596 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
38597 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
38599 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
38600 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
38601 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
38602 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
38603 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
38604 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
38605 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
38606 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
38607 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
38608 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
38609 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
38610 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
38611 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
38613 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
38614 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
38615 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
38616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
38617 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
38618 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
38619 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
38620 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
38621 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
38622 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
38623 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
38624 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
38625 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
38627 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
38628 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
38629 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
38630 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38631 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
38632 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
38633 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
38634 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
38635 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
38636 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
38637 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
38638 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
38639 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
38641 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
38642 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
38643 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
38644 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
38645 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
38646 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
38647 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
38648 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
38649 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
38650 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
38651 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
38652 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
38653 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
38655 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
38656 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
38657 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
38658 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
38659 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
38660 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38661 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
38662 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
38663 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
38664 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
38665 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
38666 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
38667 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
38669 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
38670 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
38671 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
38672 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
38673 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
38674 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38675 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
38676 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
38677 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
38678 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
38679 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
38680 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
38681 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
38683 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
38684 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
38685 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
38686 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
38687 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38688 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
38689 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
38690 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
38691 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
38692 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
38693 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
38694 +4 0 0 4 0 0 5 5 5 5 5 5 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
38697 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
38698 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
38699 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
38700 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
38701 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
38702 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38703 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38704 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
38705 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
38706 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
38707 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
38708 +3 3 3 5 5 5 6 6 6 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
38711 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
38712 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
38713 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
38714 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
38715 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38716 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
38717 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
38718 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
38719 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
38720 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
38721 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
38722 +4 4 4 4 4 4 4 4 4 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
38725 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
38726 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
38727 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
38728 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
38729 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38730 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38731 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38732 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
38733 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
38734 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
38735 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
38736 +4 4 4 4 4 4 4 4 4 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
38739 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
38740 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
38741 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
38742 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
38743 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38744 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
38745 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38746 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
38747 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
38748 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
38749 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38750 +4 4 4 4 4 4 4 4 4 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
38753 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
38754 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
38755 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
38756 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
38757 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38758 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
38759 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
38760 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
38761 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
38762 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
38763 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
38764 +4 4 4 4 4 4 4 4 4 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
38767 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
38768 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
38769 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
38770 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
38771 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38772 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
38773 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
38774 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
38775 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
38776 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
38777 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
38778 +4 4 4 4 4 4 4 4 4 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
38781 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
38782 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
38783 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
38784 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38785 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
38786 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
38787 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
38788 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
38789 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
38790 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
38791 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38792 +4 4 4 4 4 4 4 4 4 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
38795 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
38796 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
38797 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
38798 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38799 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38800 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
38801 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
38802 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
38803 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
38804 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
38805 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38806 +4 4 4 4 4 4 4 4 4 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
38809 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
38810 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
38811 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38812 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38813 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38814 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
38815 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
38816 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
38817 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
38818 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
38819 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38820 +4 4 4 4 4 4 4 4 4 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
38823 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
38824 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
38825 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38826 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38827 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38828 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
38829 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
38830 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
38831 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38832 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38833 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38834 +4 4 4 4 4 4 4 4 4 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
38837 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38838 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
38839 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38840 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
38841 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
38842 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
38843 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
38844 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
38845 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38846 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38847 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38848 +4 4 4 4 4 4 4 4 4 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
38851 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38852 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
38853 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38854 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
38855 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38856 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
38857 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
38858 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
38859 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38860 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38861 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38862 +4 4 4 4 4 4 4 4 4 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
38865 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
38866 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
38867 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38868 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
38869 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
38870 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
38871 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
38872 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
38873 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38874 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38875 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38876 +4 4 4 4 4 4 4 4 4 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
38879 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
38880 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
38881 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38882 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
38883 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
38884 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
38885 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
38886 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
38887 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38888 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38889 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38890 +4 4 4 4 4 4 4 4 4 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
38893 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38894 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
38895 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38896 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
38897 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
38898 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
38899 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
38900 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
38901 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38902 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38903 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38904 +4 4 4 4 4 4 4 4 4 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
38907 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
38908 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
38909 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38910 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
38911 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
38912 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
38913 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
38914 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
38915 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
38916 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38917 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38918 +4 4 4 4 4 4 4 4 4 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
38921 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38922 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
38923 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
38924 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
38925 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
38926 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
38927 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
38928 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
38929 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38930 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38931 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38932 +4 4 4 4 4 4 4 4 4 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
38935 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38936 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
38937 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38938 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
38939 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
38940 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
38941 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
38942 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
38943 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38944 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38945 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38946 +4 4 4 4 4 4 4 4 4 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
38949 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38950 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
38951 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
38952 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
38953 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
38954 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
38955 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38956 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
38957 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38958 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38959 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38960 +4 4 4 4 4 4 4 4 4 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
38963 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38964 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
38965 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
38966 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38967 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
38968 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
38969 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38970 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
38971 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38972 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38973 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38974 +4 4 4 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
38977 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38978 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
38979 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
38980 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
38981 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
38982 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
38983 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
38984 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
38985 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
38986 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38987 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38988 +4 4 4 4 4 4 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
38991 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38992 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
38993 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
38994 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
38995 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
38996 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
38997 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
38998 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
38999 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
39000 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39001 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39002 +4 4 4 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
39005 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
39006 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
39007 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
39008 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
39009 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
39010 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
39011 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
39012 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
39013 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
39014 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39015 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
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
39019 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
39020 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
39021 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
39022 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
39023 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
39024 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
39025 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
39026 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
39027 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
39028 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
39029 +0 0 0 3 3 3 5 5 5 4 4 4 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
39033 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
39034 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
39035 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
39036 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
39037 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
39038 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
39039 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
39040 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
39041 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
39042 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
39043 +0 0 0 3 3 3 5 5 5 4 4 4 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
39047 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
39048 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
39049 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
39050 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
39051 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
39052 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
39053 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
39054 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
39055 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
39056 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
39057 +0 0 0 4 4 4 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
39061 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
39062 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
39063 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
39064 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
39065 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
39066 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
39067 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39068 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
39069 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
39070 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
39071 +4 3 3 5 5 5 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
39075 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
39076 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
39077 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
39078 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
39079 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
39080 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
39081 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
39082 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
39083 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
39084 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
39085 +5 5 5 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
39089 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
39090 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
39091 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
39092 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
39093 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
39094 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
39095 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
39096 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
39097 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
39098 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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
39103 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39104 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
39105 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
39106 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
39107 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
39108 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
39109 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
39110 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
39111 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
39112 +13 16 17 4 0 0 4 0 0 4 3 3 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
39117 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
39118 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
39119 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
39120 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
39121 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
39122 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
39123 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
39124 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
39125 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
39126 +4 0 0 4 0 0 5 5 5 5 5 5 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
39131 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
39132 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
39133 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
39134 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
39135 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
39136 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
39137 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
39138 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
39139 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
39140 +4 3 3 5 5 5 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
39145 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
39146 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39147 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
39148 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
39149 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
39150 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
39151 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
39152 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
39153 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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
39159 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
39160 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
39161 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
39162 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
39163 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
39164 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
39165 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
39166 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
39167 +4 0 0 4 0 0 4 0 0 6 6 6 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
39173 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
39174 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
39175 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
39176 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
39177 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
39178 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
39179 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
39180 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
39181 +4 0 0 4 4 4 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
39187 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
39188 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
39189 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39190 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
39191 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
39192 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
39193 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
39194 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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
39201 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39202 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
39203 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
39204 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
39205 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
39206 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
39207 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
39208 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
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
39215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39216 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
39217 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39218 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
39219 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
39220 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
39221 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
39222 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 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
39229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39230 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
39231 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
39232 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
39233 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
39234 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
39235 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
39236 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 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
39243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39244 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
39245 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
39246 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39247 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
39248 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
39249 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
39250 +5 5 5 5 5 5 4 4 4 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
39257 +4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39260 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
39261 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
39262 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
39263 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
39264 +4 3 3 5 5 5 4 4 4 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
39271 +4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5
39274 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39275 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
39276 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
39277 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
39278 +4 4 4 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
39285 +4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39289 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39290 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
39291 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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
39299 +4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
39303 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39304 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39305 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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
39313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39316 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
39317 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
39318 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
39319 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
39320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39331 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
39332 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39333 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39345 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
39346 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
39347 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39359 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
39360 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
39361 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39373 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
39374 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
39375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39387 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39388 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
39389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39397 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
39398 index 3473e75..c930142 100644
39399 --- a/drivers/video/udlfb.c
39400 +++ b/drivers/video/udlfb.c
39401 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
39402 dlfb_urb_completion(urb);
39405 - atomic_add(bytes_sent, &dev->bytes_sent);
39406 - atomic_add(bytes_identical, &dev->bytes_identical);
39407 - atomic_add(width*height*2, &dev->bytes_rendered);
39408 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39409 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39410 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
39411 end_cycles = get_cycles();
39412 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39413 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39414 >> 10)), /* Kcycles */
39415 &dev->cpu_kcycles_used);
39417 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
39418 dlfb_urb_completion(urb);
39421 - atomic_add(bytes_sent, &dev->bytes_sent);
39422 - atomic_add(bytes_identical, &dev->bytes_identical);
39423 - atomic_add(bytes_rendered, &dev->bytes_rendered);
39424 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39425 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39426 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
39427 end_cycles = get_cycles();
39428 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39429 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39430 >> 10)), /* Kcycles */
39431 &dev->cpu_kcycles_used);
39433 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
39434 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39435 struct dlfb_data *dev = fb_info->par;
39436 return snprintf(buf, PAGE_SIZE, "%u\n",
39437 - atomic_read(&dev->bytes_rendered));
39438 + atomic_read_unchecked(&dev->bytes_rendered));
39441 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39442 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39443 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39444 struct dlfb_data *dev = fb_info->par;
39445 return snprintf(buf, PAGE_SIZE, "%u\n",
39446 - atomic_read(&dev->bytes_identical));
39447 + atomic_read_unchecked(&dev->bytes_identical));
39450 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39451 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39452 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39453 struct dlfb_data *dev = fb_info->par;
39454 return snprintf(buf, PAGE_SIZE, "%u\n",
39455 - atomic_read(&dev->bytes_sent));
39456 + atomic_read_unchecked(&dev->bytes_sent));
39459 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39460 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39461 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39462 struct dlfb_data *dev = fb_info->par;
39463 return snprintf(buf, PAGE_SIZE, "%u\n",
39464 - atomic_read(&dev->cpu_kcycles_used));
39465 + atomic_read_unchecked(&dev->cpu_kcycles_used));
39468 static ssize_t edid_show(
39469 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
39470 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39471 struct dlfb_data *dev = fb_info->par;
39473 - atomic_set(&dev->bytes_rendered, 0);
39474 - atomic_set(&dev->bytes_identical, 0);
39475 - atomic_set(&dev->bytes_sent, 0);
39476 - atomic_set(&dev->cpu_kcycles_used, 0);
39477 + atomic_set_unchecked(&dev->bytes_rendered, 0);
39478 + atomic_set_unchecked(&dev->bytes_identical, 0);
39479 + atomic_set_unchecked(&dev->bytes_sent, 0);
39480 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
39484 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
39485 index 7f8472c..9842e87 100644
39486 --- a/drivers/video/uvesafb.c
39487 +++ b/drivers/video/uvesafb.c
39489 #include <linux/io.h>
39490 #include <linux/mutex.h>
39491 #include <linux/slab.h>
39492 +#include <linux/moduleloader.h>
39493 #include <video/edid.h>
39494 #include <video/uvesafb.h>
39496 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
39500 - return call_usermodehelper(v86d_path, argv, envp, 1);
39501 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
39505 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
39506 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
39507 par->pmi_setpal = par->ypan = 0;
39510 +#ifdef CONFIG_PAX_KERNEXEC
39511 +#ifdef CONFIG_MODULES
39512 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
39514 + if (!par->pmi_code) {
39515 + par->pmi_setpal = par->ypan = 0;
39520 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
39521 + task->t.regs.edi);
39523 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39524 + pax_open_kernel();
39525 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
39526 + pax_close_kernel();
39528 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
39529 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
39531 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
39532 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
39535 printk(KERN_INFO "uvesafb: protected mode interface info at "
39537 (u16)task->t.regs.es, (u16)task->t.regs.edi);
39538 @@ -1821,6 +1844,11 @@ out:
39539 if (par->vbe_modes)
39540 kfree(par->vbe_modes);
39542 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39543 + if (par->pmi_code)
39544 + module_free_exec(NULL, par->pmi_code);
39547 framebuffer_release(info);
39550 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
39551 kfree(par->vbe_state_orig);
39552 if (par->vbe_state_saved)
39553 kfree(par->vbe_state_saved);
39555 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39556 + if (par->pmi_code)
39557 + module_free_exec(NULL, par->pmi_code);
39562 framebuffer_release(info);
39563 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
39564 index 501b340..86bd4cf 100644
39565 --- a/drivers/video/vesafb.c
39566 +++ b/drivers/video/vesafb.c
39570 #include <linux/module.h>
39571 +#include <linux/moduleloader.h>
39572 #include <linux/kernel.h>
39573 #include <linux/errno.h>
39574 #include <linux/string.h>
39575 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
39576 static int vram_total __initdata; /* Set total amount of memory */
39577 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
39578 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
39579 -static void (*pmi_start)(void) __read_mostly;
39580 -static void (*pmi_pal) (void) __read_mostly;
39581 +static void (*pmi_start)(void) __read_only;
39582 +static void (*pmi_pal) (void) __read_only;
39583 static int depth __read_mostly;
39584 static int vga_compat __read_mostly;
39585 /* --------------------------------------------------------------------- */
39586 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
39587 unsigned int size_vmode;
39588 unsigned int size_remap;
39589 unsigned int size_total;
39590 + void *pmi_code = NULL;
39592 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
39594 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
39595 size_remap = size_total;
39596 vesafb_fix.smem_len = size_remap;
39599 - screen_info.vesapm_seg = 0;
39602 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
39603 printk(KERN_WARNING
39604 "vesafb: cannot reserve video memory at 0x%lx\n",
39605 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
39606 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
39607 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
39611 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39612 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
39614 +#elif !defined(CONFIG_PAX_KERNEXEC)
39619 + screen_info.vesapm_seg = 0;
39621 if (screen_info.vesapm_seg) {
39622 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
39623 - screen_info.vesapm_seg,screen_info.vesapm_off);
39624 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
39625 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
39628 if (screen_info.vesapm_seg < 0xc000)
39629 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
39631 if (ypan || pmi_setpal) {
39632 unsigned short *pmi_base;
39634 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
39635 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
39636 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
39638 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39639 + pax_open_kernel();
39640 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
39642 + pmi_code = pmi_base;
39645 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
39646 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
39648 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39649 + pmi_start = ktva_ktla(pmi_start);
39650 + pmi_pal = ktva_ktla(pmi_pal);
39651 + pax_close_kernel();
39654 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
39656 printk(KERN_INFO "vesafb: pmi: ports = ");
39657 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
39658 info->node, info->fix.id);
39662 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39663 + module_free_exec(NULL, pmi_code);
39666 if (info->screen_base)
39667 iounmap(info->screen_base);
39668 framebuffer_release(info);
39669 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
39670 index 88714ae..16c2e11 100644
39671 --- a/drivers/video/via/via_clock.h
39672 +++ b/drivers/video/via/via_clock.h
39673 @@ -56,7 +56,7 @@ struct via_clock {
39675 void (*set_engine_pll_state)(u8 state);
39676 void (*set_engine_pll)(struct via_pll_config config);
39681 static inline u32 get_pll_internal_frequency(u32 ref_freq,
39682 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
39683 index e56c934..fc22f4b 100644
39684 --- a/drivers/xen/xen-pciback/conf_space.h
39685 +++ b/drivers/xen/xen-pciback/conf_space.h
39686 @@ -44,15 +44,15 @@ struct config_field {
39688 conf_dword_write write;
39689 conf_dword_read read;
39693 conf_word_write write;
39694 conf_word_read read;
39698 conf_byte_write write;
39699 conf_byte_read read;
39703 struct list_head list;
39705 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
39706 index 879ed88..bc03a01 100644
39707 --- a/fs/9p/vfs_inode.c
39708 +++ b/fs/9p/vfs_inode.c
39709 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
39711 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39713 - char *s = nd_get_link(nd);
39714 + const char *s = nd_get_link(nd);
39716 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
39717 IS_ERR(s) ? "<error>" : s);
39718 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
39719 index 79e2ca7..5828ad1 100644
39720 --- a/fs/Kconfig.binfmt
39721 +++ b/fs/Kconfig.binfmt
39722 @@ -86,7 +86,7 @@ config HAVE_AOUT
39725 tristate "Kernel support for a.out and ECOFF binaries"
39726 - depends on HAVE_AOUT
39727 + depends on HAVE_AOUT && BROKEN
39729 A.out (Assembler.OUTput) is a set of formats for libraries and
39730 executables used in the earliest versions of UNIX. Linux used
39731 diff --git a/fs/aio.c b/fs/aio.c
39732 index 969beb0..09fab51 100644
39735 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
39736 size += sizeof(struct io_event) * nr_events;
39737 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
39739 - if (nr_pages < 0)
39740 + if (nr_pages <= 0)
39743 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
39744 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
39745 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
39748 + struct iovec iovstack;
39750 #ifdef CONFIG_COMPAT
39752 ret = compat_rw_copy_check_uvector(type,
39753 (struct compat_iovec __user *)kiocb->ki_buf,
39754 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39755 + kiocb->ki_nbytes, 1, &iovstack,
39756 &kiocb->ki_iovec, 1);
39759 ret = rw_copy_check_uvector(type,
39760 (struct iovec __user *)kiocb->ki_buf,
39761 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39762 + kiocb->ki_nbytes, 1, &iovstack,
39763 &kiocb->ki_iovec, 1);
39767 + if (kiocb->ki_iovec == &iovstack) {
39768 + kiocb->ki_inline_vec = iovstack;
39769 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
39771 kiocb->ki_nr_segs = kiocb->ki_nbytes;
39772 kiocb->ki_cur_seg = 0;
39773 /* ki_nbytes/left now reflect bytes instead of segs */
39774 diff --git a/fs/attr.c b/fs/attr.c
39775 index 7ee7ba4..0c61a60 100644
39778 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
39779 unsigned long limit;
39781 limit = rlimit(RLIMIT_FSIZE);
39782 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
39783 if (limit != RLIM_INFINITY && offset > limit)
39785 if (offset > inode->i_sb->s_maxbytes)
39786 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
39787 index e1fbdee..cd5ea56 100644
39788 --- a/fs/autofs4/waitq.c
39789 +++ b/fs/autofs4/waitq.c
39790 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
39792 unsigned long sigpipe, flags;
39794 - const char *data = (const char *)addr;
39795 + const char __user *data = (const char __force_user *)addr;
39798 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
39799 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
39800 index 8342ca6..82fd192 100644
39801 --- a/fs/befs/linuxvfs.c
39802 +++ b/fs/befs/linuxvfs.c
39803 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39805 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
39806 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
39807 - char *link = nd_get_link(nd);
39808 + const char *link = nd_get_link(nd);
39812 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
39813 index a6395bd..f1e376a 100644
39814 --- a/fs/binfmt_aout.c
39815 +++ b/fs/binfmt_aout.c
39817 #include <linux/string.h>
39818 #include <linux/fs.h>
39819 #include <linux/file.h>
39820 +#include <linux/security.h>
39821 #include <linux/stat.h>
39822 #include <linux/fcntl.h>
39823 #include <linux/ptrace.h>
39824 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
39826 # define START_STACK(u) ((void __user *)u.start_stack)
39828 + memset(&dump, 0, sizeof(dump));
39833 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
39835 /* If the size of the dump file exceeds the rlimit, then see what would happen
39836 if we wrote the stack, but not the data area. */
39837 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
39838 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
39841 /* Make sure we have enough room to write the stack and data areas. */
39842 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
39843 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
39846 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39847 rlim = rlimit(RLIMIT_DATA);
39848 if (rlim >= RLIM_INFINITY)
39851 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
39852 if (ex.a_data + ex.a_bss > rlim)
39855 @@ -259,9 +266,37 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39856 current->mm->free_area_cache = current->mm->mmap_base;
39857 current->mm->cached_hole_size = 0;
39859 + retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
39860 + if (retval < 0) {
39861 + /* Someone check-me: is this error path enough? */
39862 + send_sig(SIGKILL, current, 0);
39866 install_exec_creds(bprm);
39867 current->flags &= ~PF_FORKNOEXEC;
39869 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39870 + current->mm->pax_flags = 0UL;
39873 +#ifdef CONFIG_PAX_PAGEEXEC
39874 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
39875 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
39877 +#ifdef CONFIG_PAX_EMUTRAMP
39878 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
39879 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
39882 +#ifdef CONFIG_PAX_MPROTECT
39883 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
39884 + current->mm->pax_flags |= MF_PAX_MPROTECT;
39890 if (N_MAGIC(ex) == OMAGIC) {
39891 unsigned long text_addr, map_size;
39893 @@ -334,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39895 down_write(¤t->mm->mmap_sem);
39896 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
39897 - PROT_READ | PROT_WRITE | PROT_EXEC,
39898 + PROT_READ | PROT_WRITE,
39899 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
39900 fd_offset + ex.a_text);
39901 up_write(¤t->mm->mmap_sem);
39902 @@ -352,13 +387,6 @@ beyond_if:
39906 - retval = setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
39907 - if (retval < 0) {
39908 - /* Someone check-me: is this error path enough? */
39909 - send_sig(SIGKILL, current, 0);
39913 current->mm->start_stack =
39914 (unsigned long) create_aout_tables((char __user *) bprm->p, bprm);
39916 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
39917 index 21ac5ee..dbf63ee 100644
39918 --- a/fs/binfmt_elf.c
39919 +++ b/fs/binfmt_elf.c
39921 #include <linux/elf.h>
39922 #include <linux/utsname.h>
39923 #include <linux/coredump.h>
39924 +#include <linux/xattr.h>
39925 #include <asm/uaccess.h>
39926 #include <asm/param.h>
39927 #include <asm/page.h>
39928 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
39929 #define elf_core_dump NULL
39932 +#ifdef CONFIG_PAX_MPROTECT
39933 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
39936 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
39937 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
39939 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
39940 .load_binary = load_elf_binary,
39941 .load_shlib = load_elf_library,
39942 .core_dump = elf_core_dump,
39944 +#ifdef CONFIG_PAX_MPROTECT
39945 + .handle_mprotect= elf_handle_mprotect,
39948 .min_coredump = ELF_EXEC_PAGESIZE,
39951 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
39953 static int set_brk(unsigned long start, unsigned long end)
39955 + unsigned long e = end;
39957 start = ELF_PAGEALIGN(start);
39958 end = ELF_PAGEALIGN(end);
39960 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
39961 if (BAD_ADDR(addr))
39964 - current->mm->start_brk = current->mm->brk = end;
39965 + current->mm->start_brk = current->mm->brk = e;
39969 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39970 elf_addr_t __user *u_rand_bytes;
39971 const char *k_platform = ELF_PLATFORM;
39972 const char *k_base_platform = ELF_BASE_PLATFORM;
39973 - unsigned char k_rand_bytes[16];
39974 + u32 k_rand_bytes[4];
39976 elf_addr_t *elf_info;
39978 const struct cred *cred = current_cred();
39979 struct vm_area_struct *vma;
39980 + unsigned long saved_auxv[AT_VECTOR_SIZE];
39983 * In some cases (e.g. Hyper-Threading), we want to avoid L1
39984 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39985 * Generate 16 random bytes for userspace PRNG seeding.
39987 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
39988 - u_rand_bytes = (elf_addr_t __user *)
39989 - STACK_ALLOC(p, sizeof(k_rand_bytes));
39990 + srandom32(k_rand_bytes[0] ^ random32());
39991 + srandom32(k_rand_bytes[1] ^ random32());
39992 + srandom32(k_rand_bytes[2] ^ random32());
39993 + srandom32(k_rand_bytes[3] ^ random32());
39994 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
39995 + u_rand_bytes = (elf_addr_t __user *) p;
39996 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
39999 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
40001 current->mm->env_end = p;
40003 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
40005 /* Put the elf_info on the stack in the right place. */
40006 sp = (elf_addr_t __user *)envp + 1;
40007 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
40008 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
40012 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
40014 struct elf_phdr *elf_phdata;
40015 struct elf_phdr *eppnt;
40016 - unsigned long load_addr = 0;
40017 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
40018 int load_addr_set = 0;
40019 unsigned long last_bss = 0, elf_bss = 0;
40020 - unsigned long error = ~0UL;
40021 + unsigned long error = -EINVAL;
40022 unsigned long total_size;
40023 int retval, i, size;
40025 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
40029 +#ifdef CONFIG_PAX_SEGMEXEC
40030 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
40031 + pax_task_size = SEGMEXEC_TASK_SIZE;
40034 eppnt = elf_phdata;
40035 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
40036 if (eppnt->p_type == PT_LOAD) {
40037 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
40038 k = load_addr + eppnt->p_vaddr;
40040 eppnt->p_filesz > eppnt->p_memsz ||
40041 - eppnt->p_memsz > TASK_SIZE ||
40042 - TASK_SIZE - eppnt->p_memsz < k) {
40043 + eppnt->p_memsz > pax_task_size ||
40044 + pax_task_size - eppnt->p_memsz < k) {
40048 @@ -528,6 +552,351 @@ out:
40052 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40053 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
40055 + unsigned long pax_flags = 0UL;
40057 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
40059 +#ifdef CONFIG_PAX_PAGEEXEC
40060 + if (elf_phdata->p_flags & PF_PAGEEXEC)
40061 + pax_flags |= MF_PAX_PAGEEXEC;
40064 +#ifdef CONFIG_PAX_SEGMEXEC
40065 + if (elf_phdata->p_flags & PF_SEGMEXEC)
40066 + pax_flags |= MF_PAX_SEGMEXEC;
40069 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40070 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40071 + if ((__supported_pte_mask & _PAGE_NX))
40072 + pax_flags &= ~MF_PAX_SEGMEXEC;
40074 + pax_flags &= ~MF_PAX_PAGEEXEC;
40078 +#ifdef CONFIG_PAX_EMUTRAMP
40079 + if (elf_phdata->p_flags & PF_EMUTRAMP)
40080 + pax_flags |= MF_PAX_EMUTRAMP;
40083 +#ifdef CONFIG_PAX_MPROTECT
40084 + if (elf_phdata->p_flags & PF_MPROTECT)
40085 + pax_flags |= MF_PAX_MPROTECT;
40088 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40089 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
40090 + pax_flags |= MF_PAX_RANDMMAP;
40095 + return pax_flags;
40098 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
40100 + unsigned long pax_flags = 0UL;
40102 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
40104 +#ifdef CONFIG_PAX_PAGEEXEC
40105 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
40106 + pax_flags |= MF_PAX_PAGEEXEC;
40109 +#ifdef CONFIG_PAX_SEGMEXEC
40110 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
40111 + pax_flags |= MF_PAX_SEGMEXEC;
40114 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40115 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40116 + if ((__supported_pte_mask & _PAGE_NX))
40117 + pax_flags &= ~MF_PAX_SEGMEXEC;
40119 + pax_flags &= ~MF_PAX_PAGEEXEC;
40123 +#ifdef CONFIG_PAX_EMUTRAMP
40124 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
40125 + pax_flags |= MF_PAX_EMUTRAMP;
40128 +#ifdef CONFIG_PAX_MPROTECT
40129 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
40130 + pax_flags |= MF_PAX_MPROTECT;
40133 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40134 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
40135 + pax_flags |= MF_PAX_RANDMMAP;
40140 + return pax_flags;
40143 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
40145 + unsigned long pax_flags = 0UL;
40147 +#ifdef CONFIG_PAX_EI_PAX
40149 +#ifdef CONFIG_PAX_PAGEEXEC
40150 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
40151 + pax_flags |= MF_PAX_PAGEEXEC;
40154 +#ifdef CONFIG_PAX_SEGMEXEC
40155 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
40156 + pax_flags |= MF_PAX_SEGMEXEC;
40159 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40160 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40161 + if ((__supported_pte_mask & _PAGE_NX))
40162 + pax_flags &= ~MF_PAX_SEGMEXEC;
40164 + pax_flags &= ~MF_PAX_PAGEEXEC;
40168 +#ifdef CONFIG_PAX_EMUTRAMP
40169 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
40170 + pax_flags |= MF_PAX_EMUTRAMP;
40173 +#ifdef CONFIG_PAX_MPROTECT
40174 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
40175 + pax_flags |= MF_PAX_MPROTECT;
40178 +#ifdef CONFIG_PAX_ASLR
40179 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
40180 + pax_flags |= MF_PAX_RANDMMAP;
40185 +#ifdef CONFIG_PAX_PAGEEXEC
40186 + pax_flags |= MF_PAX_PAGEEXEC;
40189 +#ifdef CONFIG_PAX_MPROTECT
40190 + pax_flags |= MF_PAX_MPROTECT;
40193 +#ifdef CONFIG_PAX_RANDMMAP
40194 + pax_flags |= MF_PAX_RANDMMAP;
40197 +#ifdef CONFIG_PAX_SEGMEXEC
40198 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
40199 + pax_flags &= ~MF_PAX_PAGEEXEC;
40200 + pax_flags |= MF_PAX_SEGMEXEC;
40206 + return pax_flags;
40209 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
40212 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
40215 + for (i = 0UL; i < elf_ex->e_phnum; i++)
40216 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
40217 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
40218 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
40219 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
40220 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
40221 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
40224 +#ifdef CONFIG_PAX_SOFTMODE
40225 + if (pax_softmode)
40226 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
40230 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
40238 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
40239 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
40241 + unsigned long pax_flags = 0UL;
40243 +#ifdef CONFIG_PAX_PAGEEXEC
40244 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
40245 + pax_flags |= MF_PAX_PAGEEXEC;
40248 +#ifdef CONFIG_PAX_SEGMEXEC
40249 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
40250 + pax_flags |= MF_PAX_SEGMEXEC;
40253 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40254 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40255 + if ((__supported_pte_mask & _PAGE_NX))
40256 + pax_flags &= ~MF_PAX_SEGMEXEC;
40258 + pax_flags &= ~MF_PAX_PAGEEXEC;
40262 +#ifdef CONFIG_PAX_EMUTRAMP
40263 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
40264 + pax_flags |= MF_PAX_EMUTRAMP;
40267 +#ifdef CONFIG_PAX_MPROTECT
40268 + if (pax_flags_softmode & MF_PAX_MPROTECT)
40269 + pax_flags |= MF_PAX_MPROTECT;
40272 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40273 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
40274 + pax_flags |= MF_PAX_RANDMMAP;
40277 + return pax_flags;
40280 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
40282 + unsigned long pax_flags = 0UL;
40284 +#ifdef CONFIG_PAX_PAGEEXEC
40285 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
40286 + pax_flags |= MF_PAX_PAGEEXEC;
40289 +#ifdef CONFIG_PAX_SEGMEXEC
40290 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
40291 + pax_flags |= MF_PAX_SEGMEXEC;
40294 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40295 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40296 + if ((__supported_pte_mask & _PAGE_NX))
40297 + pax_flags &= ~MF_PAX_SEGMEXEC;
40299 + pax_flags &= ~MF_PAX_PAGEEXEC;
40303 +#ifdef CONFIG_PAX_EMUTRAMP
40304 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
40305 + pax_flags |= MF_PAX_EMUTRAMP;
40308 +#ifdef CONFIG_PAX_MPROTECT
40309 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
40310 + pax_flags |= MF_PAX_MPROTECT;
40313 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40314 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
40315 + pax_flags |= MF_PAX_RANDMMAP;
40318 + return pax_flags;
40322 +static unsigned long pax_parse_xattr_pax(struct file * const file)
40325 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
40326 + ssize_t xattr_size, i;
40327 + unsigned char xattr_value[5];
40328 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
40330 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
40331 + if (xattr_size <= 0)
40334 + for (i = 0; i < xattr_size; i++)
40335 + switch (xattr_value[i]) {
40339 +#define parse_flag(option1, option2, flag) \
40341 + pax_flags_hardmode |= MF_PAX_##flag; \
40344 + pax_flags_softmode |= MF_PAX_##flag; \
40347 + parse_flag('p', 'P', PAGEEXEC);
40348 + parse_flag('e', 'E', EMUTRAMP);
40349 + parse_flag('m', 'M', MPROTECT);
40350 + parse_flag('r', 'R', RANDMMAP);
40351 + parse_flag('s', 'S', SEGMEXEC);
40356 + if (pax_flags_hardmode & pax_flags_softmode)
40359 +#ifdef CONFIG_PAX_SOFTMODE
40360 + if (pax_softmode)
40361 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
40365 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
40372 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
40374 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
40376 + pax_flags = pax_parse_ei_pax(elf_ex);
40377 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
40378 + xattr_pax_flags = pax_parse_xattr_pax(file);
40380 + if (pt_pax_flags == ~0UL)
40381 + pt_pax_flags = xattr_pax_flags;
40382 + else if (xattr_pax_flags == ~0UL)
40383 + xattr_pax_flags = pt_pax_flags;
40384 + if (pt_pax_flags != xattr_pax_flags)
40386 + if (pt_pax_flags != ~0UL)
40387 + pax_flags = pt_pax_flags;
40389 + if (0 > pax_check_flags(&pax_flags))
40392 + current->mm->pax_flags = pax_flags;
40398 * These are the functions used to load ELF style executables and shared
40399 * libraries. There is no binary dependent code anywhere else.
40400 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
40402 unsigned int random_variable = 0;
40404 +#ifdef CONFIG_PAX_RANDUSTACK
40405 + if (randomize_va_space)
40406 + return stack_top - current->mm->delta_stack;
40409 if ((current->flags & PF_RANDOMIZE) &&
40410 !(current->personality & ADDR_NO_RANDOMIZE)) {
40411 random_variable = get_random_int() & STACK_RND_MASK;
40412 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40413 unsigned long load_addr = 0, load_bias = 0;
40414 int load_addr_set = 0;
40415 char * elf_interpreter = NULL;
40416 - unsigned long error;
40417 + unsigned long error = 0;
40418 struct elf_phdr *elf_ppnt, *elf_phdata;
40419 unsigned long elf_bss, elf_brk;
40421 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40422 unsigned long start_code, end_code, start_data, end_data;
40423 unsigned long reloc_func_desc __maybe_unused = 0;
40424 int executable_stack = EXSTACK_DEFAULT;
40425 - unsigned long def_flags = 0;
40427 struct elfhdr elf_ex;
40428 struct elfhdr interp_elf_ex;
40430 + unsigned long pax_task_size = TASK_SIZE;
40432 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
40434 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40436 /* OK, This is the point of no return */
40437 current->flags &= ~PF_FORKNOEXEC;
40438 - current->mm->def_flags = def_flags;
40440 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40441 + current->mm->pax_flags = 0UL;
40444 +#ifdef CONFIG_PAX_DLRESOLVE
40445 + current->mm->call_dl_resolve = 0UL;
40448 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
40449 + current->mm->call_syscall = 0UL;
40452 +#ifdef CONFIG_PAX_ASLR
40453 + current->mm->delta_mmap = 0UL;
40454 + current->mm->delta_stack = 0UL;
40457 + current->mm->def_flags = 0;
40459 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40460 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
40461 + send_sig(SIGKILL, current, 0);
40462 + goto out_free_dentry;
40466 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
40467 + pax_set_initial_flags(bprm);
40468 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
40469 + if (pax_set_initial_flags_func)
40470 + (pax_set_initial_flags_func)(bprm);
40473 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
40474 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
40475 + current->mm->context.user_cs_limit = PAGE_SIZE;
40476 + current->mm->def_flags |= VM_PAGEEXEC;
40480 +#ifdef CONFIG_PAX_SEGMEXEC
40481 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
40482 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
40483 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
40484 + pax_task_size = SEGMEXEC_TASK_SIZE;
40485 + current->mm->def_flags |= VM_NOHUGEPAGE;
40489 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
40490 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40491 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
40496 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
40497 may depend on the personality. */
40498 SET_PERSONALITY(loc->elf_ex);
40500 +#ifdef CONFIG_PAX_ASLR
40501 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
40502 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
40503 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
40507 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
40508 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40509 + executable_stack = EXSTACK_DISABLE_X;
40510 + current->personality &= ~READ_IMPLIES_EXEC;
40514 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
40515 current->personality |= READ_IMPLIES_EXEC;
40517 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40519 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
40522 +#ifdef CONFIG_PAX_RANDMMAP
40523 + /* PaX: randomize base address at the default exe base if requested */
40524 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
40525 +#ifdef CONFIG_SPARC64
40526 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
40528 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
40530 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
40531 + elf_flags |= MAP_FIXED;
40537 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
40538 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40539 * allowed task size. Note that p_filesz must always be
40540 * <= p_memsz so it is only necessary to check p_memsz.
40542 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40543 - elf_ppnt->p_memsz > TASK_SIZE ||
40544 - TASK_SIZE - elf_ppnt->p_memsz < k) {
40545 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40546 + elf_ppnt->p_memsz > pax_task_size ||
40547 + pax_task_size - elf_ppnt->p_memsz < k) {
40548 /* set_brk can never work. Avoid overflows. */
40549 send_sig(SIGKILL, current, 0);
40551 @@ -870,6 +1328,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40552 start_data += load_bias;
40553 end_data += load_bias;
40555 +#ifdef CONFIG_PAX_RANDMMAP
40556 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
40557 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
40560 /* Calling set_brk effectively mmaps the pages that we need
40561 * for the bss and break sections. We must do this before
40562 * mapping in the interpreter, to make sure it doesn't wind
40563 @@ -881,9 +1344,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40564 goto out_free_dentry;
40566 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
40567 - send_sig(SIGSEGV, current, 0);
40568 - retval = -EFAULT; /* Nobody gets to see this, but.. */
40569 - goto out_free_dentry;
40571 + * This bss-zeroing can fail if the ELF
40572 + * file specifies odd protections. So
40573 + * we don't check the return value
40577 if (elf_interpreter) {
40578 @@ -1098,7 +1563,7 @@ out:
40579 * Decide what to dump of a segment, part, all or none.
40581 static unsigned long vma_dump_size(struct vm_area_struct *vma,
40582 - unsigned long mm_flags)
40583 + unsigned long mm_flags, long signr)
40585 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
40587 @@ -1132,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
40588 if (vma->vm_file == NULL)
40591 - if (FILTER(MAPPED_PRIVATE))
40592 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
40596 @@ -1354,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
40598 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
40603 - while (auxv[i - 2] != AT_NULL);
40604 + } while (auxv[i - 2] != AT_NULL);
40605 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
40608 @@ -1421,7 +1886,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
40609 for (i = 1; i < view->n; ++i) {
40610 const struct user_regset *regset = &view->regsets[i];
40611 do_thread_regset_writeback(t->task, regset);
40612 - if (regset->core_note_type &&
40613 + if (regset->core_note_type && regset->get &&
40614 (!regset->active || regset->active(t->task, regset))) {
40616 size_t size = regset->n * regset->size;
40617 @@ -1862,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
40620 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
40621 - unsigned long mm_flags)
40622 + struct coredump_params *cprm)
40624 struct vm_area_struct *vma;
40627 for (vma = first_vma(current, gate_vma); vma != NULL;
40628 vma = next_vma(vma, gate_vma))
40629 - size += vma_dump_size(vma, mm_flags);
40630 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40634 @@ -1963,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40636 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
40638 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
40639 + offset += elf_core_vma_data_size(gate_vma, cprm);
40640 offset += elf_core_extra_data_size();
40643 @@ -1977,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
40646 size += sizeof(*elf);
40647 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40648 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
40651 size += sizeof(*phdr4note);
40652 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40653 if (size > cprm->limit
40654 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
40656 @@ -1994,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40657 phdr.p_offset = offset;
40658 phdr.p_vaddr = vma->vm_start;
40660 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
40661 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40662 phdr.p_memsz = vma->vm_end - vma->vm_start;
40663 offset += phdr.p_filesz;
40664 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
40665 @@ -2005,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40666 phdr.p_align = ELF_EXEC_PAGESIZE;
40668 size += sizeof(phdr);
40669 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40670 if (size > cprm->limit
40671 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
40673 @@ -2029,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40674 unsigned long addr;
40677 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
40678 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40680 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
40682 @@ -2038,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40683 page = get_dump_page(addr);
40685 void *kaddr = kmap(page);
40686 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
40687 stop = ((size += PAGE_SIZE) > cprm->limit) ||
40688 !dump_write(cprm->file, kaddr,
40690 @@ -2055,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40692 if (e_phnum == PN_XNUM) {
40693 size += sizeof(*shdr4extnum);
40694 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40695 if (size > cprm->limit
40696 || !dump_write(cprm->file, shdr4extnum,
40697 sizeof(*shdr4extnum)))
40698 @@ -2075,6 +2545,97 @@ out:
40700 #endif /* CONFIG_ELF_CORE */
40702 +#ifdef CONFIG_PAX_MPROTECT
40703 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
40704 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
40705 + * we'll remove VM_MAYWRITE for good on RELRO segments.
40707 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
40708 + * basis because we want to allow the common case and not the special ones.
40710 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
40712 + struct elfhdr elf_h;
40713 + struct elf_phdr elf_p;
40715 + unsigned long oldflags;
40716 + bool is_textrel_rw, is_textrel_rx, is_relro;
40718 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
40721 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
40722 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
40724 +#ifdef CONFIG_PAX_ELFRELOCS
40725 + /* possible TEXTREL */
40726 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
40727 + 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);
40729 + is_textrel_rw = false;
40730 + is_textrel_rx = false;
40733 + /* possible RELRO */
40734 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
40736 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
40739 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
40740 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
40742 +#ifdef CONFIG_PAX_ETEXECRELOCS
40743 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40745 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
40748 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40749 + !elf_check_arch(&elf_h) ||
40750 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
40751 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
40754 + for (i = 0UL; i < elf_h.e_phnum; i++) {
40755 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
40757 + switch (elf_p.p_type) {
40759 + if (!is_textrel_rw && !is_textrel_rx)
40762 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
40765 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
40767 + if (dyn.d_tag == DT_NULL)
40769 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
40770 + gr_log_textrel(vma);
40771 + if (is_textrel_rw)
40772 + vma->vm_flags |= VM_MAYWRITE;
40774 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
40775 + vma->vm_flags &= ~VM_MAYWRITE;
40782 + case PT_GNU_RELRO:
40785 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
40786 + vma->vm_flags &= ~VM_MAYWRITE;
40793 static int __init init_elf_binfmt(void)
40795 return register_binfmt(&elf_format);
40796 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
40797 index 1bffbe0..c8c283e 100644
40798 --- a/fs/binfmt_flat.c
40799 +++ b/fs/binfmt_flat.c
40800 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
40801 realdatastart = (unsigned long) -ENOMEM;
40802 printk("Unable to allocate RAM for process data, errno %d\n",
40803 (int)-realdatastart);
40804 + down_write(¤t->mm->mmap_sem);
40805 do_munmap(current->mm, textpos, text_len);
40806 + up_write(¤t->mm->mmap_sem);
40807 ret = realdatastart;
40810 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40812 if (IS_ERR_VALUE(result)) {
40813 printk("Unable to read data+bss, errno %d\n", (int)-result);
40814 + down_write(¤t->mm->mmap_sem);
40815 do_munmap(current->mm, textpos, text_len);
40816 do_munmap(current->mm, realdatastart, len);
40817 + up_write(¤t->mm->mmap_sem);
40821 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40823 if (IS_ERR_VALUE(result)) {
40824 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
40825 + down_write(¤t->mm->mmap_sem);
40826 do_munmap(current->mm, textpos, text_len + data_len + extra +
40827 MAX_SHARED_LIBS * sizeof(unsigned long));
40828 + up_write(¤t->mm->mmap_sem);
40832 diff --git a/fs/bio.c b/fs/bio.c
40833 index b1fe82c..84da0a9 100644
40836 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
40837 const int read = bio_data_dir(bio) == READ;
40838 struct bio_map_data *bmd = bio->bi_private;
40840 - char *p = bmd->sgvecs[0].iov_base;
40841 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
40843 __bio_for_each_segment(bvec, bio, i, 0) {
40844 char *addr = page_address(bvec->bv_page);
40845 diff --git a/fs/block_dev.c b/fs/block_dev.c
40846 index b07f1da..9efcb92 100644
40847 --- a/fs/block_dev.c
40848 +++ b/fs/block_dev.c
40849 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
40850 else if (bdev->bd_contains == bdev)
40851 return true; /* is a whole device which isn't held */
40853 - else if (whole->bd_holder == bd_may_claim)
40854 + else if (whole->bd_holder == (void *)bd_may_claim)
40855 return true; /* is a partition of a device that is being partitioned */
40856 else if (whole->bd_holder != NULL)
40857 return false; /* is a partition of a held device */
40858 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
40859 index dede441..f2a2507 100644
40860 --- a/fs/btrfs/ctree.c
40861 +++ b/fs/btrfs/ctree.c
40862 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
40863 free_extent_buffer(buf);
40864 add_root_to_dirty_list(root);
40866 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
40867 - parent_start = parent->start;
40869 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
40871 + parent_start = parent->start;
40873 + parent_start = 0;
40877 WARN_ON(trans->transid != btrfs_header_generation(parent));
40878 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
40879 index fd1a06d..6e9033d 100644
40880 --- a/fs/btrfs/inode.c
40881 +++ b/fs/btrfs/inode.c
40882 @@ -6895,7 +6895,7 @@ fail:
40886 -static int btrfs_getattr(struct vfsmount *mnt,
40887 +int btrfs_getattr(struct vfsmount *mnt,
40888 struct dentry *dentry, struct kstat *stat)
40890 struct inode *inode = dentry->d_inode;
40891 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
40895 +EXPORT_SYMBOL(btrfs_getattr);
40897 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
40899 + return BTRFS_I(inode)->root->anon_dev;
40901 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
40904 * If a file is moved, it will inherit the cow and compression flags of the new
40906 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
40907 index c04f02c..f5c9e2e 100644
40908 --- a/fs/btrfs/ioctl.c
40909 +++ b/fs/btrfs/ioctl.c
40910 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40911 for (i = 0; i < num_types; i++) {
40912 struct btrfs_space_info *tmp;
40914 + /* Don't copy in more than we allocated */
40922 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
40923 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40924 memcpy(dest, &space, sizeof(space));
40926 space_args.total_spaces++;
40932 up_read(&info->groups_sem);
40935 - user_dest = (struct btrfs_ioctl_space_info *)
40936 + user_dest = (struct btrfs_ioctl_space_info __user *)
40937 (arg + sizeof(struct btrfs_ioctl_space_args));
40939 if (copy_to_user(user_dest, dest_orig, alloc_size))
40940 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
40941 index cfb5543..1ae7347 100644
40942 --- a/fs/btrfs/relocation.c
40943 +++ b/fs/btrfs/relocation.c
40944 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
40946 spin_unlock(&rc->reloc_root_tree.lock);
40948 - BUG_ON((struct btrfs_root *)node->data != root);
40949 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
40952 spin_lock(&rc->reloc_root_tree.lock);
40953 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
40954 index 622f469..e8d2d55 100644
40955 --- a/fs/cachefiles/bind.c
40956 +++ b/fs/cachefiles/bind.c
40957 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
40960 /* start by checking things over */
40961 - ASSERT(cache->fstop_percent >= 0 &&
40962 - cache->fstop_percent < cache->fcull_percent &&
40963 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
40964 cache->fcull_percent < cache->frun_percent &&
40965 cache->frun_percent < 100);
40967 - ASSERT(cache->bstop_percent >= 0 &&
40968 - cache->bstop_percent < cache->bcull_percent &&
40969 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
40970 cache->bcull_percent < cache->brun_percent &&
40971 cache->brun_percent < 100);
40973 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
40974 index 0a1467b..6a53245 100644
40975 --- a/fs/cachefiles/daemon.c
40976 +++ b/fs/cachefiles/daemon.c
40977 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
40981 - if (copy_to_user(_buffer, buffer, n) != 0)
40982 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
40986 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
40987 if (test_bit(CACHEFILES_DEAD, &cache->flags))
40990 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
40991 + if (datalen > PAGE_SIZE - 1)
40992 return -EOPNOTSUPP;
40994 /* drag the command string into the kernel so we can parse it */
40995 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
40996 if (args[0] != '%' || args[1] != '\0')
40999 - if (fstop < 0 || fstop >= cache->fcull_percent)
41000 + if (fstop >= cache->fcull_percent)
41001 return cachefiles_daemon_range_error(cache, args);
41003 cache->fstop_percent = fstop;
41004 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
41005 if (args[0] != '%' || args[1] != '\0')
41008 - if (bstop < 0 || bstop >= cache->bcull_percent)
41009 + if (bstop >= cache->bcull_percent)
41010 return cachefiles_daemon_range_error(cache, args);
41012 cache->bstop_percent = bstop;
41013 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
41014 index bd6bc1b..b627b53 100644
41015 --- a/fs/cachefiles/internal.h
41016 +++ b/fs/cachefiles/internal.h
41017 @@ -57,7 +57,7 @@ struct cachefiles_cache {
41018 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
41019 struct rb_root active_nodes; /* active nodes (can't be culled) */
41020 rwlock_t active_lock; /* lock for active_nodes */
41021 - atomic_t gravecounter; /* graveyard uniquifier */
41022 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
41023 unsigned frun_percent; /* when to stop culling (% files) */
41024 unsigned fcull_percent; /* when to start culling (% files) */
41025 unsigned fstop_percent; /* when to stop allocating (% files) */
41026 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
41029 #ifdef CONFIG_CACHEFILES_HISTOGRAM
41030 -extern atomic_t cachefiles_lookup_histogram[HZ];
41031 -extern atomic_t cachefiles_mkdir_histogram[HZ];
41032 -extern atomic_t cachefiles_create_histogram[HZ];
41033 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
41034 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
41035 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
41037 extern int __init cachefiles_proc_init(void);
41038 extern void cachefiles_proc_cleanup(void);
41040 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
41041 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
41043 unsigned long jif = jiffies - start_jif;
41046 - atomic_inc(&histogram[jif]);
41047 + atomic_inc_unchecked(&histogram[jif]);
41051 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
41052 index a0358c2..d6137f2 100644
41053 --- a/fs/cachefiles/namei.c
41054 +++ b/fs/cachefiles/namei.c
41055 @@ -318,7 +318,7 @@ try_again:
41056 /* first step is to make up a grave dentry in the graveyard */
41057 sprintf(nbuffer, "%08x%08x",
41058 (uint32_t) get_seconds(),
41059 - (uint32_t) atomic_inc_return(&cache->gravecounter));
41060 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
41062 /* do the multiway lock magic */
41063 trap = lock_rename(cache->graveyard, dir);
41064 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
41065 index eccd339..4c1d995 100644
41066 --- a/fs/cachefiles/proc.c
41067 +++ b/fs/cachefiles/proc.c
41069 #include <linux/seq_file.h>
41070 #include "internal.h"
41072 -atomic_t cachefiles_lookup_histogram[HZ];
41073 -atomic_t cachefiles_mkdir_histogram[HZ];
41074 -atomic_t cachefiles_create_histogram[HZ];
41075 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
41076 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
41077 +atomic_unchecked_t cachefiles_create_histogram[HZ];
41080 * display the latency histogram
41081 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
41084 index = (unsigned long) v - 3;
41085 - x = atomic_read(&cachefiles_lookup_histogram[index]);
41086 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
41087 - z = atomic_read(&cachefiles_create_histogram[index]);
41088 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
41089 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
41090 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
41091 if (x == 0 && y == 0 && z == 0)
41094 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
41095 index 0e3c092..818480e 100644
41096 --- a/fs/cachefiles/rdwr.c
41097 +++ b/fs/cachefiles/rdwr.c
41098 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
41101 ret = file->f_op->write(
41102 - file, (const void __user *) data, len, &pos);
41103 + file, (const void __force_user *) data, len, &pos);
41107 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
41108 index 9895400..fa40a7d 100644
41109 --- a/fs/ceph/dir.c
41110 +++ b/fs/ceph/dir.c
41111 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
41112 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
41113 struct ceph_mds_client *mdsc = fsc->mdsc;
41114 unsigned frag = fpos_frag(filp->f_pos);
41115 - int off = fpos_off(filp->f_pos);
41116 + unsigned int off = fpos_off(filp->f_pos);
41119 struct ceph_mds_reply_info_parsed *rinfo;
41120 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
41121 index 84e8c07..6170d31 100644
41122 --- a/fs/cifs/cifs_debug.c
41123 +++ b/fs/cifs/cifs_debug.c
41124 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
41126 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
41127 #ifdef CONFIG_CIFS_STATS2
41128 - atomic_set(&totBufAllocCount, 0);
41129 - atomic_set(&totSmBufAllocCount, 0);
41130 + atomic_set_unchecked(&totBufAllocCount, 0);
41131 + atomic_set_unchecked(&totSmBufAllocCount, 0);
41132 #endif /* CONFIG_CIFS_STATS2 */
41133 spin_lock(&cifs_tcp_ses_lock);
41134 list_for_each(tmp1, &cifs_tcp_ses_list) {
41135 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
41136 tcon = list_entry(tmp3,
41139 - atomic_set(&tcon->num_smbs_sent, 0);
41140 - atomic_set(&tcon->num_writes, 0);
41141 - atomic_set(&tcon->num_reads, 0);
41142 - atomic_set(&tcon->num_oplock_brks, 0);
41143 - atomic_set(&tcon->num_opens, 0);
41144 - atomic_set(&tcon->num_posixopens, 0);
41145 - atomic_set(&tcon->num_posixmkdirs, 0);
41146 - atomic_set(&tcon->num_closes, 0);
41147 - atomic_set(&tcon->num_deletes, 0);
41148 - atomic_set(&tcon->num_mkdirs, 0);
41149 - atomic_set(&tcon->num_rmdirs, 0);
41150 - atomic_set(&tcon->num_renames, 0);
41151 - atomic_set(&tcon->num_t2renames, 0);
41152 - atomic_set(&tcon->num_ffirst, 0);
41153 - atomic_set(&tcon->num_fnext, 0);
41154 - atomic_set(&tcon->num_fclose, 0);
41155 - atomic_set(&tcon->num_hardlinks, 0);
41156 - atomic_set(&tcon->num_symlinks, 0);
41157 - atomic_set(&tcon->num_locks, 0);
41158 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
41159 + atomic_set_unchecked(&tcon->num_writes, 0);
41160 + atomic_set_unchecked(&tcon->num_reads, 0);
41161 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
41162 + atomic_set_unchecked(&tcon->num_opens, 0);
41163 + atomic_set_unchecked(&tcon->num_posixopens, 0);
41164 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
41165 + atomic_set_unchecked(&tcon->num_closes, 0);
41166 + atomic_set_unchecked(&tcon->num_deletes, 0);
41167 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
41168 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
41169 + atomic_set_unchecked(&tcon->num_renames, 0);
41170 + atomic_set_unchecked(&tcon->num_t2renames, 0);
41171 + atomic_set_unchecked(&tcon->num_ffirst, 0);
41172 + atomic_set_unchecked(&tcon->num_fnext, 0);
41173 + atomic_set_unchecked(&tcon->num_fclose, 0);
41174 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
41175 + atomic_set_unchecked(&tcon->num_symlinks, 0);
41176 + atomic_set_unchecked(&tcon->num_locks, 0);
41180 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
41181 smBufAllocCount.counter, cifs_min_small);
41182 #ifdef CONFIG_CIFS_STATS2
41183 seq_printf(m, "Total Large %d Small %d Allocations\n",
41184 - atomic_read(&totBufAllocCount),
41185 - atomic_read(&totSmBufAllocCount));
41186 + atomic_read_unchecked(&totBufAllocCount),
41187 + atomic_read_unchecked(&totSmBufAllocCount));
41188 #endif /* CONFIG_CIFS_STATS2 */
41190 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
41191 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
41192 if (tcon->need_reconnect)
41193 seq_puts(m, "\tDISCONNECTED ");
41194 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
41195 - atomic_read(&tcon->num_smbs_sent),
41196 - atomic_read(&tcon->num_oplock_brks));
41197 + atomic_read_unchecked(&tcon->num_smbs_sent),
41198 + atomic_read_unchecked(&tcon->num_oplock_brks));
41199 seq_printf(m, "\nReads: %d Bytes: %lld",
41200 - atomic_read(&tcon->num_reads),
41201 + atomic_read_unchecked(&tcon->num_reads),
41202 (long long)(tcon->bytes_read));
41203 seq_printf(m, "\nWrites: %d Bytes: %lld",
41204 - atomic_read(&tcon->num_writes),
41205 + atomic_read_unchecked(&tcon->num_writes),
41206 (long long)(tcon->bytes_written));
41207 seq_printf(m, "\nFlushes: %d",
41208 - atomic_read(&tcon->num_flushes));
41209 + atomic_read_unchecked(&tcon->num_flushes));
41210 seq_printf(m, "\nLocks: %d HardLinks: %d "
41212 - atomic_read(&tcon->num_locks),
41213 - atomic_read(&tcon->num_hardlinks),
41214 - atomic_read(&tcon->num_symlinks));
41215 + atomic_read_unchecked(&tcon->num_locks),
41216 + atomic_read_unchecked(&tcon->num_hardlinks),
41217 + atomic_read_unchecked(&tcon->num_symlinks));
41218 seq_printf(m, "\nOpens: %d Closes: %d "
41220 - atomic_read(&tcon->num_opens),
41221 - atomic_read(&tcon->num_closes),
41222 - atomic_read(&tcon->num_deletes));
41223 + atomic_read_unchecked(&tcon->num_opens),
41224 + atomic_read_unchecked(&tcon->num_closes),
41225 + atomic_read_unchecked(&tcon->num_deletes));
41226 seq_printf(m, "\nPosix Opens: %d "
41227 "Posix Mkdirs: %d",
41228 - atomic_read(&tcon->num_posixopens),
41229 - atomic_read(&tcon->num_posixmkdirs));
41230 + atomic_read_unchecked(&tcon->num_posixopens),
41231 + atomic_read_unchecked(&tcon->num_posixmkdirs));
41232 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
41233 - atomic_read(&tcon->num_mkdirs),
41234 - atomic_read(&tcon->num_rmdirs));
41235 + atomic_read_unchecked(&tcon->num_mkdirs),
41236 + atomic_read_unchecked(&tcon->num_rmdirs));
41237 seq_printf(m, "\nRenames: %d T2 Renames %d",
41238 - atomic_read(&tcon->num_renames),
41239 - atomic_read(&tcon->num_t2renames));
41240 + atomic_read_unchecked(&tcon->num_renames),
41241 + atomic_read_unchecked(&tcon->num_t2renames));
41242 seq_printf(m, "\nFindFirst: %d FNext %d "
41244 - atomic_read(&tcon->num_ffirst),
41245 - atomic_read(&tcon->num_fnext),
41246 - atomic_read(&tcon->num_fclose));
41247 + atomic_read_unchecked(&tcon->num_ffirst),
41248 + atomic_read_unchecked(&tcon->num_fnext),
41249 + atomic_read_unchecked(&tcon->num_fclose));
41253 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
41254 index 8f1fe32..38f9e27 100644
41255 --- a/fs/cifs/cifsfs.c
41256 +++ b/fs/cifs/cifsfs.c
41257 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
41258 cifs_req_cachep = kmem_cache_create("cifs_request",
41260 MAX_CIFS_HDR_SIZE, 0,
41261 - SLAB_HWCACHE_ALIGN, NULL);
41262 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
41263 if (cifs_req_cachep == NULL)
41266 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
41267 efficient to alloc 1 per page off the slab compared to 17K (5page)
41268 alloc of large cifs buffers even when page debugging is on */
41269 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
41270 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
41271 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
41273 if (cifs_sm_req_cachep == NULL) {
41274 mempool_destroy(cifs_req_poolp);
41275 @@ -1101,8 +1101,8 @@ init_cifs(void)
41276 atomic_set(&bufAllocCount, 0);
41277 atomic_set(&smBufAllocCount, 0);
41278 #ifdef CONFIG_CIFS_STATS2
41279 - atomic_set(&totBufAllocCount, 0);
41280 - atomic_set(&totSmBufAllocCount, 0);
41281 + atomic_set_unchecked(&totBufAllocCount, 0);
41282 + atomic_set_unchecked(&totSmBufAllocCount, 0);
41283 #endif /* CONFIG_CIFS_STATS2 */
41285 atomic_set(&midCount, 0);
41286 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
41287 index 8238aa1..0347196 100644
41288 --- a/fs/cifs/cifsglob.h
41289 +++ b/fs/cifs/cifsglob.h
41290 @@ -392,28 +392,28 @@ struct cifs_tcon {
41291 __u16 Flags; /* optional support bits */
41292 enum statusEnum tidStatus;
41293 #ifdef CONFIG_CIFS_STATS
41294 - atomic_t num_smbs_sent;
41295 - atomic_t num_writes;
41296 - atomic_t num_reads;
41297 - atomic_t num_flushes;
41298 - atomic_t num_oplock_brks;
41299 - atomic_t num_opens;
41300 - atomic_t num_closes;
41301 - atomic_t num_deletes;
41302 - atomic_t num_mkdirs;
41303 - atomic_t num_posixopens;
41304 - atomic_t num_posixmkdirs;
41305 - atomic_t num_rmdirs;
41306 - atomic_t num_renames;
41307 - atomic_t num_t2renames;
41308 - atomic_t num_ffirst;
41309 - atomic_t num_fnext;
41310 - atomic_t num_fclose;
41311 - atomic_t num_hardlinks;
41312 - atomic_t num_symlinks;
41313 - atomic_t num_locks;
41314 - atomic_t num_acl_get;
41315 - atomic_t num_acl_set;
41316 + atomic_unchecked_t num_smbs_sent;
41317 + atomic_unchecked_t num_writes;
41318 + atomic_unchecked_t num_reads;
41319 + atomic_unchecked_t num_flushes;
41320 + atomic_unchecked_t num_oplock_brks;
41321 + atomic_unchecked_t num_opens;
41322 + atomic_unchecked_t num_closes;
41323 + atomic_unchecked_t num_deletes;
41324 + atomic_unchecked_t num_mkdirs;
41325 + atomic_unchecked_t num_posixopens;
41326 + atomic_unchecked_t num_posixmkdirs;
41327 + atomic_unchecked_t num_rmdirs;
41328 + atomic_unchecked_t num_renames;
41329 + atomic_unchecked_t num_t2renames;
41330 + atomic_unchecked_t num_ffirst;
41331 + atomic_unchecked_t num_fnext;
41332 + atomic_unchecked_t num_fclose;
41333 + atomic_unchecked_t num_hardlinks;
41334 + atomic_unchecked_t num_symlinks;
41335 + atomic_unchecked_t num_locks;
41336 + atomic_unchecked_t num_acl_get;
41337 + atomic_unchecked_t num_acl_set;
41338 #ifdef CONFIG_CIFS_STATS2
41339 unsigned long long time_writes;
41340 unsigned long long time_reads;
41341 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
41344 #ifdef CONFIG_CIFS_STATS
41345 -#define cifs_stats_inc atomic_inc
41346 +#define cifs_stats_inc atomic_inc_unchecked
41348 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
41349 unsigned int bytes)
41350 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
41351 /* Various Debug counters */
41352 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
41353 #ifdef CONFIG_CIFS_STATS2
41354 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
41355 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
41356 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
41357 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
41359 GLOBAL_EXTERN atomic_t smBufAllocCount;
41360 GLOBAL_EXTERN atomic_t midCount;
41361 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
41362 index 6b0e064..94e6c3c 100644
41363 --- a/fs/cifs/link.c
41364 +++ b/fs/cifs/link.c
41365 @@ -600,7 +600,7 @@ symlink_exit:
41367 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
41369 - char *p = nd_get_link(nd);
41370 + const char *p = nd_get_link(nd);
41374 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
41375 index 703ef5c..2a44ed5 100644
41376 --- a/fs/cifs/misc.c
41377 +++ b/fs/cifs/misc.c
41378 @@ -156,7 +156,7 @@ cifs_buf_get(void)
41379 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
41380 atomic_inc(&bufAllocCount);
41381 #ifdef CONFIG_CIFS_STATS2
41382 - atomic_inc(&totBufAllocCount);
41383 + atomic_inc_unchecked(&totBufAllocCount);
41384 #endif /* CONFIG_CIFS_STATS2 */
41387 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
41388 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
41389 atomic_inc(&smBufAllocCount);
41390 #ifdef CONFIG_CIFS_STATS2
41391 - atomic_inc(&totSmBufAllocCount);
41392 + atomic_inc_unchecked(&totSmBufAllocCount);
41393 #endif /* CONFIG_CIFS_STATS2 */
41396 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
41397 index 6901578..d402eb5 100644
41398 --- a/fs/coda/cache.c
41399 +++ b/fs/coda/cache.c
41401 #include "coda_linux.h"
41402 #include "coda_cache.h"
41404 -static atomic_t permission_epoch = ATOMIC_INIT(0);
41405 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
41407 /* replace or extend an acl cache hit */
41408 void coda_cache_enter(struct inode *inode, int mask)
41409 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
41410 struct coda_inode_info *cii = ITOC(inode);
41412 spin_lock(&cii->c_lock);
41413 - cii->c_cached_epoch = atomic_read(&permission_epoch);
41414 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
41415 if (cii->c_uid != current_fsuid()) {
41416 cii->c_uid = current_fsuid();
41417 cii->c_cached_perm = mask;
41418 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
41420 struct coda_inode_info *cii = ITOC(inode);
41421 spin_lock(&cii->c_lock);
41422 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
41423 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
41424 spin_unlock(&cii->c_lock);
41427 /* remove all acl caches */
41428 void coda_cache_clear_all(struct super_block *sb)
41430 - atomic_inc(&permission_epoch);
41431 + atomic_inc_unchecked(&permission_epoch);
41435 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
41436 spin_lock(&cii->c_lock);
41437 hit = (mask & cii->c_cached_perm) == mask &&
41438 cii->c_uid == current_fsuid() &&
41439 - cii->c_cached_epoch == atomic_read(&permission_epoch);
41440 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
41441 spin_unlock(&cii->c_lock);
41444 diff --git a/fs/compat.c b/fs/compat.c
41445 index c987875..08771ca 100644
41448 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
41449 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
41451 compat_ino_t ino = stat->ino;
41452 - typeof(ubuf->st_uid) uid = 0;
41453 - typeof(ubuf->st_gid) gid = 0;
41454 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
41455 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
41458 SET_UID(uid, stat->uid);
41459 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
41462 /* The __user pointer cast is valid because of the set_fs() */
41463 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
41464 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
41466 /* truncating is ok because it's a user address */
41468 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
41472 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
41473 + if (nr_segs > UIO_MAXIOV)
41475 if (nr_segs > fast_segs) {
41477 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
41479 struct compat_readdir_callback {
41480 struct compat_old_linux_dirent __user *dirent;
41481 + struct file * file;
41485 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
41486 buf->result = -EOVERFLOW;
41490 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41494 dirent = buf->dirent;
41495 if (!access_ok(VERIFY_WRITE, dirent,
41496 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
41499 buf.dirent = dirent;
41502 error = vfs_readdir(file, compat_fillonedir, &buf);
41504 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
41505 struct compat_getdents_callback {
41506 struct compat_linux_dirent __user *current_dir;
41507 struct compat_linux_dirent __user *previous;
41508 + struct file * file;
41512 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
41513 buf->error = -EOVERFLOW;
41517 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41520 dirent = buf->previous;
41522 if (__put_user(offset, &dirent->d_off))
41523 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
41524 buf.previous = NULL;
41529 error = vfs_readdir(file, compat_filldir, &buf);
41531 @@ -1003,6 +1015,7 @@ out:
41532 struct compat_getdents_callback64 {
41533 struct linux_dirent64 __user *current_dir;
41534 struct linux_dirent64 __user *previous;
41535 + struct file * file;
41539 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
41540 buf->error = -EINVAL; /* only used if we fail.. */
41541 if (reclen > buf->count)
41544 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41547 dirent = buf->previous;
41550 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
41551 buf.previous = NULL;
41556 error = vfs_readdir(file, compat_filldir64, &buf);
41559 lastdirent = buf.previous;
41561 - typeof(lastdirent->d_off) d_off = file->f_pos;
41562 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
41563 if (__put_user_unaligned(d_off, &lastdirent->d_off))
41566 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
41567 index 112e45a..b59845b 100644
41568 --- a/fs/compat_binfmt_elf.c
41569 +++ b/fs/compat_binfmt_elf.c
41570 @@ -30,11 +30,13 @@
41576 #define elfhdr elf32_hdr
41577 #define elf_phdr elf32_phdr
41578 #define elf_shdr elf32_shdr
41579 #define elf_note elf32_note
41580 +#define elf_dyn Elf32_Dyn
41581 #define elf_addr_t Elf32_Addr
41584 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
41585 index 51352de..93292ff 100644
41586 --- a/fs/compat_ioctl.c
41587 +++ b/fs/compat_ioctl.c
41588 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
41590 err = get_user(palp, &up->palette);
41591 err |= get_user(length, &up->length);
41595 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
41596 err = put_user(compat_ptr(palp), &up_native->palette);
41597 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
41599 if (__get_user(udata, &ss32->iomem_base))
41601 - ss.iomem_base = compat_ptr(udata);
41602 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
41603 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
41604 __get_user(ss.port_high, &ss32->port_high))
41606 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
41607 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
41608 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
41609 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
41610 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41611 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41614 return ioctl_preallocate(file, p);
41615 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
41616 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
41619 - a = *(unsigned int *)p;
41620 - b = *(unsigned int *)q;
41621 + a = *(const unsigned int *)p;
41622 + b = *(const unsigned int *)q;
41626 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
41627 index 9a37a9b..35792b6 100644
41628 --- a/fs/configfs/dir.c
41629 +++ b/fs/configfs/dir.c
41630 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41632 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
41633 struct configfs_dirent *next;
41634 - const char * name;
41635 + const unsigned char * name;
41636 + char d_name[sizeof(next->s_dentry->d_iname)];
41638 struct inode *inode = NULL;
41640 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41643 name = configfs_get_name(next);
41644 - len = strlen(name);
41645 + if (next->s_dentry && name == next->s_dentry->d_iname) {
41646 + len = next->s_dentry->d_name.len;
41647 + memcpy(d_name, name, len);
41650 + len = strlen(name);
41653 * We'll have a dentry and an inode for
41654 diff --git a/fs/dcache.c b/fs/dcache.c
41655 index f7908ae..920a680 100644
41658 @@ -3042,7 +3042,7 @@ void __init vfs_caches_init(unsigned long mempages)
41659 mempages -= reserve;
41661 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
41662 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
41663 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
41667 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
41668 index f3a257d..715ac0f 100644
41669 --- a/fs/debugfs/inode.c
41670 +++ b/fs/debugfs/inode.c
41671 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
41672 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
41674 return debugfs_create_file(name,
41675 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
41676 + S_IFDIR | S_IRWXU,
41678 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
41680 parent, NULL, NULL);
41682 EXPORT_SYMBOL_GPL(debugfs_create_dir);
41683 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
41684 index af11098..81e3bbe 100644
41685 --- a/fs/ecryptfs/inode.c
41686 +++ b/fs/ecryptfs/inode.c
41687 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
41690 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
41691 - (char __user *)lower_buf,
41692 + (char __force_user *)lower_buf,
41696 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41700 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
41701 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
41705 @@ -752,7 +752,7 @@ out:
41707 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
41709 - char *buf = nd_get_link(nd);
41710 + const char *buf = nd_get_link(nd);
41711 if (!IS_ERR(buf)) {
41712 /* Free the char* */
41714 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
41715 index 0dc5a3d..d3cdeea 100644
41716 --- a/fs/ecryptfs/miscdev.c
41717 +++ b/fs/ecryptfs/miscdev.c
41718 @@ -328,7 +328,7 @@ check_list:
41719 goto out_unlock_msg_ctx;
41721 if (msg_ctx->msg) {
41722 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
41723 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
41724 goto out_unlock_msg_ctx;
41725 i += packet_length_size;
41726 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
41727 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
41728 index 608c1c3..7d040a8 100644
41729 --- a/fs/ecryptfs/read_write.c
41730 +++ b/fs/ecryptfs/read_write.c
41731 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
41733 fs_save = get_fs();
41735 - rc = vfs_write(lower_file, data, size, &offset);
41736 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
41738 mark_inode_dirty_sync(ecryptfs_inode);
41740 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
41742 fs_save = get_fs();
41744 - rc = vfs_read(lower_file, data, size, &offset);
41745 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
41749 diff --git a/fs/exec.c b/fs/exec.c
41750 index 3625464..04855f9 100644
41753 @@ -55,12 +55,28 @@
41754 #include <linux/pipe_fs_i.h>
41755 #include <linux/oom.h>
41756 #include <linux/compat.h>
41757 +#include <linux/random.h>
41758 +#include <linux/seq_file.h>
41760 +#ifdef CONFIG_PAX_REFCOUNT
41761 +#include <linux/kallsyms.h>
41762 +#include <linux/kdebug.h>
41765 #include <asm/uaccess.h>
41766 #include <asm/mmu_context.h>
41767 #include <asm/tlb.h>
41768 #include "internal.h"
41770 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
41771 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
41774 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
41775 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
41776 +EXPORT_SYMBOL(pax_set_initial_flags_func);
41780 char core_pattern[CORENAME_MAX_SIZE] = "core";
41781 unsigned int core_pipe_limit;
41782 @@ -70,7 +86,7 @@ struct core_name {
41786 -static atomic_t call_count = ATOMIC_INIT(1);
41787 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
41789 /* The maximal length of core_pattern is also specified in sysctl.c */
41791 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
41797 -#ifdef CONFIG_STACK_GROWSUP
41799 - ret = expand_downwards(bprm->vma, pos);
41804 - ret = get_user_pages(current, bprm->mm, pos,
41805 - 1, write, 1, &page, NULL);
41807 + if (0 > expand_downwards(bprm->vma, pos))
41809 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
41813 @@ -215,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
41814 if (size <= ARG_MAX)
41817 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41818 + // only allow 1MB for argv+env on suid/sgid binaries
41819 + // to prevent easy ASLR exhaustion
41820 + if (((bprm->cred->euid != current_euid()) ||
41821 + (bprm->cred->egid != current_egid())) &&
41822 + (size > (1024 * 1024))) {
41829 * Limit to 1/4-th the stack size for the argv+env strings.
41830 * This ensures that:
41831 @@ -274,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41832 vma->vm_end = STACK_TOP_MAX;
41833 vma->vm_start = vma->vm_end - PAGE_SIZE;
41834 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
41836 +#ifdef CONFIG_PAX_SEGMEXEC
41837 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
41840 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
41841 INIT_LIST_HEAD(&vma->anon_vma_chain);
41843 @@ -288,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41844 mm->stack_vm = mm->total_vm = 1;
41845 up_write(&mm->mmap_sem);
41846 bprm->p = vma->vm_end - sizeof(void *);
41848 +#ifdef CONFIG_PAX_RANDUSTACK
41849 + if (randomize_va_space)
41850 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
41855 up_write(&mm->mmap_sem);
41856 @@ -396,19 +426,7 @@ err:
41860 -struct user_arg_ptr {
41861 -#ifdef CONFIG_COMPAT
41865 - const char __user *const __user *native;
41866 -#ifdef CONFIG_COMPAT
41867 - compat_uptr_t __user *compat;
41872 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41873 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41875 const char __user *native;
41877 @@ -417,14 +435,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41878 compat_uptr_t compat;
41880 if (get_user(compat, argv.ptr.compat + nr))
41881 - return ERR_PTR(-EFAULT);
41882 + return (const char __force_user *)ERR_PTR(-EFAULT);
41884 return compat_ptr(compat);
41888 if (get_user(native, argv.ptr.native + nr))
41889 - return ERR_PTR(-EFAULT);
41890 + return (const char __force_user *)ERR_PTR(-EFAULT);
41894 @@ -443,7 +461,7 @@ static int count(struct user_arg_ptr argv, int max)
41899 + if (IS_ERR((const char __force_kernel *)p))
41903 @@ -477,7 +495,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
41906 str = get_user_arg_ptr(argv, argc);
41908 + if (IS_ERR((const char __force_kernel *)str))
41911 len = strnlen_user(str, MAX_ARG_STRLEN);
41912 @@ -559,7 +577,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
41914 mm_segment_t oldfs = get_fs();
41915 struct user_arg_ptr argv = {
41916 - .ptr.native = (const char __user *const __user *)__argv,
41917 + .ptr.native = (const char __force_user *const __force_user *)__argv,
41921 @@ -594,7 +612,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41922 unsigned long new_end = old_end - shift;
41923 struct mmu_gather tlb;
41925 - BUG_ON(new_start > new_end);
41926 + if (new_start >= new_end || new_start < mmap_min_addr)
41930 * ensure there are no vmas between where we want to go
41931 @@ -603,6 +622,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41932 if (vma != find_vma(mm, new_start))
41935 +#ifdef CONFIG_PAX_SEGMEXEC
41936 + BUG_ON(pax_find_mirror_vma(vma));
41940 * cover the whole range: [new_start, old_end)
41942 @@ -683,10 +706,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41943 stack_top = arch_align_stack(stack_top);
41944 stack_top = PAGE_ALIGN(stack_top);
41946 - if (unlikely(stack_top < mmap_min_addr) ||
41947 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
41950 stack_shift = vma->vm_end - stack_top;
41952 bprm->p -= stack_shift;
41953 @@ -698,8 +717,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
41954 bprm->exec -= stack_shift;
41956 down_write(&mm->mmap_sem);
41958 + /* Move stack pages down in memory. */
41959 + if (stack_shift) {
41960 + ret = shift_arg_pages(vma, stack_shift);
41965 vm_flags = VM_STACK_FLAGS;
41967 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41968 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41969 + vm_flags &= ~VM_EXEC;
41971 +#ifdef CONFIG_PAX_MPROTECT
41972 + if (mm->pax_flags & MF_PAX_MPROTECT)
41973 + vm_flags &= ~VM_MAYEXEC;
41980 * Adjust stack execute permissions; explicitly enable for
41981 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
41982 @@ -718,13 +757,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41984 BUG_ON(prev != vma);
41986 - /* Move stack pages down in memory. */
41987 - if (stack_shift) {
41988 - ret = shift_arg_pages(vma, stack_shift);
41993 /* mprotect_fixup is overkill to remove the temporary stack flags */
41994 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
41996 @@ -805,7 +837,7 @@ int kernel_read(struct file *file, loff_t offset,
41999 /* The cast to a user pointer is valid due to the set_fs() */
42000 - result = vfs_read(file, (void __user *)addr, count, &pos);
42001 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
42005 @@ -1067,6 +1099,21 @@ void set_task_comm(struct task_struct *tsk, char *buf)
42006 perf_event_comm(tsk);
42009 +static void filename_to_taskname(char *tcomm, const char *fn, unsigned int len)
42013 + /* Copies the binary name from after last slash */
42014 + for (i = 0; (ch = *(fn++)) != '\0';) {
42016 + i = 0; /* overwrite what we wrote */
42024 int flush_old_exec(struct linux_binprm * bprm)
42027 @@ -1081,6 +1128,7 @@ int flush_old_exec(struct linux_binprm * bprm)
42029 set_mm_exe_file(bprm->mm, bprm->file);
42031 + filename_to_taskname(bprm->tcomm, bprm->filename, sizeof(bprm->tcomm));
42033 * Release all of the old mmap stuff
42035 @@ -1112,10 +1160,6 @@ EXPORT_SYMBOL(would_dump);
42037 void setup_new_exec(struct linux_binprm * bprm)
42040 - const char *name;
42041 - char tcomm[sizeof(current->comm)];
42043 arch_pick_mmap_layout(current->mm);
42045 /* This is the point of no return */
42046 @@ -1126,18 +1170,7 @@ void setup_new_exec(struct linux_binprm * bprm)
42048 set_dumpable(current->mm, suid_dumpable);
42050 - name = bprm->filename;
42052 - /* Copies the binary name from after last slash */
42053 - for (i=0; (ch = *(name++)) != '\0';) {
42055 - i = 0; /* overwrite what we wrote */
42057 - if (i < (sizeof(tcomm) - 1))
42061 - set_task_comm(current, tcomm);
42062 + set_task_comm(current, bprm->tcomm);
42064 /* Set the new mm task size. We have to do that late because it may
42065 * depend on TIF_32BIT which is only updated in flush_thread() on
42066 @@ -1247,7 +1280,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
42070 - if (p->fs->users > n_fs) {
42071 + if (atomic_read(&p->fs->users) > n_fs) {
42072 bprm->unsafe |= LSM_UNSAFE_SHARE;
42075 @@ -1442,6 +1475,10 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
42077 EXPORT_SYMBOL(search_binary_handler);
42079 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42080 +static atomic64_unchecked_t global_exec_counter = ATOMIC64_INIT(0);
42084 * sys_execve() executes a new program.
42086 @@ -1450,6 +1487,11 @@ static int do_execve_common(const char *filename,
42087 struct user_arg_ptr envp,
42088 struct pt_regs *regs)
42090 +#ifdef CONFIG_GRKERNSEC
42091 + struct file *old_exec_file;
42092 + struct acl_subject_label *old_acl;
42093 + struct rlimit old_rlim[RLIM_NLIMITS];
42095 struct linux_binprm *bprm;
42097 struct files_struct *displaced;
42098 @@ -1457,6 +1499,8 @@ static int do_execve_common(const char *filename,
42100 const struct cred *cred = current_cred();
42102 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(¤t->cred->user->processes), 1);
42105 * We move the actual failure in case of RLIMIT_NPROC excess from
42106 * set*uid() to execve() because too many poorly written programs
42107 @@ -1497,12 +1541,27 @@ static int do_execve_common(const char *filename,
42111 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
42119 bprm->filename = filename;
42120 bprm->interp = filename;
42122 + if (gr_process_user_ban()) {
42127 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
42128 + retval = -EACCES;
42132 retval = bprm_mm_init(bprm);
42135 @@ -1532,11 +1591,46 @@ static int do_execve_common(const char *filename,
42139 + if (!gr_tpe_allow(file)) {
42140 + retval = -EACCES;
42144 + if (gr_check_crash_exec(file)) {
42145 + retval = -EACCES;
42149 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
42151 + gr_handle_exec_args(bprm, argv);
42153 +#ifdef CONFIG_GRKERNSEC
42154 + old_acl = current->acl;
42155 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
42156 + old_exec_file = current->exec_file;
42158 + current->exec_file = file;
42161 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
42166 retval = search_binary_handler(bprm,regs);
42170 +#ifdef CONFIG_GRKERNSEC
42171 + if (old_exec_file)
42172 + fput(old_exec_file);
42175 /* execve succeeded */
42176 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42177 + current->exec_id = atomic64_inc_return_unchecked(&global_exec_counter);
42180 current->fs->in_exec = 0;
42181 current->in_execve = 0;
42182 acct_update_integrals(current);
42183 @@ -1545,6 +1639,14 @@ static int do_execve_common(const char *filename,
42184 put_files_struct(displaced);
42188 +#ifdef CONFIG_GRKERNSEC
42189 + current->acl = old_acl;
42190 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
42191 + fput(current->exec_file);
42192 + current->exec_file = old_exec_file;
42197 acct_arg_size(bprm, 0);
42198 @@ -1618,7 +1720,7 @@ static int expand_corename(struct core_name *cn)
42200 char *old_corename = cn->corename;
42202 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
42203 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
42204 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
42206 if (!cn->corename) {
42207 @@ -1715,7 +1817,7 @@ static int format_corename(struct core_name *cn, long signr)
42208 int pid_in_pattern = 0;
42211 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
42212 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
42213 cn->corename = kmalloc(cn->size, GFP_KERNEL);
42216 @@ -1812,6 +1914,218 @@ out:
42220 +int pax_check_flags(unsigned long *flags)
42224 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
42225 + if (*flags & MF_PAX_SEGMEXEC)
42227 + *flags &= ~MF_PAX_SEGMEXEC;
42228 + retval = -EINVAL;
42232 + if ((*flags & MF_PAX_PAGEEXEC)
42234 +#ifdef CONFIG_PAX_PAGEEXEC
42235 + && (*flags & MF_PAX_SEGMEXEC)
42240 + *flags &= ~MF_PAX_PAGEEXEC;
42241 + retval = -EINVAL;
42244 + if ((*flags & MF_PAX_MPROTECT)
42246 +#ifdef CONFIG_PAX_MPROTECT
42247 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
42252 + *flags &= ~MF_PAX_MPROTECT;
42253 + retval = -EINVAL;
42256 + if ((*flags & MF_PAX_EMUTRAMP)
42258 +#ifdef CONFIG_PAX_EMUTRAMP
42259 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
42264 + *flags &= ~MF_PAX_EMUTRAMP;
42265 + retval = -EINVAL;
42271 +EXPORT_SYMBOL(pax_check_flags);
42273 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42274 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
42276 + struct task_struct *tsk = current;
42277 + struct mm_struct *mm = current->mm;
42278 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
42279 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
42280 + char *path_exec = NULL;
42281 + char *path_fault = NULL;
42282 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
42284 + if (buffer_exec && buffer_fault) {
42285 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
42287 + down_read(&mm->mmap_sem);
42289 + while (vma && (!vma_exec || !vma_fault)) {
42290 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
42292 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
42294 + vma = vma->vm_next;
42297 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
42298 + if (IS_ERR(path_exec))
42299 + path_exec = "<path too long>";
42301 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
42304 + path_exec = buffer_exec;
42306 + path_exec = "<path too long>";
42310 + start = vma_fault->vm_start;
42311 + end = vma_fault->vm_end;
42312 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
42313 + if (vma_fault->vm_file) {
42314 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
42315 + if (IS_ERR(path_fault))
42316 + path_fault = "<path too long>";
42318 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
42319 + if (path_fault) {
42321 + path_fault = buffer_fault;
42323 + path_fault = "<path too long>";
42326 + path_fault = "<anonymous mapping>";
42328 + up_read(&mm->mmap_sem);
42330 + if (tsk->signal->curr_ip)
42331 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
42333 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
42334 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
42335 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
42336 + task_uid(tsk), task_euid(tsk), pc, sp);
42337 + free_page((unsigned long)buffer_exec);
42338 + free_page((unsigned long)buffer_fault);
42339 + pax_report_insns(regs, pc, sp);
42340 + do_coredump(SIGKILL, SIGKILL, regs);
42344 +#ifdef CONFIG_PAX_REFCOUNT
42345 +void pax_report_refcount_overflow(struct pt_regs *regs)
42347 + if (current->signal->curr_ip)
42348 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
42349 + ¤t->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
42351 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
42352 + current->comm, task_pid_nr(current), current_uid(), current_euid());
42353 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
42355 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
42359 +#ifdef CONFIG_PAX_USERCOPY
42360 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
42361 +int object_is_on_stack(const void *obj, unsigned long len)
42363 + const void * const stack = task_stack_page(current);
42364 + const void * const stackend = stack + THREAD_SIZE;
42366 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42367 + const void *frame = NULL;
42368 + const void *oldframe;
42371 + if (obj + len < obj)
42374 + if (obj + len <= stack || stackend <= obj)
42377 + if (obj < stack || stackend < obj + len)
42380 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42381 + oldframe = __builtin_frame_address(1);
42383 + frame = __builtin_frame_address(2);
42385 + low ----------------------------------------------> high
42386 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
42387 + ^----------------^
42388 + allow copies only within here
42390 + while (stack <= frame && frame < stackend) {
42391 + /* if obj + len extends past the last frame, this
42392 + check won't pass and the next frame will be 0,
42393 + causing us to bail out and correctly report
42394 + the copy as invalid
42396 + if (obj + len <= frame)
42397 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
42398 + oldframe = frame;
42399 + frame = *(const void * const *)frame;
42407 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
42409 + if (current->signal->curr_ip)
42410 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42411 + ¤t->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42413 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42414 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42416 + gr_handle_kernel_exploit();
42417 + do_group_exit(SIGKILL);
42421 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
42422 +void pax_track_stack(void)
42424 + unsigned long sp = (unsigned long)&sp;
42425 + if (sp < current_thread_info()->lowest_stack &&
42426 + sp > (unsigned long)task_stack_page(current))
42427 + current_thread_info()->lowest_stack = sp;
42429 +EXPORT_SYMBOL(pax_track_stack);
42432 static int zap_process(struct task_struct *start, int exit_code)
42434 struct task_struct *t;
42435 @@ -2023,17 +2337,17 @@ static void wait_for_dump_helpers(struct file *file)
42436 pipe = file->f_path.dentry->d_inode->i_pipe;
42441 + atomic_inc(&pipe->readers);
42442 + atomic_dec(&pipe->writers);
42444 - while ((pipe->readers > 1) && (!signal_pending(current))) {
42445 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
42446 wake_up_interruptible_sync(&pipe->wait);
42447 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
42453 + atomic_dec(&pipe->readers);
42454 + atomic_inc(&pipe->writers);
42458 @@ -2094,7 +2408,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42462 - static atomic_t core_dump_count = ATOMIC_INIT(0);
42463 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
42464 struct coredump_params cprm = {
42467 @@ -2109,6 +2423,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42469 audit_core_dumps(signr);
42471 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
42472 + gr_handle_brute_attach(current, cprm.mm_flags);
42474 binfmt = mm->binfmt;
42475 if (!binfmt || !binfmt->core_dump)
42477 @@ -2176,7 +2493,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42479 cprm.limit = RLIM_INFINITY;
42481 - dump_count = atomic_inc_return(&core_dump_count);
42482 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
42483 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
42484 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
42485 task_tgid_vnr(current), current->comm);
42486 @@ -2203,6 +2520,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42488 struct inode *inode;
42490 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
42492 if (cprm.limit < binfmt->min_coredump)
42495 @@ -2246,7 +2565,7 @@ close_fail:
42496 filp_close(cprm.file, NULL);
42499 - atomic_dec(&core_dump_count);
42500 + atomic_dec_unchecked(&core_dump_count);
42502 kfree(cn.corename);
42504 @@ -2265,7 +2584,7 @@ fail:
42506 int dump_write(struct file *file, const void *addr, int nr)
42508 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
42509 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
42511 EXPORT_SYMBOL(dump_write);
42513 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
42514 index a8cbe1b..fed04cb 100644
42515 --- a/fs/ext2/balloc.c
42516 +++ b/fs/ext2/balloc.c
42517 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
42519 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42520 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42521 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42522 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
42523 sbi->s_resuid != current_fsuid() &&
42524 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42526 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
42527 index a203892..4e64db5 100644
42528 --- a/fs/ext3/balloc.c
42529 +++ b/fs/ext3/balloc.c
42530 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
42532 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42533 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42534 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42535 + if (free_blocks < root_blocks + 1 &&
42536 !use_reservation && sbi->s_resuid != current_fsuid() &&
42537 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42538 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
42539 + !capable_nolog(CAP_SYS_RESOURCE)) {
42543 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
42544 index 12ccacd..a6035fce0 100644
42545 --- a/fs/ext4/balloc.c
42546 +++ b/fs/ext4/balloc.c
42547 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
42548 /* Hm, nope. Are (enough) root reserved clusters available? */
42549 if (sbi->s_resuid == current_fsuid() ||
42550 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
42551 - capable(CAP_SYS_RESOURCE) ||
42552 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
42553 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
42554 + capable_nolog(CAP_SYS_RESOURCE)) {
42556 if (free_clusters >= (nclusters + dirty_clusters))
42558 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
42559 index 5b0e26a..0aa002d 100644
42560 --- a/fs/ext4/ext4.h
42561 +++ b/fs/ext4/ext4.h
42562 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
42563 unsigned long s_mb_last_start;
42565 /* stats for buddy allocator */
42566 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
42567 - atomic_t s_bal_success; /* we found long enough chunks */
42568 - atomic_t s_bal_allocated; /* in blocks */
42569 - atomic_t s_bal_ex_scanned; /* total extents scanned */
42570 - atomic_t s_bal_goals; /* goal hits */
42571 - atomic_t s_bal_breaks; /* too long searches */
42572 - atomic_t s_bal_2orders; /* 2^order hits */
42573 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
42574 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
42575 + atomic_unchecked_t s_bal_allocated; /* in blocks */
42576 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
42577 + atomic_unchecked_t s_bal_goals; /* goal hits */
42578 + atomic_unchecked_t s_bal_breaks; /* too long searches */
42579 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
42580 spinlock_t s_bal_lock;
42581 unsigned long s_mb_buddies_generated;
42582 unsigned long long s_mb_generation_time;
42583 - atomic_t s_mb_lost_chunks;
42584 - atomic_t s_mb_preallocated;
42585 - atomic_t s_mb_discarded;
42586 + atomic_unchecked_t s_mb_lost_chunks;
42587 + atomic_unchecked_t s_mb_preallocated;
42588 + atomic_unchecked_t s_mb_discarded;
42589 atomic_t s_lock_busy;
42591 /* locality groups */
42592 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
42593 index e2d8be8..c7f0ce9 100644
42594 --- a/fs/ext4/mballoc.c
42595 +++ b/fs/ext4/mballoc.c
42596 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
42597 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
42599 if (EXT4_SB(sb)->s_mb_stats)
42600 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
42601 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
42605 @@ -2088,7 +2088,7 @@ repeat:
42606 ac->ac_status = AC_STATUS_CONTINUE;
42607 ac->ac_flags |= EXT4_MB_HINT_FIRST;
42609 - atomic_inc(&sbi->s_mb_lost_chunks);
42610 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
42614 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
42615 if (sbi->s_mb_stats) {
42616 ext4_msg(sb, KERN_INFO,
42617 "mballoc: %u blocks %u reqs (%u success)",
42618 - atomic_read(&sbi->s_bal_allocated),
42619 - atomic_read(&sbi->s_bal_reqs),
42620 - atomic_read(&sbi->s_bal_success));
42621 + atomic_read_unchecked(&sbi->s_bal_allocated),
42622 + atomic_read_unchecked(&sbi->s_bal_reqs),
42623 + atomic_read_unchecked(&sbi->s_bal_success));
42624 ext4_msg(sb, KERN_INFO,
42625 "mballoc: %u extents scanned, %u goal hits, "
42626 "%u 2^N hits, %u breaks, %u lost",
42627 - atomic_read(&sbi->s_bal_ex_scanned),
42628 - atomic_read(&sbi->s_bal_goals),
42629 - atomic_read(&sbi->s_bal_2orders),
42630 - atomic_read(&sbi->s_bal_breaks),
42631 - atomic_read(&sbi->s_mb_lost_chunks));
42632 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
42633 + atomic_read_unchecked(&sbi->s_bal_goals),
42634 + atomic_read_unchecked(&sbi->s_bal_2orders),
42635 + atomic_read_unchecked(&sbi->s_bal_breaks),
42636 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
42637 ext4_msg(sb, KERN_INFO,
42638 "mballoc: %lu generated and it took %Lu",
42639 sbi->s_mb_buddies_generated,
42640 sbi->s_mb_generation_time);
42641 ext4_msg(sb, KERN_INFO,
42642 "mballoc: %u preallocated, %u discarded",
42643 - atomic_read(&sbi->s_mb_preallocated),
42644 - atomic_read(&sbi->s_mb_discarded));
42645 + atomic_read_unchecked(&sbi->s_mb_preallocated),
42646 + atomic_read_unchecked(&sbi->s_mb_discarded));
42649 free_percpu(sbi->s_locality_groups);
42650 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
42651 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
42653 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
42654 - atomic_inc(&sbi->s_bal_reqs);
42655 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42656 + atomic_inc_unchecked(&sbi->s_bal_reqs);
42657 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42658 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
42659 - atomic_inc(&sbi->s_bal_success);
42660 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
42661 + atomic_inc_unchecked(&sbi->s_bal_success);
42662 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
42663 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
42664 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
42665 - atomic_inc(&sbi->s_bal_goals);
42666 + atomic_inc_unchecked(&sbi->s_bal_goals);
42667 if (ac->ac_found > sbi->s_mb_max_to_scan)
42668 - atomic_inc(&sbi->s_bal_breaks);
42669 + atomic_inc_unchecked(&sbi->s_bal_breaks);
42672 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
42673 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
42674 trace_ext4_mb_new_inode_pa(ac, pa);
42676 ext4_mb_use_inode_pa(ac, pa);
42677 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
42678 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
42680 ei = EXT4_I(ac->ac_inode);
42681 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42682 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
42683 trace_ext4_mb_new_group_pa(ac, pa);
42685 ext4_mb_use_group_pa(ac, pa);
42686 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42687 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42689 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42691 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
42692 * from the bitmap and continue.
42695 - atomic_add(free, &sbi->s_mb_discarded);
42696 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
42700 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
42701 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
42702 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
42703 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
42704 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42705 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42706 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
42709 diff --git a/fs/fcntl.c b/fs/fcntl.c
42710 index 22764c7..86372c9 100644
42713 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
42717 + if (gr_handle_chroot_fowner(pid, type))
42719 + if (gr_check_protected_task_fowner(pid, type))
42722 f_modown(filp, pid, type, force);
42725 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
42727 static int f_setown_ex(struct file *filp, unsigned long arg)
42729 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42730 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42731 struct f_owner_ex owner;
42734 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
42736 static int f_getown_ex(struct file *filp, unsigned long arg)
42738 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42739 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42740 struct f_owner_ex owner;
42743 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
42746 case F_DUPFD_CLOEXEC:
42747 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
42748 if (arg >= rlimit(RLIMIT_NOFILE))
42750 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
42751 diff --git a/fs/fifo.c b/fs/fifo.c
42752 index b1a524d..4ee270e 100644
42755 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
42757 filp->f_op = &read_pipefifo_fops;
42759 - if (pipe->readers++ == 0)
42760 + if (atomic_inc_return(&pipe->readers) == 1)
42761 wake_up_partner(inode);
42763 - if (!pipe->writers) {
42764 + if (!atomic_read(&pipe->writers)) {
42765 if ((filp->f_flags & O_NONBLOCK)) {
42766 /* suppress POLLHUP until we have
42768 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
42769 * errno=ENXIO when there is no process reading the FIFO.
42772 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
42773 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
42776 filp->f_op = &write_pipefifo_fops;
42778 - if (!pipe->writers++)
42779 + if (atomic_inc_return(&pipe->writers) == 1)
42780 wake_up_partner(inode);
42782 - if (!pipe->readers) {
42783 + if (!atomic_read(&pipe->readers)) {
42784 wait_for_partner(inode, &pipe->r_counter);
42785 if (signal_pending(current))
42787 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
42789 filp->f_op = &rdwr_pipefifo_fops;
42793 + atomic_inc(&pipe->readers);
42794 + atomic_inc(&pipe->writers);
42797 - if (pipe->readers == 1 || pipe->writers == 1)
42798 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
42799 wake_up_partner(inode);
42802 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
42806 - if (!--pipe->readers)
42807 + if (atomic_dec_and_test(&pipe->readers))
42808 wake_up_interruptible(&pipe->wait);
42809 ret = -ERESTARTSYS;
42813 - if (!--pipe->writers)
42814 + if (atomic_dec_and_test(&pipe->writers))
42815 wake_up_interruptible(&pipe->wait);
42816 ret = -ERESTARTSYS;
42820 - if (!pipe->readers && !pipe->writers)
42821 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
42822 free_pipe_info(inode);
42825 diff --git a/fs/file.c b/fs/file.c
42826 index 4c6992d..104cdea 100644
42830 #include <linux/slab.h>
42831 #include <linux/vmalloc.h>
42832 #include <linux/file.h>
42833 +#include <linux/security.h>
42834 #include <linux/fdtable.h>
42835 #include <linux/bitops.h>
42836 #include <linux/interrupt.h>
42837 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
42838 * N.B. For clone tasks sharing a files structure, this test
42839 * will limit the total number of files that can be opened.
42841 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
42842 if (nr >= rlimit(RLIMIT_NOFILE))
42845 diff --git a/fs/filesystems.c b/fs/filesystems.c
42846 index 0845f84..7b4ebef 100644
42847 --- a/fs/filesystems.c
42848 +++ b/fs/filesystems.c
42849 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
42850 int len = dot ? dot - name : strlen(name);
42852 fs = __get_fs_type(name, len);
42854 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
42855 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
42857 if (!fs && (request_module("%.*s", len, name) == 0))
42859 fs = __get_fs_type(name, len);
42861 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
42862 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
42863 index 78b519c..a8b4979 100644
42864 --- a/fs/fs_struct.c
42865 +++ b/fs/fs_struct.c
42867 #include <linux/path.h>
42868 #include <linux/slab.h>
42869 #include <linux/fs_struct.h>
42870 +#include <linux/grsecurity.h>
42871 #include "internal.h"
42873 static inline void path_get_longterm(struct path *path)
42874 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
42875 old_root = fs->root;
42877 path_get_longterm(path);
42878 + gr_set_chroot_entries(current, path);
42879 write_seqcount_end(&fs->seq);
42880 spin_unlock(&fs->lock);
42881 if (old_root.dentry)
42882 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
42883 && fs->root.mnt == old_root->mnt) {
42884 path_get_longterm(new_root);
42885 fs->root = *new_root;
42886 + gr_set_chroot_entries(p, new_root);
42889 if (fs->pwd.dentry == old_root->dentry
42890 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
42891 spin_lock(&fs->lock);
42892 write_seqcount_begin(&fs->seq);
42894 - kill = !--fs->users;
42895 + gr_clear_chroot_entries(tsk);
42896 + kill = !atomic_dec_return(&fs->users);
42897 write_seqcount_end(&fs->seq);
42898 spin_unlock(&fs->lock);
42900 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42901 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
42902 /* We don't need to lock fs - think why ;-) */
42905 + atomic_set(&fs->users, 1);
42907 spin_lock_init(&fs->lock);
42908 seqcount_init(&fs->seq);
42909 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42910 spin_lock(&old->lock);
42911 fs->root = old->root;
42912 path_get_longterm(&fs->root);
42913 + /* instead of calling gr_set_chroot_entries here,
42914 + we call it from every caller of this function
42916 fs->pwd = old->pwd;
42917 path_get_longterm(&fs->pwd);
42918 spin_unlock(&old->lock);
42919 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
42921 task_lock(current);
42922 spin_lock(&fs->lock);
42923 - kill = !--fs->users;
42924 + kill = !atomic_dec_return(&fs->users);
42925 current->fs = new_fs;
42926 + gr_set_chroot_entries(current, &new_fs->root);
42927 spin_unlock(&fs->lock);
42928 task_unlock(current);
42930 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
42932 int current_umask(void)
42934 - return current->fs->umask;
42935 + return current->fs->umask | gr_acl_umask();
42937 EXPORT_SYMBOL(current_umask);
42939 /* to be mentioned only in INIT_TASK */
42940 struct fs_struct init_fs = {
42942 + .users = ATOMIC_INIT(1),
42943 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
42944 .seq = SEQCNT_ZERO,
42946 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
42947 task_lock(current);
42949 spin_lock(&init_fs.lock);
42951 + atomic_inc(&init_fs.users);
42952 spin_unlock(&init_fs.lock);
42954 spin_lock(&fs->lock);
42955 current->fs = &init_fs;
42956 - kill = !--fs->users;
42957 + gr_set_chroot_entries(current, ¤t->fs->root);
42958 + kill = !atomic_dec_return(&fs->users);
42959 spin_unlock(&fs->lock);
42961 task_unlock(current);
42962 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
42963 index 9905350..02eaec4 100644
42964 --- a/fs/fscache/cookie.c
42965 +++ b/fs/fscache/cookie.c
42966 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
42967 parent ? (char *) parent->def->name : "<no-parent>",
42968 def->name, netfs_data);
42970 - fscache_stat(&fscache_n_acquires);
42971 + fscache_stat_unchecked(&fscache_n_acquires);
42973 /* if there's no parent cookie, then we don't create one here either */
42975 - fscache_stat(&fscache_n_acquires_null);
42976 + fscache_stat_unchecked(&fscache_n_acquires_null);
42977 _leave(" [no parent]");
42980 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
42981 /* allocate and initialise a cookie */
42982 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
42984 - fscache_stat(&fscache_n_acquires_oom);
42985 + fscache_stat_unchecked(&fscache_n_acquires_oom);
42986 _leave(" [ENOMEM]");
42989 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42991 switch (cookie->def->type) {
42992 case FSCACHE_COOKIE_TYPE_INDEX:
42993 - fscache_stat(&fscache_n_cookie_index);
42994 + fscache_stat_unchecked(&fscache_n_cookie_index);
42996 case FSCACHE_COOKIE_TYPE_DATAFILE:
42997 - fscache_stat(&fscache_n_cookie_data);
42998 + fscache_stat_unchecked(&fscache_n_cookie_data);
43001 - fscache_stat(&fscache_n_cookie_special);
43002 + fscache_stat_unchecked(&fscache_n_cookie_special);
43006 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
43007 if (fscache_acquire_non_index_cookie(cookie) < 0) {
43008 atomic_dec(&parent->n_children);
43009 __fscache_cookie_put(cookie);
43010 - fscache_stat(&fscache_n_acquires_nobufs);
43011 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
43017 - fscache_stat(&fscache_n_acquires_ok);
43018 + fscache_stat_unchecked(&fscache_n_acquires_ok);
43019 _leave(" = %p", cookie);
43022 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
43023 cache = fscache_select_cache_for_object(cookie->parent);
43025 up_read(&fscache_addremove_sem);
43026 - fscache_stat(&fscache_n_acquires_no_cache);
43027 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
43028 _leave(" = -ENOMEDIUM [no cache]");
43031 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
43032 object = cache->ops->alloc_object(cache, cookie);
43033 fscache_stat_d(&fscache_n_cop_alloc_object);
43034 if (IS_ERR(object)) {
43035 - fscache_stat(&fscache_n_object_no_alloc);
43036 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
43037 ret = PTR_ERR(object);
43041 - fscache_stat(&fscache_n_object_alloc);
43042 + fscache_stat_unchecked(&fscache_n_object_alloc);
43044 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
43046 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
43047 struct fscache_object *object;
43048 struct hlist_node *_p;
43050 - fscache_stat(&fscache_n_updates);
43051 + fscache_stat_unchecked(&fscache_n_updates);
43054 - fscache_stat(&fscache_n_updates_null);
43055 + fscache_stat_unchecked(&fscache_n_updates_null);
43056 _leave(" [no cookie]");
43059 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
43060 struct fscache_object *object;
43061 unsigned long event;
43063 - fscache_stat(&fscache_n_relinquishes);
43064 + fscache_stat_unchecked(&fscache_n_relinquishes);
43066 - fscache_stat(&fscache_n_relinquishes_retire);
43067 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
43070 - fscache_stat(&fscache_n_relinquishes_null);
43071 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
43072 _leave(" [no cookie]");
43075 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
43077 /* wait for the cookie to finish being instantiated (or to fail) */
43078 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
43079 - fscache_stat(&fscache_n_relinquishes_waitcrt);
43080 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
43081 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
43082 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
43084 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
43085 index f6aad48..88dcf26 100644
43086 --- a/fs/fscache/internal.h
43087 +++ b/fs/fscache/internal.h
43088 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
43089 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
43090 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
43092 -extern atomic_t fscache_n_op_pend;
43093 -extern atomic_t fscache_n_op_run;
43094 -extern atomic_t fscache_n_op_enqueue;
43095 -extern atomic_t fscache_n_op_deferred_release;
43096 -extern atomic_t fscache_n_op_release;
43097 -extern atomic_t fscache_n_op_gc;
43098 -extern atomic_t fscache_n_op_cancelled;
43099 -extern atomic_t fscache_n_op_rejected;
43100 +extern atomic_unchecked_t fscache_n_op_pend;
43101 +extern atomic_unchecked_t fscache_n_op_run;
43102 +extern atomic_unchecked_t fscache_n_op_enqueue;
43103 +extern atomic_unchecked_t fscache_n_op_deferred_release;
43104 +extern atomic_unchecked_t fscache_n_op_release;
43105 +extern atomic_unchecked_t fscache_n_op_gc;
43106 +extern atomic_unchecked_t fscache_n_op_cancelled;
43107 +extern atomic_unchecked_t fscache_n_op_rejected;
43109 -extern atomic_t fscache_n_attr_changed;
43110 -extern atomic_t fscache_n_attr_changed_ok;
43111 -extern atomic_t fscache_n_attr_changed_nobufs;
43112 -extern atomic_t fscache_n_attr_changed_nomem;
43113 -extern atomic_t fscache_n_attr_changed_calls;
43114 +extern atomic_unchecked_t fscache_n_attr_changed;
43115 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
43116 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
43117 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
43118 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
43120 -extern atomic_t fscache_n_allocs;
43121 -extern atomic_t fscache_n_allocs_ok;
43122 -extern atomic_t fscache_n_allocs_wait;
43123 -extern atomic_t fscache_n_allocs_nobufs;
43124 -extern atomic_t fscache_n_allocs_intr;
43125 -extern atomic_t fscache_n_allocs_object_dead;
43126 -extern atomic_t fscache_n_alloc_ops;
43127 -extern atomic_t fscache_n_alloc_op_waits;
43128 +extern atomic_unchecked_t fscache_n_allocs;
43129 +extern atomic_unchecked_t fscache_n_allocs_ok;
43130 +extern atomic_unchecked_t fscache_n_allocs_wait;
43131 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
43132 +extern atomic_unchecked_t fscache_n_allocs_intr;
43133 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
43134 +extern atomic_unchecked_t fscache_n_alloc_ops;
43135 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
43137 -extern atomic_t fscache_n_retrievals;
43138 -extern atomic_t fscache_n_retrievals_ok;
43139 -extern atomic_t fscache_n_retrievals_wait;
43140 -extern atomic_t fscache_n_retrievals_nodata;
43141 -extern atomic_t fscache_n_retrievals_nobufs;
43142 -extern atomic_t fscache_n_retrievals_intr;
43143 -extern atomic_t fscache_n_retrievals_nomem;
43144 -extern atomic_t fscache_n_retrievals_object_dead;
43145 -extern atomic_t fscache_n_retrieval_ops;
43146 -extern atomic_t fscache_n_retrieval_op_waits;
43147 +extern atomic_unchecked_t fscache_n_retrievals;
43148 +extern atomic_unchecked_t fscache_n_retrievals_ok;
43149 +extern atomic_unchecked_t fscache_n_retrievals_wait;
43150 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
43151 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
43152 +extern atomic_unchecked_t fscache_n_retrievals_intr;
43153 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
43154 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
43155 +extern atomic_unchecked_t fscache_n_retrieval_ops;
43156 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
43158 -extern atomic_t fscache_n_stores;
43159 -extern atomic_t fscache_n_stores_ok;
43160 -extern atomic_t fscache_n_stores_again;
43161 -extern atomic_t fscache_n_stores_nobufs;
43162 -extern atomic_t fscache_n_stores_oom;
43163 -extern atomic_t fscache_n_store_ops;
43164 -extern atomic_t fscache_n_store_calls;
43165 -extern atomic_t fscache_n_store_pages;
43166 -extern atomic_t fscache_n_store_radix_deletes;
43167 -extern atomic_t fscache_n_store_pages_over_limit;
43168 +extern atomic_unchecked_t fscache_n_stores;
43169 +extern atomic_unchecked_t fscache_n_stores_ok;
43170 +extern atomic_unchecked_t fscache_n_stores_again;
43171 +extern atomic_unchecked_t fscache_n_stores_nobufs;
43172 +extern atomic_unchecked_t fscache_n_stores_oom;
43173 +extern atomic_unchecked_t fscache_n_store_ops;
43174 +extern atomic_unchecked_t fscache_n_store_calls;
43175 +extern atomic_unchecked_t fscache_n_store_pages;
43176 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
43177 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
43179 -extern atomic_t fscache_n_store_vmscan_not_storing;
43180 -extern atomic_t fscache_n_store_vmscan_gone;
43181 -extern atomic_t fscache_n_store_vmscan_busy;
43182 -extern atomic_t fscache_n_store_vmscan_cancelled;
43183 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
43184 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
43185 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
43186 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
43188 -extern atomic_t fscache_n_marks;
43189 -extern atomic_t fscache_n_uncaches;
43190 +extern atomic_unchecked_t fscache_n_marks;
43191 +extern atomic_unchecked_t fscache_n_uncaches;
43193 -extern atomic_t fscache_n_acquires;
43194 -extern atomic_t fscache_n_acquires_null;
43195 -extern atomic_t fscache_n_acquires_no_cache;
43196 -extern atomic_t fscache_n_acquires_ok;
43197 -extern atomic_t fscache_n_acquires_nobufs;
43198 -extern atomic_t fscache_n_acquires_oom;
43199 +extern atomic_unchecked_t fscache_n_acquires;
43200 +extern atomic_unchecked_t fscache_n_acquires_null;
43201 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
43202 +extern atomic_unchecked_t fscache_n_acquires_ok;
43203 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
43204 +extern atomic_unchecked_t fscache_n_acquires_oom;
43206 -extern atomic_t fscache_n_updates;
43207 -extern atomic_t fscache_n_updates_null;
43208 -extern atomic_t fscache_n_updates_run;
43209 +extern atomic_unchecked_t fscache_n_updates;
43210 +extern atomic_unchecked_t fscache_n_updates_null;
43211 +extern atomic_unchecked_t fscache_n_updates_run;
43213 -extern atomic_t fscache_n_relinquishes;
43214 -extern atomic_t fscache_n_relinquishes_null;
43215 -extern atomic_t fscache_n_relinquishes_waitcrt;
43216 -extern atomic_t fscache_n_relinquishes_retire;
43217 +extern atomic_unchecked_t fscache_n_relinquishes;
43218 +extern atomic_unchecked_t fscache_n_relinquishes_null;
43219 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
43220 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
43222 -extern atomic_t fscache_n_cookie_index;
43223 -extern atomic_t fscache_n_cookie_data;
43224 -extern atomic_t fscache_n_cookie_special;
43225 +extern atomic_unchecked_t fscache_n_cookie_index;
43226 +extern atomic_unchecked_t fscache_n_cookie_data;
43227 +extern atomic_unchecked_t fscache_n_cookie_special;
43229 -extern atomic_t fscache_n_object_alloc;
43230 -extern atomic_t fscache_n_object_no_alloc;
43231 -extern atomic_t fscache_n_object_lookups;
43232 -extern atomic_t fscache_n_object_lookups_negative;
43233 -extern atomic_t fscache_n_object_lookups_positive;
43234 -extern atomic_t fscache_n_object_lookups_timed_out;
43235 -extern atomic_t fscache_n_object_created;
43236 -extern atomic_t fscache_n_object_avail;
43237 -extern atomic_t fscache_n_object_dead;
43238 +extern atomic_unchecked_t fscache_n_object_alloc;
43239 +extern atomic_unchecked_t fscache_n_object_no_alloc;
43240 +extern atomic_unchecked_t fscache_n_object_lookups;
43241 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
43242 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
43243 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
43244 +extern atomic_unchecked_t fscache_n_object_created;
43245 +extern atomic_unchecked_t fscache_n_object_avail;
43246 +extern atomic_unchecked_t fscache_n_object_dead;
43248 -extern atomic_t fscache_n_checkaux_none;
43249 -extern atomic_t fscache_n_checkaux_okay;
43250 -extern atomic_t fscache_n_checkaux_update;
43251 -extern atomic_t fscache_n_checkaux_obsolete;
43252 +extern atomic_unchecked_t fscache_n_checkaux_none;
43253 +extern atomic_unchecked_t fscache_n_checkaux_okay;
43254 +extern atomic_unchecked_t fscache_n_checkaux_update;
43255 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
43257 extern atomic_t fscache_n_cop_alloc_object;
43258 extern atomic_t fscache_n_cop_lookup_object;
43259 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
43263 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
43265 + atomic_inc_unchecked(stat);
43268 static inline void fscache_stat_d(atomic_t *stat)
43271 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
43273 #define __fscache_stat(stat) (NULL)
43274 #define fscache_stat(stat) do {} while (0)
43275 +#define fscache_stat_unchecked(stat) do {} while (0)
43276 #define fscache_stat_d(stat) do {} while (0)
43279 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
43280 index b6b897c..0ffff9c 100644
43281 --- a/fs/fscache/object.c
43282 +++ b/fs/fscache/object.c
43283 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
43284 /* update the object metadata on disk */
43285 case FSCACHE_OBJECT_UPDATING:
43286 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
43287 - fscache_stat(&fscache_n_updates_run);
43288 + fscache_stat_unchecked(&fscache_n_updates_run);
43289 fscache_stat(&fscache_n_cop_update_object);
43290 object->cache->ops->update_object(object);
43291 fscache_stat_d(&fscache_n_cop_update_object);
43292 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
43293 spin_lock(&object->lock);
43294 object->state = FSCACHE_OBJECT_DEAD;
43295 spin_unlock(&object->lock);
43296 - fscache_stat(&fscache_n_object_dead);
43297 + fscache_stat_unchecked(&fscache_n_object_dead);
43298 goto terminal_transit;
43300 /* handle the parent cache of this object being withdrawn from
43301 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
43302 spin_lock(&object->lock);
43303 object->state = FSCACHE_OBJECT_DEAD;
43304 spin_unlock(&object->lock);
43305 - fscache_stat(&fscache_n_object_dead);
43306 + fscache_stat_unchecked(&fscache_n_object_dead);
43307 goto terminal_transit;
43309 /* complain about the object being woken up once it is
43310 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
43311 parent->cookie->def->name, cookie->def->name,
43312 object->cache->tag->name);
43314 - fscache_stat(&fscache_n_object_lookups);
43315 + fscache_stat_unchecked(&fscache_n_object_lookups);
43316 fscache_stat(&fscache_n_cop_lookup_object);
43317 ret = object->cache->ops->lookup_object(object);
43318 fscache_stat_d(&fscache_n_cop_lookup_object);
43319 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
43320 if (ret == -ETIMEDOUT) {
43321 /* probably stuck behind another object, so move this one to
43322 * the back of the queue */
43323 - fscache_stat(&fscache_n_object_lookups_timed_out);
43324 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
43325 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
43328 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
43330 spin_lock(&object->lock);
43331 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
43332 - fscache_stat(&fscache_n_object_lookups_negative);
43333 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
43335 /* transit here to allow write requests to begin stacking up
43336 * and read requests to begin returning ENODATA */
43337 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
43338 * result, in which case there may be data available */
43339 spin_lock(&object->lock);
43340 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
43341 - fscache_stat(&fscache_n_object_lookups_positive);
43342 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
43344 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
43346 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
43347 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
43349 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
43350 - fscache_stat(&fscache_n_object_created);
43351 + fscache_stat_unchecked(&fscache_n_object_created);
43353 object->state = FSCACHE_OBJECT_AVAILABLE;
43354 spin_unlock(&object->lock);
43355 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
43356 fscache_enqueue_dependents(object);
43358 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
43359 - fscache_stat(&fscache_n_object_avail);
43360 + fscache_stat_unchecked(&fscache_n_object_avail);
43364 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
43365 enum fscache_checkaux result;
43367 if (!object->cookie->def->check_aux) {
43368 - fscache_stat(&fscache_n_checkaux_none);
43369 + fscache_stat_unchecked(&fscache_n_checkaux_none);
43370 return FSCACHE_CHECKAUX_OKAY;
43373 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
43375 /* entry okay as is */
43376 case FSCACHE_CHECKAUX_OKAY:
43377 - fscache_stat(&fscache_n_checkaux_okay);
43378 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
43381 /* entry requires update */
43382 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
43383 - fscache_stat(&fscache_n_checkaux_update);
43384 + fscache_stat_unchecked(&fscache_n_checkaux_update);
43387 /* entry requires deletion */
43388 case FSCACHE_CHECKAUX_OBSOLETE:
43389 - fscache_stat(&fscache_n_checkaux_obsolete);
43390 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
43394 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
43395 index 30afdfa..2256596 100644
43396 --- a/fs/fscache/operation.c
43397 +++ b/fs/fscache/operation.c
43399 #include <linux/slab.h>
43400 #include "internal.h"
43402 -atomic_t fscache_op_debug_id;
43403 +atomic_unchecked_t fscache_op_debug_id;
43404 EXPORT_SYMBOL(fscache_op_debug_id);
43407 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
43408 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
43409 ASSERTCMP(atomic_read(&op->usage), >, 0);
43411 - fscache_stat(&fscache_n_op_enqueue);
43412 + fscache_stat_unchecked(&fscache_n_op_enqueue);
43413 switch (op->flags & FSCACHE_OP_TYPE) {
43414 case FSCACHE_OP_ASYNC:
43415 _debug("queue async");
43416 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
43417 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
43419 fscache_enqueue_operation(op);
43420 - fscache_stat(&fscache_n_op_run);
43421 + fscache_stat_unchecked(&fscache_n_op_run);
43425 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43426 if (object->n_ops > 1) {
43427 atomic_inc(&op->usage);
43428 list_add_tail(&op->pend_link, &object->pending_ops);
43429 - fscache_stat(&fscache_n_op_pend);
43430 + fscache_stat_unchecked(&fscache_n_op_pend);
43431 } else if (!list_empty(&object->pending_ops)) {
43432 atomic_inc(&op->usage);
43433 list_add_tail(&op->pend_link, &object->pending_ops);
43434 - fscache_stat(&fscache_n_op_pend);
43435 + fscache_stat_unchecked(&fscache_n_op_pend);
43436 fscache_start_operations(object);
43438 ASSERTCMP(object->n_in_progress, ==, 0);
43439 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43440 object->n_exclusive++; /* reads and writes must wait */
43441 atomic_inc(&op->usage);
43442 list_add_tail(&op->pend_link, &object->pending_ops);
43443 - fscache_stat(&fscache_n_op_pend);
43444 + fscache_stat_unchecked(&fscache_n_op_pend);
43447 /* not allowed to submit ops in any other state */
43448 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
43449 if (object->n_exclusive > 0) {
43450 atomic_inc(&op->usage);
43451 list_add_tail(&op->pend_link, &object->pending_ops);
43452 - fscache_stat(&fscache_n_op_pend);
43453 + fscache_stat_unchecked(&fscache_n_op_pend);
43454 } else if (!list_empty(&object->pending_ops)) {
43455 atomic_inc(&op->usage);
43456 list_add_tail(&op->pend_link, &object->pending_ops);
43457 - fscache_stat(&fscache_n_op_pend);
43458 + fscache_stat_unchecked(&fscache_n_op_pend);
43459 fscache_start_operations(object);
43461 ASSERTCMP(object->n_exclusive, ==, 0);
43462 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
43464 atomic_inc(&op->usage);
43465 list_add_tail(&op->pend_link, &object->pending_ops);
43466 - fscache_stat(&fscache_n_op_pend);
43467 + fscache_stat_unchecked(&fscache_n_op_pend);
43469 } else if (object->state == FSCACHE_OBJECT_DYING ||
43470 object->state == FSCACHE_OBJECT_LC_DYING ||
43471 object->state == FSCACHE_OBJECT_WITHDRAWING) {
43472 - fscache_stat(&fscache_n_op_rejected);
43473 + fscache_stat_unchecked(&fscache_n_op_rejected);
43475 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
43476 fscache_report_unexpected_submission(object, op, ostate);
43477 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
43480 if (!list_empty(&op->pend_link)) {
43481 - fscache_stat(&fscache_n_op_cancelled);
43482 + fscache_stat_unchecked(&fscache_n_op_cancelled);
43483 list_del_init(&op->pend_link);
43485 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
43486 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
43487 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
43490 - fscache_stat(&fscache_n_op_release);
43491 + fscache_stat_unchecked(&fscache_n_op_release);
43495 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
43496 * lock, and defer it otherwise */
43497 if (!spin_trylock(&object->lock)) {
43498 _debug("defer put");
43499 - fscache_stat(&fscache_n_op_deferred_release);
43500 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
43502 cache = object->cache;
43503 spin_lock(&cache->op_gc_list_lock);
43504 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
43506 _debug("GC DEFERRED REL OBJ%x OP%x",
43507 object->debug_id, op->debug_id);
43508 - fscache_stat(&fscache_n_op_gc);
43509 + fscache_stat_unchecked(&fscache_n_op_gc);
43511 ASSERTCMP(atomic_read(&op->usage), ==, 0);
43513 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
43514 index 3f7a59b..cf196cc 100644
43515 --- a/fs/fscache/page.c
43516 +++ b/fs/fscache/page.c
43517 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43518 val = radix_tree_lookup(&cookie->stores, page->index);
43521 - fscache_stat(&fscache_n_store_vmscan_not_storing);
43522 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
43523 __fscache_uncache_page(cookie, page);
43526 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43527 spin_unlock(&cookie->stores_lock);
43530 - fscache_stat(&fscache_n_store_vmscan_cancelled);
43531 - fscache_stat(&fscache_n_store_radix_deletes);
43532 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
43533 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43534 ASSERTCMP(xpage, ==, page);
43536 - fscache_stat(&fscache_n_store_vmscan_gone);
43537 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
43540 wake_up_bit(&cookie->flags, 0);
43541 @@ -107,7 +107,7 @@ page_busy:
43542 /* we might want to wait here, but that could deadlock the allocator as
43543 * the work threads writing to the cache may all end up sleeping
43544 * on memory allocation */
43545 - fscache_stat(&fscache_n_store_vmscan_busy);
43546 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
43549 EXPORT_SYMBOL(__fscache_maybe_release_page);
43550 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
43551 FSCACHE_COOKIE_STORING_TAG);
43552 if (!radix_tree_tag_get(&cookie->stores, page->index,
43553 FSCACHE_COOKIE_PENDING_TAG)) {
43554 - fscache_stat(&fscache_n_store_radix_deletes);
43555 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43556 xpage = radix_tree_delete(&cookie->stores, page->index);
43558 spin_unlock(&cookie->stores_lock);
43559 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
43561 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
43563 - fscache_stat(&fscache_n_attr_changed_calls);
43564 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
43566 if (fscache_object_is_active(object)) {
43567 fscache_stat(&fscache_n_cop_attr_changed);
43568 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43570 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43572 - fscache_stat(&fscache_n_attr_changed);
43573 + fscache_stat_unchecked(&fscache_n_attr_changed);
43575 op = kzalloc(sizeof(*op), GFP_KERNEL);
43577 - fscache_stat(&fscache_n_attr_changed_nomem);
43578 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
43579 _leave(" = -ENOMEM");
43582 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43583 if (fscache_submit_exclusive_op(object, op) < 0)
43585 spin_unlock(&cookie->lock);
43586 - fscache_stat(&fscache_n_attr_changed_ok);
43587 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
43588 fscache_put_operation(op);
43591 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43593 spin_unlock(&cookie->lock);
43595 - fscache_stat(&fscache_n_attr_changed_nobufs);
43596 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
43597 _leave(" = %d", -ENOBUFS);
43600 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
43601 /* allocate a retrieval operation and attempt to submit it */
43602 op = kzalloc(sizeof(*op), GFP_NOIO);
43604 - fscache_stat(&fscache_n_retrievals_nomem);
43605 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43609 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43613 - fscache_stat(&fscache_n_retrievals_wait);
43614 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
43617 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
43618 fscache_wait_bit_interruptible,
43619 TASK_INTERRUPTIBLE) != 0) {
43620 - fscache_stat(&fscache_n_retrievals_intr);
43621 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43622 _leave(" = -ERESTARTSYS");
43623 return -ERESTARTSYS;
43625 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43627 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43628 struct fscache_retrieval *op,
43629 - atomic_t *stat_op_waits,
43630 - atomic_t *stat_object_dead)
43631 + atomic_unchecked_t *stat_op_waits,
43632 + atomic_unchecked_t *stat_object_dead)
43636 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43637 goto check_if_dead;
43640 - fscache_stat(stat_op_waits);
43641 + fscache_stat_unchecked(stat_op_waits);
43642 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
43643 fscache_wait_bit_interruptible,
43644 TASK_INTERRUPTIBLE) < 0) {
43645 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43648 if (unlikely(fscache_object_is_dead(object))) {
43649 - fscache_stat(stat_object_dead);
43650 + fscache_stat_unchecked(stat_object_dead);
43654 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43656 _enter("%p,%p,,,", cookie, page);
43658 - fscache_stat(&fscache_n_retrievals);
43659 + fscache_stat_unchecked(&fscache_n_retrievals);
43661 if (hlist_empty(&cookie->backing_objects))
43663 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43664 goto nobufs_unlock;
43665 spin_unlock(&cookie->lock);
43667 - fscache_stat(&fscache_n_retrieval_ops);
43668 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43670 /* pin the netfs read context in case we need to do the actual netfs
43671 * read because we've encountered a cache read failure */
43672 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43675 if (ret == -ENOMEM)
43676 - fscache_stat(&fscache_n_retrievals_nomem);
43677 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43678 else if (ret == -ERESTARTSYS)
43679 - fscache_stat(&fscache_n_retrievals_intr);
43680 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43681 else if (ret == -ENODATA)
43682 - fscache_stat(&fscache_n_retrievals_nodata);
43683 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43685 - fscache_stat(&fscache_n_retrievals_nobufs);
43686 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43688 - fscache_stat(&fscache_n_retrievals_ok);
43689 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43691 fscache_put_retrieval(op);
43692 _leave(" = %d", ret);
43693 @@ -429,7 +429,7 @@ nobufs_unlock:
43694 spin_unlock(&cookie->lock);
43697 - fscache_stat(&fscache_n_retrievals_nobufs);
43698 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43699 _leave(" = -ENOBUFS");
43702 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43704 _enter("%p,,%d,,,", cookie, *nr_pages);
43706 - fscache_stat(&fscache_n_retrievals);
43707 + fscache_stat_unchecked(&fscache_n_retrievals);
43709 if (hlist_empty(&cookie->backing_objects))
43711 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43712 goto nobufs_unlock;
43713 spin_unlock(&cookie->lock);
43715 - fscache_stat(&fscache_n_retrieval_ops);
43716 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43718 /* pin the netfs read context in case we need to do the actual netfs
43719 * read because we've encountered a cache read failure */
43720 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43723 if (ret == -ENOMEM)
43724 - fscache_stat(&fscache_n_retrievals_nomem);
43725 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43726 else if (ret == -ERESTARTSYS)
43727 - fscache_stat(&fscache_n_retrievals_intr);
43728 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43729 else if (ret == -ENODATA)
43730 - fscache_stat(&fscache_n_retrievals_nodata);
43731 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43733 - fscache_stat(&fscache_n_retrievals_nobufs);
43734 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43736 - fscache_stat(&fscache_n_retrievals_ok);
43737 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43739 fscache_put_retrieval(op);
43740 _leave(" = %d", ret);
43741 @@ -545,7 +545,7 @@ nobufs_unlock:
43742 spin_unlock(&cookie->lock);
43745 - fscache_stat(&fscache_n_retrievals_nobufs);
43746 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43747 _leave(" = -ENOBUFS");
43750 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43752 _enter("%p,%p,,,", cookie, page);
43754 - fscache_stat(&fscache_n_allocs);
43755 + fscache_stat_unchecked(&fscache_n_allocs);
43757 if (hlist_empty(&cookie->backing_objects))
43759 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43760 goto nobufs_unlock;
43761 spin_unlock(&cookie->lock);
43763 - fscache_stat(&fscache_n_alloc_ops);
43764 + fscache_stat_unchecked(&fscache_n_alloc_ops);
43766 ret = fscache_wait_for_retrieval_activation(
43768 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43771 if (ret == -ERESTARTSYS)
43772 - fscache_stat(&fscache_n_allocs_intr);
43773 + fscache_stat_unchecked(&fscache_n_allocs_intr);
43775 - fscache_stat(&fscache_n_allocs_nobufs);
43776 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43778 - fscache_stat(&fscache_n_allocs_ok);
43779 + fscache_stat_unchecked(&fscache_n_allocs_ok);
43781 fscache_put_retrieval(op);
43782 _leave(" = %d", ret);
43783 @@ -625,7 +625,7 @@ nobufs_unlock:
43784 spin_unlock(&cookie->lock);
43787 - fscache_stat(&fscache_n_allocs_nobufs);
43788 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43789 _leave(" = -ENOBUFS");
43792 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43794 spin_lock(&cookie->stores_lock);
43796 - fscache_stat(&fscache_n_store_calls);
43797 + fscache_stat_unchecked(&fscache_n_store_calls);
43799 /* find a page to store */
43801 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43803 _debug("gang %d [%lx]", n, page->index);
43804 if (page->index > op->store_limit) {
43805 - fscache_stat(&fscache_n_store_pages_over_limit);
43806 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
43810 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43811 spin_unlock(&cookie->stores_lock);
43812 spin_unlock(&object->lock);
43814 - fscache_stat(&fscache_n_store_pages);
43815 + fscache_stat_unchecked(&fscache_n_store_pages);
43816 fscache_stat(&fscache_n_cop_write_page);
43817 ret = object->cache->ops->write_page(op, page);
43818 fscache_stat_d(&fscache_n_cop_write_page);
43819 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43820 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43821 ASSERT(PageFsCache(page));
43823 - fscache_stat(&fscache_n_stores);
43824 + fscache_stat_unchecked(&fscache_n_stores);
43826 op = kzalloc(sizeof(*op), GFP_NOIO);
43828 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43829 spin_unlock(&cookie->stores_lock);
43830 spin_unlock(&object->lock);
43832 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
43833 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
43834 op->store_limit = object->store_limit;
43836 if (fscache_submit_op(object, &op->op) < 0)
43837 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43839 spin_unlock(&cookie->lock);
43840 radix_tree_preload_end();
43841 - fscache_stat(&fscache_n_store_ops);
43842 - fscache_stat(&fscache_n_stores_ok);
43843 + fscache_stat_unchecked(&fscache_n_store_ops);
43844 + fscache_stat_unchecked(&fscache_n_stores_ok);
43846 /* the work queue now carries its own ref on the object */
43847 fscache_put_operation(&op->op);
43848 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43852 - fscache_stat(&fscache_n_stores_again);
43853 + fscache_stat_unchecked(&fscache_n_stores_again);
43855 spin_unlock(&cookie->stores_lock);
43856 spin_unlock(&object->lock);
43857 spin_unlock(&cookie->lock);
43858 radix_tree_preload_end();
43860 - fscache_stat(&fscache_n_stores_ok);
43861 + fscache_stat_unchecked(&fscache_n_stores_ok);
43865 @@ -851,14 +851,14 @@ nobufs:
43866 spin_unlock(&cookie->lock);
43867 radix_tree_preload_end();
43869 - fscache_stat(&fscache_n_stores_nobufs);
43870 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
43871 _leave(" = -ENOBUFS");
43877 - fscache_stat(&fscache_n_stores_oom);
43878 + fscache_stat_unchecked(&fscache_n_stores_oom);
43879 _leave(" = -ENOMEM");
43882 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
43883 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43884 ASSERTCMP(page, !=, NULL);
43886 - fscache_stat(&fscache_n_uncaches);
43887 + fscache_stat_unchecked(&fscache_n_uncaches);
43889 /* cache withdrawal may beat us to it */
43890 if (!PageFsCache(page))
43891 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
43892 unsigned long loop;
43894 #ifdef CONFIG_FSCACHE_STATS
43895 - atomic_add(pagevec->nr, &fscache_n_marks);
43896 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
43899 for (loop = 0; loop < pagevec->nr; loop++) {
43900 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
43901 index 4765190..2a067f2 100644
43902 --- a/fs/fscache/stats.c
43903 +++ b/fs/fscache/stats.c
43904 @@ -18,95 +18,95 @@
43906 * operation counters
43908 -atomic_t fscache_n_op_pend;
43909 -atomic_t fscache_n_op_run;
43910 -atomic_t fscache_n_op_enqueue;
43911 -atomic_t fscache_n_op_requeue;
43912 -atomic_t fscache_n_op_deferred_release;
43913 -atomic_t fscache_n_op_release;
43914 -atomic_t fscache_n_op_gc;
43915 -atomic_t fscache_n_op_cancelled;
43916 -atomic_t fscache_n_op_rejected;
43917 +atomic_unchecked_t fscache_n_op_pend;
43918 +atomic_unchecked_t fscache_n_op_run;
43919 +atomic_unchecked_t fscache_n_op_enqueue;
43920 +atomic_unchecked_t fscache_n_op_requeue;
43921 +atomic_unchecked_t fscache_n_op_deferred_release;
43922 +atomic_unchecked_t fscache_n_op_release;
43923 +atomic_unchecked_t fscache_n_op_gc;
43924 +atomic_unchecked_t fscache_n_op_cancelled;
43925 +atomic_unchecked_t fscache_n_op_rejected;
43927 -atomic_t fscache_n_attr_changed;
43928 -atomic_t fscache_n_attr_changed_ok;
43929 -atomic_t fscache_n_attr_changed_nobufs;
43930 -atomic_t fscache_n_attr_changed_nomem;
43931 -atomic_t fscache_n_attr_changed_calls;
43932 +atomic_unchecked_t fscache_n_attr_changed;
43933 +atomic_unchecked_t fscache_n_attr_changed_ok;
43934 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
43935 +atomic_unchecked_t fscache_n_attr_changed_nomem;
43936 +atomic_unchecked_t fscache_n_attr_changed_calls;
43938 -atomic_t fscache_n_allocs;
43939 -atomic_t fscache_n_allocs_ok;
43940 -atomic_t fscache_n_allocs_wait;
43941 -atomic_t fscache_n_allocs_nobufs;
43942 -atomic_t fscache_n_allocs_intr;
43943 -atomic_t fscache_n_allocs_object_dead;
43944 -atomic_t fscache_n_alloc_ops;
43945 -atomic_t fscache_n_alloc_op_waits;
43946 +atomic_unchecked_t fscache_n_allocs;
43947 +atomic_unchecked_t fscache_n_allocs_ok;
43948 +atomic_unchecked_t fscache_n_allocs_wait;
43949 +atomic_unchecked_t fscache_n_allocs_nobufs;
43950 +atomic_unchecked_t fscache_n_allocs_intr;
43951 +atomic_unchecked_t fscache_n_allocs_object_dead;
43952 +atomic_unchecked_t fscache_n_alloc_ops;
43953 +atomic_unchecked_t fscache_n_alloc_op_waits;
43955 -atomic_t fscache_n_retrievals;
43956 -atomic_t fscache_n_retrievals_ok;
43957 -atomic_t fscache_n_retrievals_wait;
43958 -atomic_t fscache_n_retrievals_nodata;
43959 -atomic_t fscache_n_retrievals_nobufs;
43960 -atomic_t fscache_n_retrievals_intr;
43961 -atomic_t fscache_n_retrievals_nomem;
43962 -atomic_t fscache_n_retrievals_object_dead;
43963 -atomic_t fscache_n_retrieval_ops;
43964 -atomic_t fscache_n_retrieval_op_waits;
43965 +atomic_unchecked_t fscache_n_retrievals;
43966 +atomic_unchecked_t fscache_n_retrievals_ok;
43967 +atomic_unchecked_t fscache_n_retrievals_wait;
43968 +atomic_unchecked_t fscache_n_retrievals_nodata;
43969 +atomic_unchecked_t fscache_n_retrievals_nobufs;
43970 +atomic_unchecked_t fscache_n_retrievals_intr;
43971 +atomic_unchecked_t fscache_n_retrievals_nomem;
43972 +atomic_unchecked_t fscache_n_retrievals_object_dead;
43973 +atomic_unchecked_t fscache_n_retrieval_ops;
43974 +atomic_unchecked_t fscache_n_retrieval_op_waits;
43976 -atomic_t fscache_n_stores;
43977 -atomic_t fscache_n_stores_ok;
43978 -atomic_t fscache_n_stores_again;
43979 -atomic_t fscache_n_stores_nobufs;
43980 -atomic_t fscache_n_stores_oom;
43981 -atomic_t fscache_n_store_ops;
43982 -atomic_t fscache_n_store_calls;
43983 -atomic_t fscache_n_store_pages;
43984 -atomic_t fscache_n_store_radix_deletes;
43985 -atomic_t fscache_n_store_pages_over_limit;
43986 +atomic_unchecked_t fscache_n_stores;
43987 +atomic_unchecked_t fscache_n_stores_ok;
43988 +atomic_unchecked_t fscache_n_stores_again;
43989 +atomic_unchecked_t fscache_n_stores_nobufs;
43990 +atomic_unchecked_t fscache_n_stores_oom;
43991 +atomic_unchecked_t fscache_n_store_ops;
43992 +atomic_unchecked_t fscache_n_store_calls;
43993 +atomic_unchecked_t fscache_n_store_pages;
43994 +atomic_unchecked_t fscache_n_store_radix_deletes;
43995 +atomic_unchecked_t fscache_n_store_pages_over_limit;
43997 -atomic_t fscache_n_store_vmscan_not_storing;
43998 -atomic_t fscache_n_store_vmscan_gone;
43999 -atomic_t fscache_n_store_vmscan_busy;
44000 -atomic_t fscache_n_store_vmscan_cancelled;
44001 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44002 +atomic_unchecked_t fscache_n_store_vmscan_gone;
44003 +atomic_unchecked_t fscache_n_store_vmscan_busy;
44004 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44006 -atomic_t fscache_n_marks;
44007 -atomic_t fscache_n_uncaches;
44008 +atomic_unchecked_t fscache_n_marks;
44009 +atomic_unchecked_t fscache_n_uncaches;
44011 -atomic_t fscache_n_acquires;
44012 -atomic_t fscache_n_acquires_null;
44013 -atomic_t fscache_n_acquires_no_cache;
44014 -atomic_t fscache_n_acquires_ok;
44015 -atomic_t fscache_n_acquires_nobufs;
44016 -atomic_t fscache_n_acquires_oom;
44017 +atomic_unchecked_t fscache_n_acquires;
44018 +atomic_unchecked_t fscache_n_acquires_null;
44019 +atomic_unchecked_t fscache_n_acquires_no_cache;
44020 +atomic_unchecked_t fscache_n_acquires_ok;
44021 +atomic_unchecked_t fscache_n_acquires_nobufs;
44022 +atomic_unchecked_t fscache_n_acquires_oom;
44024 -atomic_t fscache_n_updates;
44025 -atomic_t fscache_n_updates_null;
44026 -atomic_t fscache_n_updates_run;
44027 +atomic_unchecked_t fscache_n_updates;
44028 +atomic_unchecked_t fscache_n_updates_null;
44029 +atomic_unchecked_t fscache_n_updates_run;
44031 -atomic_t fscache_n_relinquishes;
44032 -atomic_t fscache_n_relinquishes_null;
44033 -atomic_t fscache_n_relinquishes_waitcrt;
44034 -atomic_t fscache_n_relinquishes_retire;
44035 +atomic_unchecked_t fscache_n_relinquishes;
44036 +atomic_unchecked_t fscache_n_relinquishes_null;
44037 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44038 +atomic_unchecked_t fscache_n_relinquishes_retire;
44040 -atomic_t fscache_n_cookie_index;
44041 -atomic_t fscache_n_cookie_data;
44042 -atomic_t fscache_n_cookie_special;
44043 +atomic_unchecked_t fscache_n_cookie_index;
44044 +atomic_unchecked_t fscache_n_cookie_data;
44045 +atomic_unchecked_t fscache_n_cookie_special;
44047 -atomic_t fscache_n_object_alloc;
44048 -atomic_t fscache_n_object_no_alloc;
44049 -atomic_t fscache_n_object_lookups;
44050 -atomic_t fscache_n_object_lookups_negative;
44051 -atomic_t fscache_n_object_lookups_positive;
44052 -atomic_t fscache_n_object_lookups_timed_out;
44053 -atomic_t fscache_n_object_created;
44054 -atomic_t fscache_n_object_avail;
44055 -atomic_t fscache_n_object_dead;
44056 +atomic_unchecked_t fscache_n_object_alloc;
44057 +atomic_unchecked_t fscache_n_object_no_alloc;
44058 +atomic_unchecked_t fscache_n_object_lookups;
44059 +atomic_unchecked_t fscache_n_object_lookups_negative;
44060 +atomic_unchecked_t fscache_n_object_lookups_positive;
44061 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
44062 +atomic_unchecked_t fscache_n_object_created;
44063 +atomic_unchecked_t fscache_n_object_avail;
44064 +atomic_unchecked_t fscache_n_object_dead;
44066 -atomic_t fscache_n_checkaux_none;
44067 -atomic_t fscache_n_checkaux_okay;
44068 -atomic_t fscache_n_checkaux_update;
44069 -atomic_t fscache_n_checkaux_obsolete;
44070 +atomic_unchecked_t fscache_n_checkaux_none;
44071 +atomic_unchecked_t fscache_n_checkaux_okay;
44072 +atomic_unchecked_t fscache_n_checkaux_update;
44073 +atomic_unchecked_t fscache_n_checkaux_obsolete;
44075 atomic_t fscache_n_cop_alloc_object;
44076 atomic_t fscache_n_cop_lookup_object;
44077 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
44078 seq_puts(m, "FS-Cache statistics\n");
44080 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
44081 - atomic_read(&fscache_n_cookie_index),
44082 - atomic_read(&fscache_n_cookie_data),
44083 - atomic_read(&fscache_n_cookie_special));
44084 + atomic_read_unchecked(&fscache_n_cookie_index),
44085 + atomic_read_unchecked(&fscache_n_cookie_data),
44086 + atomic_read_unchecked(&fscache_n_cookie_special));
44088 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
44089 - atomic_read(&fscache_n_object_alloc),
44090 - atomic_read(&fscache_n_object_no_alloc),
44091 - atomic_read(&fscache_n_object_avail),
44092 - atomic_read(&fscache_n_object_dead));
44093 + atomic_read_unchecked(&fscache_n_object_alloc),
44094 + atomic_read_unchecked(&fscache_n_object_no_alloc),
44095 + atomic_read_unchecked(&fscache_n_object_avail),
44096 + atomic_read_unchecked(&fscache_n_object_dead));
44097 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
44098 - atomic_read(&fscache_n_checkaux_none),
44099 - atomic_read(&fscache_n_checkaux_okay),
44100 - atomic_read(&fscache_n_checkaux_update),
44101 - atomic_read(&fscache_n_checkaux_obsolete));
44102 + atomic_read_unchecked(&fscache_n_checkaux_none),
44103 + atomic_read_unchecked(&fscache_n_checkaux_okay),
44104 + atomic_read_unchecked(&fscache_n_checkaux_update),
44105 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
44107 seq_printf(m, "Pages : mrk=%u unc=%u\n",
44108 - atomic_read(&fscache_n_marks),
44109 - atomic_read(&fscache_n_uncaches));
44110 + atomic_read_unchecked(&fscache_n_marks),
44111 + atomic_read_unchecked(&fscache_n_uncaches));
44113 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
44115 - atomic_read(&fscache_n_acquires),
44116 - atomic_read(&fscache_n_acquires_null),
44117 - atomic_read(&fscache_n_acquires_no_cache),
44118 - atomic_read(&fscache_n_acquires_ok),
44119 - atomic_read(&fscache_n_acquires_nobufs),
44120 - atomic_read(&fscache_n_acquires_oom));
44121 + atomic_read_unchecked(&fscache_n_acquires),
44122 + atomic_read_unchecked(&fscache_n_acquires_null),
44123 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
44124 + atomic_read_unchecked(&fscache_n_acquires_ok),
44125 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
44126 + atomic_read_unchecked(&fscache_n_acquires_oom));
44128 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
44129 - atomic_read(&fscache_n_object_lookups),
44130 - atomic_read(&fscache_n_object_lookups_negative),
44131 - atomic_read(&fscache_n_object_lookups_positive),
44132 - atomic_read(&fscache_n_object_created),
44133 - atomic_read(&fscache_n_object_lookups_timed_out));
44134 + atomic_read_unchecked(&fscache_n_object_lookups),
44135 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
44136 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
44137 + atomic_read_unchecked(&fscache_n_object_created),
44138 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
44140 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
44141 - atomic_read(&fscache_n_updates),
44142 - atomic_read(&fscache_n_updates_null),
44143 - atomic_read(&fscache_n_updates_run));
44144 + atomic_read_unchecked(&fscache_n_updates),
44145 + atomic_read_unchecked(&fscache_n_updates_null),
44146 + atomic_read_unchecked(&fscache_n_updates_run));
44148 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
44149 - atomic_read(&fscache_n_relinquishes),
44150 - atomic_read(&fscache_n_relinquishes_null),
44151 - atomic_read(&fscache_n_relinquishes_waitcrt),
44152 - atomic_read(&fscache_n_relinquishes_retire));
44153 + atomic_read_unchecked(&fscache_n_relinquishes),
44154 + atomic_read_unchecked(&fscache_n_relinquishes_null),
44155 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
44156 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
44158 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
44159 - atomic_read(&fscache_n_attr_changed),
44160 - atomic_read(&fscache_n_attr_changed_ok),
44161 - atomic_read(&fscache_n_attr_changed_nobufs),
44162 - atomic_read(&fscache_n_attr_changed_nomem),
44163 - atomic_read(&fscache_n_attr_changed_calls));
44164 + atomic_read_unchecked(&fscache_n_attr_changed),
44165 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
44166 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
44167 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
44168 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
44170 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
44171 - atomic_read(&fscache_n_allocs),
44172 - atomic_read(&fscache_n_allocs_ok),
44173 - atomic_read(&fscache_n_allocs_wait),
44174 - atomic_read(&fscache_n_allocs_nobufs),
44175 - atomic_read(&fscache_n_allocs_intr));
44176 + atomic_read_unchecked(&fscache_n_allocs),
44177 + atomic_read_unchecked(&fscache_n_allocs_ok),
44178 + atomic_read_unchecked(&fscache_n_allocs_wait),
44179 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
44180 + atomic_read_unchecked(&fscache_n_allocs_intr));
44181 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
44182 - atomic_read(&fscache_n_alloc_ops),
44183 - atomic_read(&fscache_n_alloc_op_waits),
44184 - atomic_read(&fscache_n_allocs_object_dead));
44185 + atomic_read_unchecked(&fscache_n_alloc_ops),
44186 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
44187 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
44189 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
44190 " int=%u oom=%u\n",
44191 - atomic_read(&fscache_n_retrievals),
44192 - atomic_read(&fscache_n_retrievals_ok),
44193 - atomic_read(&fscache_n_retrievals_wait),
44194 - atomic_read(&fscache_n_retrievals_nodata),
44195 - atomic_read(&fscache_n_retrievals_nobufs),
44196 - atomic_read(&fscache_n_retrievals_intr),
44197 - atomic_read(&fscache_n_retrievals_nomem));
44198 + atomic_read_unchecked(&fscache_n_retrievals),
44199 + atomic_read_unchecked(&fscache_n_retrievals_ok),
44200 + atomic_read_unchecked(&fscache_n_retrievals_wait),
44201 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
44202 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
44203 + atomic_read_unchecked(&fscache_n_retrievals_intr),
44204 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
44205 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
44206 - atomic_read(&fscache_n_retrieval_ops),
44207 - atomic_read(&fscache_n_retrieval_op_waits),
44208 - atomic_read(&fscache_n_retrievals_object_dead));
44209 + atomic_read_unchecked(&fscache_n_retrieval_ops),
44210 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
44211 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
44213 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
44214 - atomic_read(&fscache_n_stores),
44215 - atomic_read(&fscache_n_stores_ok),
44216 - atomic_read(&fscache_n_stores_again),
44217 - atomic_read(&fscache_n_stores_nobufs),
44218 - atomic_read(&fscache_n_stores_oom));
44219 + atomic_read_unchecked(&fscache_n_stores),
44220 + atomic_read_unchecked(&fscache_n_stores_ok),
44221 + atomic_read_unchecked(&fscache_n_stores_again),
44222 + atomic_read_unchecked(&fscache_n_stores_nobufs),
44223 + atomic_read_unchecked(&fscache_n_stores_oom));
44224 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
44225 - atomic_read(&fscache_n_store_ops),
44226 - atomic_read(&fscache_n_store_calls),
44227 - atomic_read(&fscache_n_store_pages),
44228 - atomic_read(&fscache_n_store_radix_deletes),
44229 - atomic_read(&fscache_n_store_pages_over_limit));
44230 + atomic_read_unchecked(&fscache_n_store_ops),
44231 + atomic_read_unchecked(&fscache_n_store_calls),
44232 + atomic_read_unchecked(&fscache_n_store_pages),
44233 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
44234 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
44236 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
44237 - atomic_read(&fscache_n_store_vmscan_not_storing),
44238 - atomic_read(&fscache_n_store_vmscan_gone),
44239 - atomic_read(&fscache_n_store_vmscan_busy),
44240 - atomic_read(&fscache_n_store_vmscan_cancelled));
44241 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
44242 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
44243 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
44244 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
44246 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
44247 - atomic_read(&fscache_n_op_pend),
44248 - atomic_read(&fscache_n_op_run),
44249 - atomic_read(&fscache_n_op_enqueue),
44250 - atomic_read(&fscache_n_op_cancelled),
44251 - atomic_read(&fscache_n_op_rejected));
44252 + atomic_read_unchecked(&fscache_n_op_pend),
44253 + atomic_read_unchecked(&fscache_n_op_run),
44254 + atomic_read_unchecked(&fscache_n_op_enqueue),
44255 + atomic_read_unchecked(&fscache_n_op_cancelled),
44256 + atomic_read_unchecked(&fscache_n_op_rejected));
44257 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
44258 - atomic_read(&fscache_n_op_deferred_release),
44259 - atomic_read(&fscache_n_op_release),
44260 - atomic_read(&fscache_n_op_gc));
44261 + atomic_read_unchecked(&fscache_n_op_deferred_release),
44262 + atomic_read_unchecked(&fscache_n_op_release),
44263 + atomic_read_unchecked(&fscache_n_op_gc));
44265 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
44266 atomic_read(&fscache_n_cop_alloc_object),
44267 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
44268 index 3426521..3b75162 100644
44269 --- a/fs/fuse/cuse.c
44270 +++ b/fs/fuse/cuse.c
44271 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
44272 INIT_LIST_HEAD(&cuse_conntbl[i]);
44274 /* inherit and extend fuse_dev_operations */
44275 - cuse_channel_fops = fuse_dev_operations;
44276 - cuse_channel_fops.owner = THIS_MODULE;
44277 - cuse_channel_fops.open = cuse_channel_open;
44278 - cuse_channel_fops.release = cuse_channel_release;
44279 + pax_open_kernel();
44280 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
44281 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
44282 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
44283 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
44284 + pax_close_kernel();
44286 cuse_class = class_create(THIS_MODULE, "cuse");
44287 if (IS_ERR(cuse_class))
44288 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
44289 index 2aaf3ea..8e50863 100644
44290 --- a/fs/fuse/dev.c
44291 +++ b/fs/fuse/dev.c
44292 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
44296 - if (!pipe->readers) {
44297 + if (!atomic_read(&pipe->readers)) {
44298 send_sig(SIGPIPE, current, 0);
44301 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
44302 index 9f63e49..d8a64c0 100644
44303 --- a/fs/fuse/dir.c
44304 +++ b/fs/fuse/dir.c
44305 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
44309 -static void free_link(char *link)
44310 +static void free_link(const char *link)
44313 free_page((unsigned long) link);
44314 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
44315 index cfd4959..a780959 100644
44316 --- a/fs/gfs2/inode.c
44317 +++ b/fs/gfs2/inode.c
44318 @@ -1490,7 +1490,7 @@ out:
44320 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44322 - char *s = nd_get_link(nd);
44323 + const char *s = nd_get_link(nd);
44327 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
44328 index 0be5a78..9cfb853 100644
44329 --- a/fs/hugetlbfs/inode.c
44330 +++ b/fs/hugetlbfs/inode.c
44331 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
44332 .kill_sb = kill_litter_super,
44335 -static struct vfsmount *hugetlbfs_vfsmount;
44336 +struct vfsmount *hugetlbfs_vfsmount;
44338 static int can_do_hugetlb_shm(void)
44340 diff --git a/fs/inode.c b/fs/inode.c
44341 index ee4e66b..0451521 100644
44344 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
44347 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
44348 - static atomic_t shared_last_ino;
44349 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
44350 + static atomic_unchecked_t shared_last_ino;
44351 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
44353 res = next - LAST_INO_BATCH;
44355 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
44356 index e513f19..2ab1351 100644
44357 --- a/fs/jffs2/erase.c
44358 +++ b/fs/jffs2/erase.c
44359 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
44360 struct jffs2_unknown_node marker = {
44361 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
44362 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
44363 - .totlen = cpu_to_je32(c->cleanmarker_size)
44364 + .totlen = cpu_to_je32(c->cleanmarker_size),
44365 + .hdr_crc = cpu_to_je32(0)
44368 jffs2_prealloc_raw_node_refs(c, jeb, 1);
44369 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
44370 index b09e51d..e482afa 100644
44371 --- a/fs/jffs2/wbuf.c
44372 +++ b/fs/jffs2/wbuf.c
44373 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
44375 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
44376 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
44377 - .totlen = constant_cpu_to_je32(8)
44378 + .totlen = constant_cpu_to_je32(8),
44379 + .hdr_crc = constant_cpu_to_je32(0)
44383 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
44384 index a44eff0..462e07d 100644
44385 --- a/fs/jfs/super.c
44386 +++ b/fs/jfs/super.c
44387 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
44390 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
44391 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
44392 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
44394 if (jfs_inode_cachep == NULL)
44396 diff --git a/fs/libfs.c b/fs/libfs.c
44397 index f6d411e..e82a08d 100644
44400 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44402 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
44403 struct dentry *next;
44404 + char d_name[sizeof(next->d_iname)];
44405 + const unsigned char *name;
44407 next = list_entry(p, struct dentry, d_u.d_child);
44408 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
44409 if (!simple_positive(next)) {
44410 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44412 spin_unlock(&next->d_lock);
44413 spin_unlock(&dentry->d_lock);
44414 - if (filldir(dirent, next->d_name.name,
44415 + name = next->d_name.name;
44416 + if (name == next->d_iname) {
44417 + memcpy(d_name, name, next->d_name.len);
44420 + if (filldir(dirent, name,
44421 next->d_name.len, filp->f_pos,
44422 next->d_inode->i_ino,
44423 dt_type(next->d_inode)) < 0)
44424 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
44425 index 8392cb8..80d6193 100644
44426 --- a/fs/lockd/clntproc.c
44427 +++ b/fs/lockd/clntproc.c
44428 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
44430 * Cookie counter for NLM requests
44432 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
44433 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
44435 void nlmclnt_next_cookie(struct nlm_cookie *c)
44437 - u32 cookie = atomic_inc_return(&nlm_cookie);
44438 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
44440 memcpy(c->data, &cookie, 4);
44442 diff --git a/fs/locks.c b/fs/locks.c
44443 index 637694b..f84a121 100644
44446 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
44449 if (filp->f_op && filp->f_op->flock) {
44450 - struct file_lock fl = {
44451 + struct file_lock flock = {
44452 .fl_pid = current->tgid,
44454 .fl_flags = FL_FLOCK,
44455 .fl_type = F_UNLCK,
44456 .fl_end = OFFSET_MAX,
44458 - filp->f_op->flock(filp, F_SETLKW, &fl);
44459 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
44460 - fl.fl_ops->fl_release_private(&fl);
44461 + filp->f_op->flock(filp, F_SETLKW, &flock);
44462 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
44463 + flock.fl_ops->fl_release_private(&flock);
44467 diff --git a/fs/namei.c b/fs/namei.c
44468 index 744e942..24ef47f 100644
44471 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
44472 if (ret != -EACCES)
44475 +#ifdef CONFIG_GRKERNSEC
44476 + /* we'll block if we have to log due to a denied capability use */
44477 + if (mask & MAY_NOT_BLOCK)
44481 if (S_ISDIR(inode->i_mode)) {
44482 /* DACs are overridable for directories */
44483 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44485 if (!(mask & MAY_WRITE))
44486 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44487 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44488 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44490 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44495 + * Searching includes executable on directories, else just read.
44497 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44498 + if (mask == MAY_READ)
44499 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44500 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44504 * Read/write DACs are always overridable.
44505 * Executable DACs are overridable when there is
44506 * at least one exec bit set.
44507 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
44508 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44512 - * Searching includes executable on directories, else just read.
44514 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44515 - if (mask == MAY_READ)
44516 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44522 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
44526 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
44527 + dentry->d_inode, dentry, nd->path.mnt)) {
44529 + *p = ERR_PTR(error); /* no ->put_link(), please */
44530 + path_put(&nd->path);
44534 nd->last_type = LAST_BIND;
44535 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
44536 error = PTR_ERR(*p);
44538 - char *s = nd_get_link(nd);
44539 + const char *s = nd_get_link(nd);
44542 error = __vfs_follow_link(nd, s);
44543 @@ -1624,6 +1640,21 @@ static int path_lookupat(int dfd, const char *name,
44545 err = complete_walk(nd);
44547 + if (!(nd->flags & LOOKUP_PARENT)) {
44548 +#ifdef CONFIG_GRKERNSEC
44549 + if (flags & LOOKUP_RCU) {
44551 + path_put(&nd->path);
44555 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44557 + path_put(&nd->path);
44562 if (!err && nd->flags & LOOKUP_DIRECTORY) {
44563 if (!nd->inode->i_op->lookup) {
44564 path_put(&nd->path);
44565 @@ -1651,6 +1682,15 @@ static int do_path_lookup(int dfd, const char *name,
44566 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
44568 if (likely(!retval)) {
44569 + if (*name != '/' && nd->path.dentry && nd->inode) {
44570 +#ifdef CONFIG_GRKERNSEC
44571 + if (flags & LOOKUP_RCU)
44574 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
44578 if (unlikely(!audit_dummy_context())) {
44579 if (nd->path.dentry && nd->inode)
44580 audit_inode(name, nd->path.dentry);
44581 @@ -2048,6 +2088,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
44582 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
44585 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
44587 + if (gr_handle_rawio(inode))
44589 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
44595 @@ -2109,6 +2156,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44596 error = complete_walk(nd);
44598 return ERR_PTR(error);
44599 +#ifdef CONFIG_GRKERNSEC
44600 + if (nd->flags & LOOKUP_RCU) {
44605 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44609 audit_inode(pathname, nd->path.dentry);
44610 if (open_flag & O_CREAT) {
44612 @@ -2119,6 +2176,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44613 error = complete_walk(nd);
44615 return ERR_PTR(error);
44616 +#ifdef CONFIG_GRKERNSEC
44617 + if (nd->flags & LOOKUP_RCU) {
44622 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
44626 audit_inode(pathname, dir);
44629 @@ -2140,6 +2207,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44630 error = complete_walk(nd);
44632 return ERR_PTR(-ECHILD);
44633 +#ifdef CONFIG_GRKERNSEC
44634 + if (nd->flags & LOOKUP_RCU) {
44639 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44645 if (nd->flags & LOOKUP_DIRECTORY) {
44646 @@ -2180,6 +2257,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44647 /* Negative dentry, just create the file */
44648 if (!dentry->d_inode) {
44649 int mode = op->mode;
44651 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
44653 + goto exit_mutex_unlock;
44656 if (!IS_POSIXACL(dir->d_inode))
44657 mode &= ~current_umask();
44659 @@ -2203,6 +2286,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44660 error = vfs_create(dir->d_inode, dentry, mode, nd);
44662 goto exit_mutex_unlock;
44664 + gr_handle_create(path->dentry, path->mnt);
44665 mutex_unlock(&dir->d_inode->i_mutex);
44666 dput(nd->path.dentry);
44667 nd->path.dentry = dentry;
44668 @@ -2212,6 +2297,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44670 * It already exists.
44673 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
44675 + goto exit_mutex_unlock;
44678 + /* only check if O_CREAT is specified, all other checks need to go
44680 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
44682 + goto exit_mutex_unlock;
44685 mutex_unlock(&dir->d_inode->i_mutex);
44686 audit_inode(pathname, path->dentry);
44688 @@ -2424,6 +2522,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
44692 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
44694 + dentry = ERR_PTR(-ENOENT);
44698 dentry = ERR_PTR(-EEXIST);
44700 @@ -2446,6 +2549,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
44702 EXPORT_SYMBOL(user_path_create);
44704 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
44706 + char *tmp = getname(pathname);
44707 + struct dentry *res;
44709 + return ERR_CAST(tmp);
44710 + res = kern_path_create(dfd, tmp, path, is_dir);
44718 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
44720 int error = may_create(dir, dentry);
44721 @@ -2513,6 +2630,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44722 error = mnt_want_write(path.mnt);
44726 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
44728 + goto out_drop_write;
44731 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
44733 + goto out_drop_write;
44736 error = security_path_mknod(&path, dentry, mode, dev);
44738 goto out_drop_write;
44739 @@ -2530,6 +2658,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44742 mnt_drop_write(path.mnt);
44745 + gr_handle_create(dentry, path.mnt);
44748 mutex_unlock(&path.dentry->d_inode->i_mutex);
44749 @@ -2579,12 +2710,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
44750 error = mnt_want_write(path.mnt);
44754 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
44756 + goto out_drop_write;
44759 error = security_path_mkdir(&path, dentry, mode);
44761 goto out_drop_write;
44762 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
44764 mnt_drop_write(path.mnt);
44767 + gr_handle_create(dentry, path.mnt);
44770 mutex_unlock(&path.dentry->d_inode->i_mutex);
44771 @@ -2664,6 +2804,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44773 struct dentry *dentry;
44774 struct nameidata nd;
44775 + ino_t saved_ino = 0;
44776 + dev_t saved_dev = 0;
44778 error = user_path_parent(dfd, pathname, &nd, &name);
44780 @@ -2692,6 +2834,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
44785 + saved_ino = dentry->d_inode->i_ino;
44786 + saved_dev = gr_get_dev_from_dentry(dentry);
44788 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
44793 error = mnt_want_write(nd.path.mnt);
44796 @@ -2699,6 +2850,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44799 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
44800 + if (!error && (saved_dev || saved_ino))
44801 + gr_handle_delete(saved_ino, saved_dev);
44803 mnt_drop_write(nd.path.mnt);
44805 @@ -2761,6 +2914,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44806 struct dentry *dentry;
44807 struct nameidata nd;
44808 struct inode *inode = NULL;
44809 + ino_t saved_ino = 0;
44810 + dev_t saved_dev = 0;
44812 error = user_path_parent(dfd, pathname, &nd, &name);
44814 @@ -2783,6 +2938,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44819 + if (inode->i_nlink <= 1) {
44820 + saved_ino = inode->i_ino;
44821 + saved_dev = gr_get_dev_from_dentry(dentry);
44823 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
44828 error = mnt_want_write(nd.path.mnt);
44831 @@ -2790,6 +2955,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44834 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
44835 + if (!error && (saved_ino || saved_dev))
44836 + gr_handle_delete(saved_ino, saved_dev);
44838 mnt_drop_write(nd.path.mnt);
44840 @@ -2865,10 +3032,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
44841 error = mnt_want_write(path.mnt);
44845 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
44847 + goto out_drop_write;
44850 error = security_path_symlink(&path, dentry, from);
44852 goto out_drop_write;
44853 error = vfs_symlink(path.dentry->d_inode, dentry, from);
44855 + gr_handle_create(dentry, path.mnt);
44857 mnt_drop_write(path.mnt);
44859 @@ -2940,6 +3115,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44861 struct dentry *new_dentry;
44862 struct path old_path, new_path;
44867 @@ -2963,7 +3139,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44871 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
44872 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
44873 error = PTR_ERR(new_dentry);
44874 if (IS_ERR(new_dentry))
44876 @@ -2974,13 +3150,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44877 error = mnt_want_write(new_path.mnt);
44881 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
44882 + old_path.dentry->d_inode,
44883 + old_path.dentry->d_inode->i_mode, to)) {
44885 + goto out_drop_write;
44888 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
44889 + old_path.dentry, old_path.mnt, to)) {
44891 + goto out_drop_write;
44894 error = security_path_link(old_path.dentry, &new_path, new_dentry);
44896 goto out_drop_write;
44897 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
44899 + gr_handle_create(new_dentry, new_path.mnt);
44901 mnt_drop_write(new_path.mnt);
44905 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
44906 path_put(&new_path);
44907 @@ -3208,6 +3401,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44908 if (new_dentry == trap)
44911 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
44912 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
44917 error = mnt_want_write(oldnd.path.mnt);
44920 @@ -3217,6 +3416,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44922 error = vfs_rename(old_dir->d_inode, old_dentry,
44923 new_dir->d_inode, new_dentry);
44925 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
44926 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
44928 mnt_drop_write(oldnd.path.mnt);
44930 @@ -3242,6 +3444,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
44932 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
44935 + const char *newlink;
44938 len = PTR_ERR(link);
44939 @@ -3251,7 +3455,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
44940 len = strlen(link);
44941 if (len > (unsigned) buflen)
44943 - if (copy_to_user(buffer, link, len))
44945 + if (len < sizeof(tmpbuf)) {
44946 + memcpy(tmpbuf, link, len);
44947 + newlink = tmpbuf;
44951 + if (copy_to_user(buffer, newlink, len))
44955 diff --git a/fs/namespace.c b/fs/namespace.c
44956 index cfc6d44..b4632a5 100644
44957 --- a/fs/namespace.c
44958 +++ b/fs/namespace.c
44959 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44960 if (!(sb->s_flags & MS_RDONLY))
44961 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
44962 up_write(&sb->s_umount);
44964 + gr_log_remount(mnt->mnt_devname, retval);
44969 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44970 br_write_unlock(vfsmount_lock);
44971 up_write(&namespace_sem);
44972 release_mounts(&umount_list);
44974 + gr_log_unmount(mnt->mnt_devname, retval);
44979 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44980 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
44983 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
44988 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
44993 if (flags & MS_REMOUNT)
44994 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
44996 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44997 dev_name, data_page);
45001 + gr_log_mount(dev_name, dir_name, retval);
45006 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
45010 + if (gr_handle_chroot_pivot()) {
45015 get_fs_root(current->fs, &root);
45016 error = lock_mount(&old);
45018 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
45019 index 3db6b82..a57597e 100644
45020 --- a/fs/nfs/blocklayout/blocklayout.c
45021 +++ b/fs/nfs/blocklayout/blocklayout.c
45022 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
45024 struct parallel_io {
45025 struct kref refcnt;
45026 - struct rpc_call_ops call_ops;
45027 + rpc_call_ops_no_const call_ops;
45028 void (*pnfs_callback) (void *data);
45031 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
45032 index 50a15fa..ca113f9 100644
45033 --- a/fs/nfs/inode.c
45034 +++ b/fs/nfs/inode.c
45035 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
45036 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
45037 nfsi->attrtimeo_timestamp = jiffies;
45039 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
45040 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
45041 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
45042 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
45044 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
45045 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
45048 -static atomic_long_t nfs_attr_generation_counter;
45049 +static atomic_long_unchecked_t nfs_attr_generation_counter;
45051 static unsigned long nfs_read_attr_generation_counter(void)
45053 - return atomic_long_read(&nfs_attr_generation_counter);
45054 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
45057 unsigned long nfs_inc_attr_generation_counter(void)
45059 - return atomic_long_inc_return(&nfs_attr_generation_counter);
45060 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
45063 void nfs_fattr_init(struct nfs_fattr *fattr)
45064 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
45065 index 7a2e442..8e544cc 100644
45066 --- a/fs/nfsd/vfs.c
45067 +++ b/fs/nfsd/vfs.c
45068 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
45072 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
45073 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
45077 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
45079 /* Write the data. */
45080 oldfs = get_fs(); set_fs(KERNEL_DS);
45081 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
45082 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
45086 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
45089 oldfs = get_fs(); set_fs(KERNEL_DS);
45090 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
45091 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
45095 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
45096 index 9fde1c0..14e8827 100644
45097 --- a/fs/notify/fanotify/fanotify_user.c
45098 +++ b/fs/notify/fanotify/fanotify_user.c
45099 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
45103 - if (copy_to_user(buf, &fanotify_event_metadata,
45104 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
45105 + copy_to_user(buf, &fanotify_event_metadata,
45106 fanotify_event_metadata.event_len))
45107 goto out_kill_access_response;
45109 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
45110 index ee18815..7aa5d01 100644
45111 --- a/fs/notify/notification.c
45112 +++ b/fs/notify/notification.c
45113 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
45114 * get set to 0 so it will never get 'freed'
45116 static struct fsnotify_event *q_overflow_event;
45117 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
45118 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
45121 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
45122 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
45124 u32 fsnotify_get_cookie(void)
45126 - return atomic_inc_return(&fsnotify_sync_cookie);
45127 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
45129 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
45131 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
45132 index 99e3610..02c1068 100644
45133 --- a/fs/ntfs/dir.c
45134 +++ b/fs/ntfs/dir.c
45135 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
45136 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
45137 ~(s64)(ndir->itype.index.block_size - 1)));
45138 /* Bounds checks. */
45139 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
45140 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
45141 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
45142 "inode 0x%lx or driver bug.", vdir->i_ino);
45144 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
45145 index c587e2d..3641eaa 100644
45146 --- a/fs/ntfs/file.c
45147 +++ b/fs/ntfs/file.c
45148 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
45149 #endif /* NTFS_RW */
45152 -const struct file_operations ntfs_empty_file_ops = {};
45153 +const struct file_operations ntfs_empty_file_ops __read_only;
45155 -const struct inode_operations ntfs_empty_inode_ops = {};
45156 +const struct inode_operations ntfs_empty_inode_ops __read_only;
45157 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
45158 index 210c352..a174f83 100644
45159 --- a/fs/ocfs2/localalloc.c
45160 +++ b/fs/ocfs2/localalloc.c
45161 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
45165 - atomic_inc(&osb->alloc_stats.moves);
45166 + atomic_inc_unchecked(&osb->alloc_stats.moves);
45170 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
45171 index d355e6e..578d905 100644
45172 --- a/fs/ocfs2/ocfs2.h
45173 +++ b/fs/ocfs2/ocfs2.h
45174 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
45176 struct ocfs2_alloc_stats
45179 - atomic_t local_data;
45180 - atomic_t bitmap_data;
45181 - atomic_t bg_allocs;
45182 - atomic_t bg_extends;
45183 + atomic_unchecked_t moves;
45184 + atomic_unchecked_t local_data;
45185 + atomic_unchecked_t bitmap_data;
45186 + atomic_unchecked_t bg_allocs;
45187 + atomic_unchecked_t bg_extends;
45190 enum ocfs2_local_alloc_state
45191 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
45192 index ba5d97e..c77db25 100644
45193 --- a/fs/ocfs2/suballoc.c
45194 +++ b/fs/ocfs2/suballoc.c
45195 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
45196 mlog_errno(status);
45199 - atomic_inc(&osb->alloc_stats.bg_extends);
45200 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
45202 /* You should never ask for this much metadata */
45203 BUG_ON(bits_wanted >
45204 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
45205 mlog_errno(status);
45208 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45209 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45211 *suballoc_loc = res.sr_bg_blkno;
45212 *suballoc_bit_start = res.sr_bit_offset;
45213 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
45214 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
45217 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45218 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45220 BUG_ON(res->sr_bits != 1);
45222 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
45223 mlog_errno(status);
45226 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45227 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45229 BUG_ON(res.sr_bits != 1);
45231 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
45235 - atomic_inc(&osb->alloc_stats.local_data);
45236 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
45238 if (min_clusters > (osb->bitmap_cpg - 1)) {
45239 /* The only paths asking for contiguousness
45240 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
45241 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
45243 res.sr_bit_offset);
45244 - atomic_inc(&osb->alloc_stats.bitmap_data);
45245 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
45246 *num_clusters = res.sr_bits;
45249 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
45250 index 4994f8b..eaab8eb 100644
45251 --- a/fs/ocfs2/super.c
45252 +++ b/fs/ocfs2/super.c
45253 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
45254 "%10s => GlobalAllocs: %d LocalAllocs: %d "
45255 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
45257 - atomic_read(&osb->alloc_stats.bitmap_data),
45258 - atomic_read(&osb->alloc_stats.local_data),
45259 - atomic_read(&osb->alloc_stats.bg_allocs),
45260 - atomic_read(&osb->alloc_stats.moves),
45261 - atomic_read(&osb->alloc_stats.bg_extends));
45262 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
45263 + atomic_read_unchecked(&osb->alloc_stats.local_data),
45264 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
45265 + atomic_read_unchecked(&osb->alloc_stats.moves),
45266 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
45268 out += snprintf(buf + out, len - out,
45269 "%10s => State: %u Descriptor: %llu Size: %u bits "
45270 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
45271 spin_lock_init(&osb->osb_xattr_lock);
45272 ocfs2_init_steal_slots(osb);
45274 - atomic_set(&osb->alloc_stats.moves, 0);
45275 - atomic_set(&osb->alloc_stats.local_data, 0);
45276 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
45277 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
45278 - atomic_set(&osb->alloc_stats.bg_extends, 0);
45279 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
45280 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
45281 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
45282 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
45283 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
45285 /* Copy the blockcheck stats from the superblock probe */
45286 osb->osb_ecc_stats = *stats;
45287 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
45288 index 5d22872..523db20 100644
45289 --- a/fs/ocfs2/symlink.c
45290 +++ b/fs/ocfs2/symlink.c
45291 @@ -142,7 +142,7 @@ bail:
45293 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
45295 - char *link = nd_get_link(nd);
45296 + const char *link = nd_get_link(nd);
45300 diff --git a/fs/open.c b/fs/open.c
45301 index 22c41b5..78894cf 100644
45304 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
45305 error = locks_verify_truncate(inode, NULL, length);
45307 error = security_path_truncate(&path);
45309 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
45313 error = do_truncate(path.dentry, length, 0, NULL);
45315 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
45316 if (__mnt_is_readonly(path.mnt))
45319 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
45325 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
45329 + gr_log_chdir(path.dentry, path.mnt);
45331 set_fs_pwd(current->fs, &path);
45334 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
45337 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
45339 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
45343 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
45346 set_fs_pwd(current->fs, &file->f_path);
45348 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
45352 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
45353 + goto dput_and_out;
45355 set_fs_root(current->fs, &path);
45357 + gr_handle_chroot_chdir(&path);
45362 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
45365 mutex_lock(&inode->i_mutex);
45367 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
45371 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
45376 error = security_path_chmod(path->dentry, path->mnt, mode);
45379 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
45381 struct iattr newattrs;
45383 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
45386 newattrs.ia_valid = ATTR_CTIME;
45387 if (user != (uid_t) -1) {
45388 newattrs.ia_valid |= ATTR_UID;
45389 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
45390 index 6296b40..417c00f 100644
45391 --- a/fs/partitions/efi.c
45392 +++ b/fs/partitions/efi.c
45393 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
45397 + if (!le32_to_cpu(gpt->num_partition_entries))
45399 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
45403 count = le32_to_cpu(gpt->num_partition_entries) *
45404 le32_to_cpu(gpt->sizeof_partition_entry);
45407 - pte = kzalloc(count, GFP_KERNEL);
45411 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
45414 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
45415 index bd8ae78..539d250 100644
45416 --- a/fs/partitions/ldm.c
45417 +++ b/fs/partitions/ldm.c
45418 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
45422 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
45423 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
45425 ldm_crit ("Out of memory.");
45427 diff --git a/fs/pipe.c b/fs/pipe.c
45428 index 4065f07..68c0706 100644
45431 @@ -420,9 +420,9 @@ redo:
45433 if (bufs) /* More to do? */
45435 - if (!pipe->writers)
45436 + if (!atomic_read(&pipe->writers))
45438 - if (!pipe->waiting_writers) {
45439 + if (!atomic_read(&pipe->waiting_writers)) {
45440 /* syscall merging: Usually we must not sleep
45441 * if O_NONBLOCK is set, or if we got some data.
45442 * But if a writer sleeps in kernel space, then
45443 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
45444 mutex_lock(&inode->i_mutex);
45445 pipe = inode->i_pipe;
45447 - if (!pipe->readers) {
45448 + if (!atomic_read(&pipe->readers)) {
45449 send_sig(SIGPIPE, current, 0);
45452 @@ -530,7 +530,7 @@ redo1:
45456 - if (!pipe->readers) {
45457 + if (!atomic_read(&pipe->readers)) {
45458 send_sig(SIGPIPE, current, 0);
45461 @@ -616,9 +616,9 @@ redo2:
45462 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45465 - pipe->waiting_writers++;
45466 + atomic_inc(&pipe->waiting_writers);
45468 - pipe->waiting_writers--;
45469 + atomic_dec(&pipe->waiting_writers);
45472 mutex_unlock(&inode->i_mutex);
45473 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45475 if (filp->f_mode & FMODE_READ) {
45476 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
45477 - if (!pipe->writers && filp->f_version != pipe->w_counter)
45478 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
45482 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45483 * Most Unices do not set POLLERR for FIFOs but on Linux they
45484 * behave exactly like pipes for poll().
45486 - if (!pipe->readers)
45487 + if (!atomic_read(&pipe->readers))
45491 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
45493 mutex_lock(&inode->i_mutex);
45494 pipe = inode->i_pipe;
45495 - pipe->readers -= decr;
45496 - pipe->writers -= decw;
45497 + atomic_sub(decr, &pipe->readers);
45498 + atomic_sub(decw, &pipe->writers);
45500 - if (!pipe->readers && !pipe->writers) {
45501 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
45502 free_pipe_info(inode);
45504 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
45505 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
45507 if (inode->i_pipe) {
45509 - inode->i_pipe->readers++;
45510 + atomic_inc(&inode->i_pipe->readers);
45513 mutex_unlock(&inode->i_mutex);
45514 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
45516 if (inode->i_pipe) {
45518 - inode->i_pipe->writers++;
45519 + atomic_inc(&inode->i_pipe->writers);
45522 mutex_unlock(&inode->i_mutex);
45523 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
45524 if (inode->i_pipe) {
45526 if (filp->f_mode & FMODE_READ)
45527 - inode->i_pipe->readers++;
45528 + atomic_inc(&inode->i_pipe->readers);
45529 if (filp->f_mode & FMODE_WRITE)
45530 - inode->i_pipe->writers++;
45531 + atomic_inc(&inode->i_pipe->writers);
45534 mutex_unlock(&inode->i_mutex);
45535 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
45536 inode->i_pipe = NULL;
45539 -static struct vfsmount *pipe_mnt __read_mostly;
45540 +struct vfsmount *pipe_mnt __read_mostly;
45543 * pipefs_dname() is called from d_path().
45544 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
45546 inode->i_pipe = pipe;
45548 - pipe->readers = pipe->writers = 1;
45549 + atomic_set(&pipe->readers, 1);
45550 + atomic_set(&pipe->writers, 1);
45551 inode->i_fop = &rdwr_pipefifo_fops;
45554 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
45555 index 15af622..0e9f4467 100644
45556 --- a/fs/proc/Kconfig
45557 +++ b/fs/proc/Kconfig
45558 @@ -30,12 +30,12 @@ config PROC_FS
45561 bool "/proc/kcore support" if !ARM
45562 - depends on PROC_FS && MMU
45563 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
45566 bool "/proc/vmcore support"
45567 - depends on PROC_FS && CRASH_DUMP
45569 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
45572 Exports the dump image of crashed kernel in ELF format.
45574 @@ -59,8 +59,8 @@ config PROC_SYSCTL
45577 config PROC_PAGE_MONITOR
45579 - depends on PROC_FS && MMU
45581 + depends on PROC_FS && MMU && !GRKERNSEC
45582 bool "Enable /proc page monitoring" if EXPERT
45584 Various /proc files exist to monitor process memory utilization:
45585 diff --git a/fs/proc/array.c b/fs/proc/array.c
45586 index 3a1dafd..bf1bd84 100644
45587 --- a/fs/proc/array.c
45588 +++ b/fs/proc/array.c
45590 #include <linux/tty.h>
45591 #include <linux/string.h>
45592 #include <linux/mman.h>
45593 +#include <linux/grsecurity.h>
45594 #include <linux/proc_fs.h>
45595 #include <linux/ioport.h>
45596 #include <linux/uaccess.h>
45597 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
45601 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45602 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
45605 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
45606 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
45607 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
45608 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
45609 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
45610 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
45612 + seq_printf(m, "PaX:\t-----\n");
45616 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45617 struct pid *pid, struct task_struct *task)
45619 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45620 task_cpus_allowed(m, task);
45621 cpuset_task_status_allowed(m, task);
45622 task_context_switch_counts(m, task);
45624 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45625 + task_pax(m, task);
45628 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
45629 + task_grsec_rbac(m, task);
45635 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45636 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45637 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45638 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45641 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45642 struct pid *pid, struct task_struct *task, int whole)
45644 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45645 char tcomm[sizeof(task->comm)];
45646 unsigned long flags;
45648 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45649 + if (current->exec_id != m->exec_id) {
45650 + gr_log_badprocpid("stat");
45655 state = *get_task_state(task);
45656 vsize = eip = esp = 0;
45657 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
45658 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45659 gtime = task->gtime;
45662 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45663 + if (PAX_RAND_FLAGS(mm)) {
45669 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45675 /* scale priority and nice values from timeslices to -20..20 */
45676 /* to make it look like a "normal" Unix priority/nice value */
45677 priority = task_prio(task);
45678 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45680 mm ? get_mm_rss(mm) : 0,
45682 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45683 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
45684 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
45685 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
45687 mm ? (permitted ? mm->start_code : 1) : 0,
45688 mm ? (permitted ? mm->end_code : 1) : 0,
45689 (permitted && mm) ? mm->start_stack : 0,
45693 /* The signal information here is obsolete.
45694 @@ -533,8 +590,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45695 struct pid *pid, struct task_struct *task)
45697 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
45698 - struct mm_struct *mm = get_task_mm(task);
45699 + struct mm_struct *mm;
45701 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45702 + if (current->exec_id != m->exec_id) {
45703 + gr_log_badprocpid("statm");
45707 + mm = get_task_mm(task);
45709 size = task_statm(mm, &shared, &text, &data, &resident);
45711 @@ -544,3 +608,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45716 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45717 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
45720 + unsigned long flags;
45722 + if (lock_task_sighand(task, &flags)) {
45723 + curr_ip = task->signal->curr_ip;
45724 + unlock_task_sighand(task, &flags);
45727 + return sprintf(buffer, "%pI4\n", &curr_ip);
45730 diff --git a/fs/proc/base.c b/fs/proc/base.c
45731 index 1ace83d..f5e575d 100644
45732 --- a/fs/proc/base.c
45733 +++ b/fs/proc/base.c
45734 @@ -107,6 +107,22 @@ struct pid_entry {
45738 +struct getdents_callback {
45739 + struct linux_dirent __user * current_dir;
45740 + struct linux_dirent __user * previous;
45741 + struct file * file;
45746 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
45747 + loff_t offset, u64 ino, unsigned int d_type)
45749 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
45750 + buf->error = -EINVAL;
45754 #define NOD(NAME, MODE, IOP, FOP, OP) { \
45756 .len = sizeof(NAME) - 1, \
45757 @@ -194,26 +210,6 @@ static int proc_root_link(struct inode *inode, struct path *path)
45761 -static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
45763 - struct mm_struct *mm;
45766 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
45768 - return ERR_PTR(err);
45770 - mm = get_task_mm(task);
45771 - if (mm && mm != current->mm &&
45772 - !ptrace_may_access(task, mode)) {
45774 - mm = ERR_PTR(-EACCES);
45776 - mutex_unlock(&task->signal->cred_guard_mutex);
45781 struct mm_struct *mm_for_maps(struct task_struct *task)
45783 return mm_access(task, PTRACE_MODE_READ);
45784 @@ -229,6 +225,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
45786 goto out_mm; /* Shh! No looking before we're done */
45788 + if (gr_acl_handle_procpidmem(task))
45791 len = mm->arg_end - mm->arg_start;
45793 if (len > PAGE_SIZE)
45794 @@ -256,12 +255,28 @@ out:
45798 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45799 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45800 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45801 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45804 static int proc_pid_auxv(struct task_struct *task, char *buffer)
45806 struct mm_struct *mm = mm_for_maps(task);
45807 int res = PTR_ERR(mm);
45808 if (mm && !IS_ERR(mm)) {
45809 unsigned int nwords = 0;
45811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45812 + /* allow if we're currently ptracing this task */
45813 + if (PAX_RAND_FLAGS(mm) &&
45814 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
45822 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
45823 @@ -275,7 +290,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
45827 -#ifdef CONFIG_KALLSYMS
45828 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45830 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
45831 * Returns the resolved symbol. If that fails, simply return the address.
45832 @@ -314,7 +329,7 @@ static void unlock_trace(struct task_struct *task)
45833 mutex_unlock(&task->signal->cred_guard_mutex);
45836 -#ifdef CONFIG_STACKTRACE
45837 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45839 #define MAX_STACK_TRACE_DEPTH 64
45841 @@ -505,7 +520,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
45845 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45846 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45847 static int proc_pid_syscall(struct task_struct *task, char *buffer)
45850 @@ -534,7 +549,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
45851 /************************************************************************/
45853 /* permission checks */
45854 -static int proc_fd_access_allowed(struct inode *inode)
45855 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
45857 struct task_struct *task;
45859 @@ -544,7 +559,10 @@ static int proc_fd_access_allowed(struct inode *inode)
45861 task = get_proc_task(inode);
45863 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45865 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
45867 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45868 put_task_struct(task);
45871 @@ -786,6 +804,10 @@ static int mem_open(struct inode* inode, struct file* file)
45872 file->f_mode |= FMODE_UNSIGNED_OFFSET;
45873 file->private_data = mm;
45875 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45876 + file->f_version = current->exec_id;
45882 @@ -797,6 +819,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
45886 +#ifdef CONFIG_GRKERNSEC
45890 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45891 + if (file->f_version != current->exec_id) {
45892 + gr_log_badprocpid("mem");
45900 @@ -897,6 +930,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
45904 + if (gr_acl_handle_procpidmem(task))
45908 page = (char *)__get_free_page(GFP_TEMPORARY);
45910 @@ -1519,7 +1555,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
45911 path_put(&nd->path);
45913 /* Are we allowed to snoop on the tasks file descriptors? */
45914 - if (!proc_fd_access_allowed(inode))
45915 + if (!proc_fd_access_allowed(inode,0))
45918 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
45919 @@ -1558,8 +1594,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
45922 /* Are we allowed to snoop on the tasks file descriptors? */
45923 - if (!proc_fd_access_allowed(inode))
45925 + /* logging this is needed for learning on chromium to work properly,
45926 + but we don't want to flood the logs from 'ps' which does a readlink
45927 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
45928 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
45930 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
45931 + if (!proc_fd_access_allowed(inode,0))
45934 + if (!proc_fd_access_allowed(inode,1))
45938 error = PROC_I(inode)->op.proc_get_link(inode, &path);
45940 @@ -1624,7 +1670,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
45942 cred = __task_cred(task);
45943 inode->i_uid = cred->euid;
45944 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45945 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45947 inode->i_gid = cred->egid;
45951 security_task_to_inode(task, inode);
45952 @@ -1642,6 +1692,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45953 struct inode *inode = dentry->d_inode;
45954 struct task_struct *task;
45955 const struct cred *cred;
45956 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45957 + const struct cred *tmpcred = current_cred();
45960 generic_fillattr(inode, stat);
45962 @@ -1649,13 +1702,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45965 task = pid_task(proc_pid(inode), PIDTYPE_PID);
45967 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
45968 + rcu_read_unlock();
45973 + cred = __task_cred(task);
45974 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45975 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
45976 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45977 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45981 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45982 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45983 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45984 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45985 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45987 task_dumpable(task)) {
45988 - cred = __task_cred(task);
45989 stat->uid = cred->euid;
45990 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45991 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
45993 stat->gid = cred->egid;
45996 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45998 + rcu_read_unlock();
46005 @@ -1692,11 +1773,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
46008 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
46009 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46010 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
46011 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46012 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
46014 task_dumpable(task)) {
46016 cred = __task_cred(task);
46017 inode->i_uid = cred->euid;
46018 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46019 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46021 inode->i_gid = cred->egid;
46026 @@ -1814,7 +1904,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
46027 int fd = proc_fd(inode);
46030 - files = get_files_struct(task);
46031 + if (!gr_acl_handle_procpidmem(task))
46032 + files = get_files_struct(task);
46033 put_task_struct(task);
46036 @@ -2082,11 +2173,21 @@ static const struct file_operations proc_fd_operations = {
46038 static int proc_fd_permission(struct inode *inode, int mask)
46040 + struct task_struct *task;
46041 int rv = generic_permission(inode, mask);
46045 if (task_pid(current) == proc_pid(inode))
46048 + task = get_proc_task(inode);
46049 + if (task == NULL)
46052 + if (gr_acl_handle_procpidmem(task))
46055 + put_task_struct(task);
46060 @@ -2196,6 +2297,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
46064 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46068 * Yes, it does not scale. And it should not. Don't add
46069 * new entries into /proc/<tgid>/ without very good reasons.
46070 @@ -2240,6 +2344,9 @@ static int proc_pident_readdir(struct file *filp,
46074 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46080 @@ -2510,7 +2617,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
46081 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
46084 - char *s = nd_get_link(nd);
46085 + const char *s = nd_get_link(nd);
46089 @@ -2708,7 +2815,7 @@ static const struct pid_entry tgid_base_stuff[] = {
46090 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
46092 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
46093 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46094 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46095 INF("syscall", S_IRUGO, proc_pid_syscall),
46097 INF("cmdline", S_IRUGO, proc_pid_cmdline),
46098 @@ -2733,10 +2840,10 @@ static const struct pid_entry tgid_base_stuff[] = {
46099 #ifdef CONFIG_SECURITY
46100 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
46102 -#ifdef CONFIG_KALLSYMS
46103 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46104 INF("wchan", S_IRUGO, proc_pid_wchan),
46106 -#ifdef CONFIG_STACKTRACE
46107 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46108 ONE("stack", S_IRUGO, proc_pid_stack),
46110 #ifdef CONFIG_SCHEDSTATS
46111 @@ -2770,6 +2877,9 @@ static const struct pid_entry tgid_base_stuff[] = {
46112 #ifdef CONFIG_HARDWALL
46113 INF("hardwall", S_IRUGO, proc_pid_hardwall),
46115 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46116 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
46120 static int proc_tgid_base_readdir(struct file * filp,
46121 @@ -2895,7 +3005,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
46125 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46126 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
46127 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46128 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46129 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
46131 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
46133 inode->i_op = &proc_tgid_base_inode_operations;
46134 inode->i_fop = &proc_tgid_base_operations;
46135 inode->i_flags|=S_IMMUTABLE;
46136 @@ -2937,7 +3054,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
46140 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46141 + goto out_put_task;
46143 result = proc_pid_instantiate(dir, dentry, task, NULL);
46145 put_task_struct(task);
46148 @@ -3002,6 +3123,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
46151 struct task_struct *reaper;
46152 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46153 + const struct cred *tmpcred = current_cred();
46154 + const struct cred *itercred;
46156 + filldir_t __filldir = filldir;
46157 struct tgid_iter iter;
46158 struct pid_namespace *ns;
46160 @@ -3025,8 +3151,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
46161 for (iter = next_tgid(ns, iter);
46163 iter.tgid += 1, iter = next_tgid(ns, iter)) {
46164 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46166 + itercred = __task_cred(iter.task);
46168 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
46169 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46170 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
46171 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46172 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
46177 + __filldir = &gr_fake_filldir;
46179 + __filldir = filldir;
46180 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46181 + rcu_read_unlock();
46183 filp->f_pos = iter.tgid + TGID_OFFSET;
46184 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
46185 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
46186 put_task_struct(iter.task);
46189 @@ -3054,7 +3199,7 @@ static const struct pid_entry tid_base_stuff[] = {
46190 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
46192 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
46193 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46194 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46195 INF("syscall", S_IRUGO, proc_pid_syscall),
46197 INF("cmdline", S_IRUGO, proc_pid_cmdline),
46198 @@ -3078,10 +3223,10 @@ static const struct pid_entry tid_base_stuff[] = {
46199 #ifdef CONFIG_SECURITY
46200 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
46202 -#ifdef CONFIG_KALLSYMS
46203 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46204 INF("wchan", S_IRUGO, proc_pid_wchan),
46206 -#ifdef CONFIG_STACKTRACE
46207 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46208 ONE("stack", S_IRUGO, proc_pid_stack),
46210 #ifdef CONFIG_SCHEDSTATS
46211 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
46212 index 82676e3..5f8518a 100644
46213 --- a/fs/proc/cmdline.c
46214 +++ b/fs/proc/cmdline.c
46215 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
46217 static int __init proc_cmdline_init(void)
46219 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46220 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
46222 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
46226 module_init(proc_cmdline_init);
46227 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
46228 index b143471..bb105e5 100644
46229 --- a/fs/proc/devices.c
46230 +++ b/fs/proc/devices.c
46231 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
46233 static int __init proc_devices_init(void)
46235 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46236 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
46238 proc_create("devices", 0, NULL, &proc_devinfo_operations);
46242 module_init(proc_devices_init);
46243 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
46244 index 7737c54..7172574 100644
46245 --- a/fs/proc/inode.c
46246 +++ b/fs/proc/inode.c
46247 @@ -18,12 +18,18 @@
46248 #include <linux/module.h>
46249 #include <linux/sysctl.h>
46250 #include <linux/slab.h>
46251 +#include <linux/grsecurity.h>
46253 #include <asm/system.h>
46254 #include <asm/uaccess.h>
46256 #include "internal.h"
46258 +#ifdef CONFIG_PROC_SYSCTL
46259 +extern const struct inode_operations proc_sys_inode_operations;
46260 +extern const struct inode_operations proc_sys_dir_operations;
46263 static void proc_evict_inode(struct inode *inode)
46265 struct proc_dir_entry *de;
46266 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
46267 ns_ops = PROC_I(inode)->ns_ops;
46268 if (ns_ops && ns_ops->put)
46269 ns_ops->put(PROC_I(inode)->ns);
46271 +#ifdef CONFIG_PROC_SYSCTL
46272 + if (inode->i_op == &proc_sys_inode_operations ||
46273 + inode->i_op == &proc_sys_dir_operations)
46274 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
46279 static struct kmem_cache * proc_inode_cachep;
46280 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
46282 inode->i_mode = de->mode;
46283 inode->i_uid = de->uid;
46284 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46285 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46287 inode->i_gid = de->gid;
46291 inode->i_size = de->size;
46292 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
46293 index 7838e5c..ff92cbc 100644
46294 --- a/fs/proc/internal.h
46295 +++ b/fs/proc/internal.h
46296 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46297 struct pid *pid, struct task_struct *task);
46298 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46299 struct pid *pid, struct task_struct *task);
46300 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46301 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
46303 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
46305 extern const struct file_operations proc_maps_operations;
46306 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
46307 index d245cb2..f4e8498 100644
46308 --- a/fs/proc/kcore.c
46309 +++ b/fs/proc/kcore.c
46310 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46311 * the addresses in the elf_phdr on our list.
46313 start = kc_offset_to_vaddr(*fpos - elf_buflen);
46314 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
46315 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
46316 + if (tsz > buflen)
46321 struct kcore_list *m;
46323 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46326 if (kern_addr_valid(start)) {
46329 + mm_segment_t oldfs;
46331 - n = copy_to_user(buffer, (char *)start, tsz);
46333 - * We cannot distingush between fault on source
46334 - * and fault on destination. When this happens
46335 - * we clear too and hope it will trigger the
46339 - if (clear_user(buffer + tsz - n,
46341 + elf_buf = kmalloc(tsz, GFP_KERNEL);
46344 + oldfs = get_fs();
46345 + set_fs(KERNEL_DS);
46346 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
46348 + if (copy_to_user(buffer, elf_buf, tsz)) {
46356 if (clear_user(buffer, tsz))
46358 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46360 static int open_kcore(struct inode *inode, struct file *filp)
46362 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
46365 if (!capable(CAP_SYS_RAWIO))
46367 if (kcore_need_update)
46368 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
46369 index 80e4645..53e5fcf 100644
46370 --- a/fs/proc/meminfo.c
46371 +++ b/fs/proc/meminfo.c
46372 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
46374 vmi.largest_chunk >> 10
46375 #ifdef CONFIG_MEMORY_FAILURE
46376 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
46377 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
46379 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
46380 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
46381 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
46382 index b1822dd..df622cb 100644
46383 --- a/fs/proc/nommu.c
46384 +++ b/fs/proc/nommu.c
46385 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
46388 seq_printf(m, "%*c", len, ' ');
46389 - seq_path(m, &file->f_path, "");
46390 + seq_path(m, &file->f_path, "\n\\");
46394 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
46395 index f738024..876984a 100644
46396 --- a/fs/proc/proc_net.c
46397 +++ b/fs/proc/proc_net.c
46398 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
46399 struct task_struct *task;
46400 struct nsproxy *ns;
46401 struct net *net = NULL;
46402 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46403 + const struct cred *cred = current_cred();
46406 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46409 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46410 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
46415 task = pid_task(proc_pid(dir), PIDTYPE_PID);
46416 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
46417 index a6b6217..1e0579d 100644
46418 --- a/fs/proc/proc_sysctl.c
46419 +++ b/fs/proc/proc_sysctl.c
46421 #include <linux/namei.h>
46422 #include "internal.h"
46424 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
46426 static const struct dentry_operations proc_sys_dentry_operations;
46427 static const struct file_operations proc_sys_file_operations;
46428 -static const struct inode_operations proc_sys_inode_operations;
46429 +const struct inode_operations proc_sys_inode_operations;
46430 static const struct file_operations proc_sys_dir_file_operations;
46431 -static const struct inode_operations proc_sys_dir_operations;
46432 +const struct inode_operations proc_sys_dir_operations;
46434 void proc_sys_poll_notify(struct ctl_table_poll *poll)
46436 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
46439 d_set_d_op(dentry, &proc_sys_dentry_operations);
46441 + gr_handle_proc_create(dentry, inode);
46443 d_add(dentry, inode);
46445 + if (gr_handle_sysctl(p, MAY_EXEC))
46446 + err = ERR_PTR(-ENOENT);
46449 sysctl_head_finish(head);
46451 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
46452 if (!table->proc_handler)
46455 +#ifdef CONFIG_GRKERNSEC
46457 + if (write && !capable(CAP_SYS_ADMIN))
46461 /* careful: calling conventions are nasty here */
46463 error = table->proc_handler(table, write, buf, &res, ppos);
46464 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
46467 d_set_d_op(child, &proc_sys_dentry_operations);
46469 + gr_handle_proc_create(child, inode);
46471 d_add(child, inode);
46474 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
46475 if (*pos < file->f_pos)
46478 + if (gr_handle_sysctl(table, 0))
46481 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
46484 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
46486 return PTR_ERR(head);
46488 + if (table && gr_handle_sysctl(table, MAY_EXEC))
46491 generic_fillattr(inode, stat);
46493 stat->mode = (stat->mode & S_IFMT) | table->mode;
46494 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
46495 .llseek = generic_file_llseek,
46498 -static const struct inode_operations proc_sys_inode_operations = {
46499 +const struct inode_operations proc_sys_inode_operations = {
46500 .permission = proc_sys_permission,
46501 .setattr = proc_sys_setattr,
46502 .getattr = proc_sys_getattr,
46505 -static const struct inode_operations proc_sys_dir_operations = {
46506 +const struct inode_operations proc_sys_dir_operations = {
46507 .lookup = proc_sys_lookup,
46508 .permission = proc_sys_permission,
46509 .setattr = proc_sys_setattr,
46510 diff --git a/fs/proc/root.c b/fs/proc/root.c
46511 index 03102d9..4ae347e 100644
46512 --- a/fs/proc/root.c
46513 +++ b/fs/proc/root.c
46514 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
46515 #ifdef CONFIG_PROC_DEVICETREE
46516 proc_device_tree_init();
46518 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46519 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46520 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
46521 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46522 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46525 proc_mkdir("bus", NULL);
46530 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
46531 index 7dcd2a2..b2f410e 100644
46532 --- a/fs/proc/task_mmu.c
46533 +++ b/fs/proc/task_mmu.c
46535 #include <linux/rmap.h>
46536 #include <linux/swap.h>
46537 #include <linux/swapops.h>
46538 +#include <linux/grsecurity.h>
46540 #include <asm/elf.h>
46541 #include <asm/uaccess.h>
46542 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46543 "VmExe:\t%8lu kB\n"
46544 "VmLib:\t%8lu kB\n"
46545 "VmPTE:\t%8lu kB\n"
46546 - "VmSwap:\t%8lu kB\n",
46547 - hiwater_vm << (PAGE_SHIFT-10),
46548 + "VmSwap:\t%8lu kB\n"
46550 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46551 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
46554 + ,hiwater_vm << (PAGE_SHIFT-10),
46555 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
46556 mm->locked_vm << (PAGE_SHIFT-10),
46557 mm->pinned_vm << (PAGE_SHIFT-10),
46558 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46559 data << (PAGE_SHIFT-10),
46560 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
46561 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
46562 - swap << (PAGE_SHIFT-10));
46563 + swap << (PAGE_SHIFT-10)
46565 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46566 + , mm->context.user_cs_base, mm->context.user_cs_limit
46572 unsigned long task_vsize(struct mm_struct *mm)
46573 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
46577 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46578 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46579 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46580 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46583 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46585 struct mm_struct *mm = vma->vm_mm;
46586 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46587 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
46590 - /* We don't show the stack guard page in /proc/maps */
46591 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46592 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
46593 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
46595 start = vma->vm_start;
46596 - if (stack_guard_page_start(vma, start))
46597 - start += PAGE_SIZE;
46599 - if (stack_guard_page_end(vma, end))
46600 - end -= PAGE_SIZE;
46603 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
46605 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46606 flags & VM_WRITE ? 'w' : '-',
46607 flags & VM_EXEC ? 'x' : '-',
46608 flags & VM_MAYSHARE ? 's' : 'p',
46609 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46610 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
46614 MAJOR(dev), MINOR(dev), ino, &len);
46617 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46620 pad_len_spaces(m, len);
46621 - seq_path(m, &file->f_path, "\n");
46622 + seq_path(m, &file->f_path, "\n\\");
46624 const char *name = arch_vma_name(vma);
46626 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46627 if (vma->vm_start <= mm->brk &&
46628 vma->vm_end >= mm->start_brk) {
46630 - } else if (vma->vm_start <= mm->start_stack &&
46631 - vma->vm_end >= mm->start_stack) {
46632 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
46633 + (vma->vm_start <= mm->start_stack &&
46634 + vma->vm_end >= mm->start_stack)) {
46638 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
46639 struct proc_maps_private *priv = m->private;
46640 struct task_struct *task = priv->task;
46642 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46643 + if (current->exec_id != m->exec_id) {
46644 + gr_log_badprocpid("maps");
46649 show_map_vma(m, vma);
46651 if (m->count < m->size) /* vma is copied successfully */
46652 @@ -434,12 +464,23 @@ static int show_smap(struct seq_file *m, void *v)
46656 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46657 + if (current->exec_id != m->exec_id) {
46658 + gr_log_badprocpid("smaps");
46662 memset(&mss, 0, sizeof mss);
46664 - /* mmap_sem is held in m_start */
46665 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46666 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46668 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46669 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
46672 + /* mmap_sem is held in m_start */
46673 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46674 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46675 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46678 show_map_vma(m, vma);
46681 @@ -457,7 +498,11 @@ static int show_smap(struct seq_file *m, void *v)
46682 "KernelPageSize: %8lu kB\n"
46683 "MMUPageSize: %8lu kB\n"
46684 "Locked: %8lu kB\n",
46685 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46686 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
46688 (vma->vm_end - vma->vm_start) >> 10,
46690 mss.resident >> 10,
46691 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
46692 mss.shared_clean >> 10,
46693 @@ -1015,6 +1060,13 @@ static int show_numa_map(struct seq_file *m, void *v)
46697 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46698 + if (current->exec_id != m->exec_id) {
46699 + gr_log_badprocpid("numa_maps");
46707 @@ -1032,11 +1084,15 @@ static int show_numa_map(struct seq_file *m, void *v)
46708 mpol_to_str(buffer, sizeof(buffer), pol, 0);
46709 mpol_cond_put(pol);
46711 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46712 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
46714 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
46718 seq_printf(m, " file=");
46719 - seq_path(m, &file->f_path, "\n\t= ");
46720 + seq_path(m, &file->f_path, "\n\t\\= ");
46721 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
46722 seq_printf(m, " heap");
46723 } else if (vma->vm_start <= mm->start_stack &&
46724 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
46725 index 980de54..2a4db5f 100644
46726 --- a/fs/proc/task_nommu.c
46727 +++ b/fs/proc/task_nommu.c
46728 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46730 bytes += kobjsize(mm);
46732 - if (current->fs && current->fs->users > 1)
46733 + if (current->fs && atomic_read(¤t->fs->users) > 1)
46734 sbytes += kobjsize(current->fs);
46736 bytes += kobjsize(current->fs);
46737 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
46740 pad_len_spaces(m, len);
46741 - seq_path(m, &file->f_path, "");
46742 + seq_path(m, &file->f_path, "\n\\");
46744 if (vma->vm_start <= mm->start_stack &&
46745 vma->vm_end >= mm->start_stack) {
46746 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
46747 index d67908b..d13f6a6 100644
46748 --- a/fs/quota/netlink.c
46749 +++ b/fs/quota/netlink.c
46750 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
46751 void quota_send_warning(short type, unsigned int id, dev_t dev,
46752 const char warntype)
46754 - static atomic_t seq;
46755 + static atomic_unchecked_t seq;
46756 struct sk_buff *skb;
46759 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
46760 "VFS: Not enough memory to send quota warning.\n");
46763 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
46764 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
46765 "a_genl_family, 0, QUOTA_NL_C_WARNING);
46768 diff --git a/fs/readdir.c b/fs/readdir.c
46769 index 356f715..c918d38 100644
46773 #include <linux/security.h>
46774 #include <linux/syscalls.h>
46775 #include <linux/unistd.h>
46776 +#include <linux/namei.h>
46778 #include <asm/uaccess.h>
46780 @@ -67,6 +68,7 @@ struct old_linux_dirent {
46782 struct readdir_callback {
46783 struct old_linux_dirent __user * dirent;
46784 + struct file * file;
46788 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
46789 buf->result = -EOVERFLOW;
46793 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46797 dirent = buf->dirent;
46798 if (!access_ok(VERIFY_WRITE, dirent,
46799 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
46802 buf.dirent = dirent;
46805 error = vfs_readdir(file, fillonedir, &buf);
46807 @@ -142,6 +149,7 @@ struct linux_dirent {
46808 struct getdents_callback {
46809 struct linux_dirent __user * current_dir;
46810 struct linux_dirent __user * previous;
46811 + struct file * file;
46815 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
46816 buf->error = -EOVERFLOW;
46820 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46823 dirent = buf->previous;
46825 if (__put_user(offset, &dirent->d_off))
46826 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
46827 buf.previous = NULL;
46832 error = vfs_readdir(file, filldir, &buf);
46834 @@ -229,6 +242,7 @@ out:
46835 struct getdents_callback64 {
46836 struct linux_dirent64 __user * current_dir;
46837 struct linux_dirent64 __user * previous;
46838 + struct file *file;
46842 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
46843 buf->error = -EINVAL; /* only used if we fail.. */
46844 if (reclen > buf->count)
46847 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46850 dirent = buf->previous;
46852 if (__put_user(offset, &dirent->d_off))
46853 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46855 buf.current_dir = dirent;
46856 buf.previous = NULL;
46861 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46863 lastdirent = buf.previous;
46865 - typeof(lastdirent->d_off) d_off = file->f_pos;
46866 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
46867 if (__put_user(d_off, &lastdirent->d_off))
46870 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
46871 index 60c0804..d814f98 100644
46872 --- a/fs/reiserfs/do_balan.c
46873 +++ b/fs/reiserfs/do_balan.c
46874 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
46878 - atomic_inc(&(fs_generation(tb->tb_sb)));
46879 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
46880 do_balance_starts(tb);
46882 /* balance leaf returns 0 except if combining L R and S into
46883 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
46884 index 7a99811..a7c96c4 100644
46885 --- a/fs/reiserfs/procfs.c
46886 +++ b/fs/reiserfs/procfs.c
46887 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
46888 "SMALL_TAILS " : "NO_TAILS ",
46889 replay_only(sb) ? "REPLAY_ONLY " : "",
46890 convert_reiserfs(sb) ? "CONV " : "",
46891 - atomic_read(&r->s_generation_counter),
46892 + atomic_read_unchecked(&r->s_generation_counter),
46893 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
46894 SF(s_do_balance), SF(s_unneeded_left_neighbor),
46895 SF(s_good_search_by_key_reada), SF(s_bmaps),
46896 diff --git a/fs/select.c b/fs/select.c
46897 index d33418f..2a5345e 100644
46901 #include <linux/module.h>
46902 #include <linux/slab.h>
46903 #include <linux/poll.h>
46904 +#include <linux/security.h>
46905 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
46906 #include <linux/file.h>
46907 #include <linux/fdtable.h>
46908 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
46909 struct poll_list *walk = head;
46910 unsigned long todo = nfds;
46912 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
46913 if (nfds > rlimit(RLIMIT_NOFILE))
46916 diff --git a/fs/seq_file.c b/fs/seq_file.c
46917 index dba43c3..9fb8511 100644
46918 --- a/fs/seq_file.c
46919 +++ b/fs/seq_file.c
46921 #include <linux/module.h>
46922 #include <linux/seq_file.h>
46923 #include <linux/slab.h>
46924 +#include <linux/sched.h>
46926 #include <asm/uaccess.h>
46927 #include <asm/page.h>
46928 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
46929 memset(p, 0, sizeof(*p));
46930 mutex_init(&p->lock);
46932 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46933 + p->exec_id = current->exec_id;
46937 * Wrappers around seq_open(e.g. swaps_open) need to be
46938 @@ -76,7 +80,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46942 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46943 + m->size = PAGE_SIZE;
46944 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46948 @@ -116,7 +121,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46952 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46954 + m->buf = kmalloc(m->size, GFP_KERNEL);
46955 return !m->buf ? -ENOMEM : -EAGAIN;
46958 @@ -169,7 +175,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46959 m->version = file->f_version;
46960 /* grab buffer if we didn't have one */
46962 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46963 + m->size = PAGE_SIZE;
46964 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46968 @@ -210,7 +217,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46972 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46974 + m->buf = kmalloc(m->size, GFP_KERNEL);
46978 @@ -549,7 +557,7 @@ static void single_stop(struct seq_file *p, void *v)
46979 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
46982 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
46983 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
46987 diff --git a/fs/splice.c b/fs/splice.c
46988 index fa2defa..8601650 100644
46991 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46995 - if (!pipe->readers) {
46996 + if (!atomic_read(&pipe->readers)) {
46997 send_sig(SIGPIPE, current, 0);
47000 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
47004 - pipe->waiting_writers++;
47005 + atomic_inc(&pipe->waiting_writers);
47007 - pipe->waiting_writers--;
47008 + atomic_dec(&pipe->waiting_writers);
47012 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
47015 /* The cast to a user pointer is valid due to the set_fs() */
47016 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
47017 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
47021 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
47024 /* The cast to a user pointer is valid due to the set_fs() */
47025 - res = vfs_write(file, (const char __user *)buf, count, &pos);
47026 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
47030 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
47033 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
47034 - vec[i].iov_base = (void __user *) page_address(page);
47035 + vec[i].iov_base = (void __force_user *) page_address(page);
47036 vec[i].iov_len = this_len;
47037 spd.pages[i] = page;
47039 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
47040 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
47042 while (!pipe->nrbufs) {
47043 - if (!pipe->writers)
47044 + if (!atomic_read(&pipe->writers))
47047 - if (!pipe->waiting_writers && sd->num_spliced)
47048 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
47051 if (sd->flags & SPLICE_F_NONBLOCK)
47052 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
47053 * out of the pipe right after the splice_to_pipe(). So set
47054 * PIPE_READERS appropriately.
47056 - pipe->readers = 1;
47057 + atomic_set(&pipe->readers, 1);
47059 current->splice_pipe = pipe;
47061 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
47062 ret = -ERESTARTSYS;
47065 - if (!pipe->writers)
47066 + if (!atomic_read(&pipe->writers))
47068 - if (!pipe->waiting_writers) {
47069 + if (!atomic_read(&pipe->waiting_writers)) {
47070 if (flags & SPLICE_F_NONBLOCK) {
47073 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
47076 while (pipe->nrbufs >= pipe->buffers) {
47077 - if (!pipe->readers) {
47078 + if (!atomic_read(&pipe->readers)) {
47079 send_sig(SIGPIPE, current, 0);
47082 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
47083 ret = -ERESTARTSYS;
47086 - pipe->waiting_writers++;
47087 + atomic_inc(&pipe->waiting_writers);
47089 - pipe->waiting_writers--;
47090 + atomic_dec(&pipe->waiting_writers);
47094 @@ -1819,14 +1819,14 @@ retry:
47095 pipe_double_lock(ipipe, opipe);
47098 - if (!opipe->readers) {
47099 + if (!atomic_read(&opipe->readers)) {
47100 send_sig(SIGPIPE, current, 0);
47106 - if (!ipipe->nrbufs && !ipipe->writers)
47107 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
47111 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
47112 pipe_double_lock(ipipe, opipe);
47115 - if (!opipe->readers) {
47116 + if (!atomic_read(&opipe->readers)) {
47117 send_sig(SIGPIPE, current, 0);
47120 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
47121 * return EAGAIN if we have the potential of some data in the
47122 * future, otherwise just return 0
47124 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
47125 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
47128 pipe_unlock(ipipe);
47129 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
47130 index 7fdf6a7..e6cd8ad 100644
47131 --- a/fs/sysfs/dir.c
47132 +++ b/fs/sysfs/dir.c
47133 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
47134 struct sysfs_dirent *sd;
47137 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47138 + const char *parent_name = parent_sd->s_name;
47140 + mode = S_IFDIR | S_IRWXU;
47142 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
47143 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
47144 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
47145 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
47146 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
47150 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
47152 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
47153 index 779789a..f58193c 100644
47154 --- a/fs/sysfs/file.c
47155 +++ b/fs/sysfs/file.c
47156 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
47158 struct sysfs_open_dirent {
47161 + atomic_unchecked_t event;
47162 wait_queue_head_t poll;
47163 struct list_head buffers; /* goes through sysfs_buffer.list */
47165 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
47166 if (!sysfs_get_active(attr_sd))
47169 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
47170 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
47171 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
47173 sysfs_put_active(attr_sd);
47174 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
47177 atomic_set(&new_od->refcnt, 0);
47178 - atomic_set(&new_od->event, 1);
47179 + atomic_set_unchecked(&new_od->event, 1);
47180 init_waitqueue_head(&new_od->poll);
47181 INIT_LIST_HEAD(&new_od->buffers);
47183 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
47185 sysfs_put_active(attr_sd);
47187 - if (buffer->event != atomic_read(&od->event))
47188 + if (buffer->event != atomic_read_unchecked(&od->event))
47191 return DEFAULT_POLLMASK;
47192 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
47194 od = sd->s_attr.open;
47196 - atomic_inc(&od->event);
47197 + atomic_inc_unchecked(&od->event);
47198 wake_up_interruptible(&od->poll);
47201 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
47202 index a7ac78f..02158e1 100644
47203 --- a/fs/sysfs/symlink.c
47204 +++ b/fs/sysfs/symlink.c
47205 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47207 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47209 - char *page = nd_get_link(nd);
47210 + const char *page = nd_get_link(nd);
47212 free_page((unsigned long)page);
47214 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
47215 index c175b4d..8f36a16 100644
47216 --- a/fs/udf/misc.c
47217 +++ b/fs/udf/misc.c
47218 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
47220 u8 udf_tag_checksum(const struct tag *t)
47222 - u8 *data = (u8 *)t;
47223 + const u8 *data = (const u8 *)t;
47226 for (i = 0; i < sizeof(struct tag); ++i)
47227 diff --git a/fs/utimes.c b/fs/utimes.c
47228 index ba653f3..06ea4b1 100644
47232 #include <linux/compiler.h>
47233 #include <linux/file.h>
47234 #include <linux/fs.h>
47235 +#include <linux/security.h>
47236 #include <linux/linkage.h>
47237 #include <linux/mount.h>
47238 #include <linux/namei.h>
47239 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
47240 goto mnt_drop_write_and_out;
47244 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
47246 + goto mnt_drop_write_and_out;
47249 mutex_lock(&inode->i_mutex);
47250 error = notify_change(path->dentry, &newattrs);
47251 mutex_unlock(&inode->i_mutex);
47252 diff --git a/fs/xattr.c b/fs/xattr.c
47253 index 67583de..c5aad14 100644
47256 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
47257 * Extended attribute SET operations
47260 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
47261 +setxattr(struct path *path, const char __user *name, const void __user *value,
47262 size_t size, int flags)
47265 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
47266 return PTR_ERR(kvalue);
47269 - error = vfs_setxattr(d, kname, kvalue, size, flags);
47270 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
47275 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
47280 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
47282 error = mnt_want_write(path.mnt);
47284 - error = setxattr(path.dentry, name, value, size, flags);
47285 + error = setxattr(&path, name, value, size, flags);
47286 mnt_drop_write(path.mnt);
47289 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
47291 error = mnt_want_write(path.mnt);
47293 - error = setxattr(path.dentry, name, value, size, flags);
47294 + error = setxattr(&path, name, value, size, flags);
47295 mnt_drop_write(path.mnt);
47298 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
47299 const void __user *,value, size_t, size, int, flags)
47302 - struct dentry *dentry;
47303 int error = -EBADF;
47308 - dentry = f->f_path.dentry;
47309 - audit_inode(NULL, dentry);
47310 + audit_inode(NULL, f->f_path.dentry);
47311 error = mnt_want_write_file(f);
47313 - error = setxattr(dentry, name, value, size, flags);
47314 + error = setxattr(&f->f_path, name, value, size, flags);
47315 mnt_drop_write(f->f_path.mnt);
47318 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
47319 index 8d5a506..7f62712 100644
47320 --- a/fs/xattr_acl.c
47321 +++ b/fs/xattr_acl.c
47324 posix_acl_from_xattr(const void *value, size_t size)
47326 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
47327 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
47328 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
47329 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
47331 struct posix_acl *acl;
47332 struct posix_acl_entry *acl_e;
47333 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
47334 index d0ab788..827999b 100644
47335 --- a/fs/xfs/xfs_bmap.c
47336 +++ b/fs/xfs/xfs_bmap.c
47337 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
47341 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
47342 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
47346 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
47347 index 79d05e8..e3e5861 100644
47348 --- a/fs/xfs/xfs_dir2_sf.c
47349 +++ b/fs/xfs/xfs_dir2_sf.c
47350 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
47353 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
47354 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47355 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
47356 + char name[sfep->namelen];
47357 + memcpy(name, sfep->name, sfep->namelen);
47358 + if (filldir(dirent, name, sfep->namelen,
47359 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
47360 + *offset = off & 0x7fffffff;
47363 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47364 off & 0x7fffffff, ino, DT_UNKNOWN)) {
47365 *offset = off & 0x7fffffff;
47367 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
47368 index d99a905..9f88202 100644
47369 --- a/fs/xfs/xfs_ioctl.c
47370 +++ b/fs/xfs/xfs_ioctl.c
47371 @@ -128,7 +128,7 @@ xfs_find_handle(
47375 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
47376 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
47377 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
47380 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
47381 index 23ce927..e274cc1 100644
47382 --- a/fs/xfs/xfs_iops.c
47383 +++ b/fs/xfs/xfs_iops.c
47384 @@ -447,7 +447,7 @@ xfs_vn_put_link(
47385 struct nameidata *nd,
47388 - char *s = nd_get_link(nd);
47389 + const char *s = nd_get_link(nd);
47393 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
47394 new file mode 100644
47395 index 0000000..41df561
47397 +++ b/grsecurity/Kconfig
47400 +# grecurity configuration
47406 + bool "Grsecurity"
47408 + select CRYPTO_SHA256
47410 + If you say Y here, you will be able to configure many features
47411 + that will enhance the security of your system. It is highly
47412 + recommended that you say Y here and read through the help
47413 + for each option so that you fully understand the features and
47414 + can evaluate their usefulness for your machine.
47417 + prompt "Security Level"
47418 + depends on GRKERNSEC
47419 + default GRKERNSEC_CUSTOM
47421 +config GRKERNSEC_LOW
47423 + select GRKERNSEC_LINK
47424 + select GRKERNSEC_FIFO
47425 + select GRKERNSEC_RANDNET
47426 + select GRKERNSEC_DMESG
47427 + select GRKERNSEC_CHROOT
47428 + select GRKERNSEC_CHROOT_CHDIR
47431 + If you choose this option, several of the grsecurity options will
47432 + be enabled that will give you greater protection against a number
47433 + of attacks, while assuring that none of your software will have any
47434 + conflicts with the additional security measures. If you run a lot
47435 + of unusual software, or you are having problems with the higher
47436 + security levels, you should say Y here. With this option, the
47437 + following features are enabled:
47439 + - Linking restrictions
47440 + - FIFO restrictions
47441 + - Restricted dmesg
47442 + - Enforced chdir("/") on chroot
47443 + - Runtime module disabling
47445 +config GRKERNSEC_MEDIUM
47448 + select PAX_EI_PAX
47449 + select PAX_PT_PAX_FLAGS
47450 + select PAX_HAVE_ACL_FLAGS
47451 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47452 + select GRKERNSEC_CHROOT
47453 + select GRKERNSEC_CHROOT_SYSCTL
47454 + select GRKERNSEC_LINK
47455 + select GRKERNSEC_FIFO
47456 + select GRKERNSEC_DMESG
47457 + select GRKERNSEC_RANDNET
47458 + select GRKERNSEC_FORKFAIL
47459 + select GRKERNSEC_TIME
47460 + select GRKERNSEC_SIGNAL
47461 + select GRKERNSEC_CHROOT
47462 + select GRKERNSEC_CHROOT_UNIX
47463 + select GRKERNSEC_CHROOT_MOUNT
47464 + select GRKERNSEC_CHROOT_PIVOT
47465 + select GRKERNSEC_CHROOT_DOUBLE
47466 + select GRKERNSEC_CHROOT_CHDIR
47467 + select GRKERNSEC_CHROOT_MKNOD
47468 + select GRKERNSEC_PROC
47469 + select GRKERNSEC_PROC_USERGROUP
47470 + select PAX_RANDUSTACK
47472 + select PAX_RANDMMAP
47473 + select PAX_REFCOUNT if (X86 || SPARC64)
47474 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
47477 + If you say Y here, several features in addition to those included
47478 + in the low additional security level will be enabled. These
47479 + features provide even more security to your system, though in rare
47480 + cases they may be incompatible with very old or poorly written
47481 + software. If you enable this option, make sure that your auth
47482 + service (identd) is running as gid 1001. With this option,
47483 + the following features (in addition to those provided in the
47484 + low additional security level) will be enabled:
47486 + - Failed fork logging
47487 + - Time change logging
47489 + - Deny mounts in chroot
47490 + - Deny double chrooting
47491 + - Deny sysctl writes in chroot
47492 + - Deny mknod in chroot
47493 + - Deny access to abstract AF_UNIX sockets out of chroot
47494 + - Deny pivot_root in chroot
47495 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
47496 + - /proc restrictions with special GID set to 10 (usually wheel)
47497 + - Address Space Layout Randomization (ASLR)
47498 + - Prevent exploitation of most refcount overflows
47499 + - Bounds checking of copying between the kernel and userland
47501 +config GRKERNSEC_HIGH
47503 + select GRKERNSEC_LINK
47504 + select GRKERNSEC_FIFO
47505 + select GRKERNSEC_DMESG
47506 + select GRKERNSEC_FORKFAIL
47507 + select GRKERNSEC_TIME
47508 + select GRKERNSEC_SIGNAL
47509 + select GRKERNSEC_CHROOT
47510 + select GRKERNSEC_CHROOT_SHMAT
47511 + select GRKERNSEC_CHROOT_UNIX
47512 + select GRKERNSEC_CHROOT_MOUNT
47513 + select GRKERNSEC_CHROOT_FCHDIR
47514 + select GRKERNSEC_CHROOT_PIVOT
47515 + select GRKERNSEC_CHROOT_DOUBLE
47516 + select GRKERNSEC_CHROOT_CHDIR
47517 + select GRKERNSEC_CHROOT_MKNOD
47518 + select GRKERNSEC_CHROOT_CAPS
47519 + select GRKERNSEC_CHROOT_SYSCTL
47520 + select GRKERNSEC_CHROOT_FINDTASK
47521 + select GRKERNSEC_SYSFS_RESTRICT
47522 + select GRKERNSEC_PROC
47523 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47524 + select GRKERNSEC_HIDESYM
47525 + select GRKERNSEC_BRUTE
47526 + select GRKERNSEC_PROC_USERGROUP
47527 + select GRKERNSEC_KMEM
47528 + select GRKERNSEC_RESLOG
47529 + select GRKERNSEC_RANDNET
47530 + select GRKERNSEC_PROC_ADD
47531 + select GRKERNSEC_CHROOT_CHMOD
47532 + select GRKERNSEC_CHROOT_NICE
47533 + select GRKERNSEC_SETXID
47534 + select GRKERNSEC_AUDIT_MOUNT
47535 + select GRKERNSEC_MODHARDEN if (MODULES)
47536 + select GRKERNSEC_HARDEN_PTRACE
47537 + select GRKERNSEC_PTRACE_READEXEC
47538 + select GRKERNSEC_VM86 if (X86_32)
47539 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
47541 + select PAX_RANDUSTACK
47543 + select PAX_RANDMMAP
47544 + select PAX_NOEXEC
47545 + select PAX_MPROTECT
47546 + select PAX_EI_PAX
47547 + select PAX_PT_PAX_FLAGS
47548 + select PAX_HAVE_ACL_FLAGS
47549 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
47550 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
47551 + select PAX_RANDKSTACK if (X86_TSC && X86)
47552 + select PAX_SEGMEXEC if (X86_32)
47553 + select PAX_PAGEEXEC
47554 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
47555 + select PAX_EMUTRAMP if (PARISC)
47556 + select PAX_EMUSIGRT if (PARISC)
47557 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
47558 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
47559 + select PAX_REFCOUNT if (X86 || SPARC64)
47560 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
47562 + If you say Y here, many of the features of grsecurity will be
47563 + enabled, which will protect you against many kinds of attacks
47564 + against your system. The heightened security comes at a cost
47565 + of an increased chance of incompatibilities with rare software
47566 + on your machine. Since this security level enables PaX, you should
47567 + view <http://pax.grsecurity.net> and read about the PaX
47568 + project. While you are there, download chpax and run it on
47569 + binaries that cause problems with PaX. Also remember that
47570 + since the /proc restrictions are enabled, you must run your
47571 + identd as gid 1001. This security level enables the following
47572 + features in addition to those listed in the low and medium
47575 + - Additional /proc restrictions
47576 + - Chmod restrictions in chroot
47577 + - No signals, ptrace, or viewing of processes outside of chroot
47578 + - Capability restrictions in chroot
47579 + - Deny fchdir out of chroot
47580 + - Priority restrictions in chroot
47581 + - Segmentation-based implementation of PaX
47582 + - Mprotect restrictions
47583 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
47584 + - Kernel stack randomization
47585 + - Mount/unmount/remount logging
47586 + - Kernel symbol hiding
47587 + - Hardening of module auto-loading
47588 + - Ptrace restrictions
47589 + - Restricted vm86 mode
47590 + - Restricted sysfs/debugfs
47591 + - Active kernel exploit response
47593 +config GRKERNSEC_CUSTOM
47596 + If you say Y here, you will be able to configure every grsecurity
47597 + option, which allows you to enable many more features that aren't
47598 + covered in the basic security levels. These additional features
47599 + include TPE, socket restrictions, and the sysctl system for
47600 + grsecurity. It is advised that you read through the help for
47601 + each option to determine its usefulness in your situation.
47605 +menu "Memory Protections"
47606 +depends on GRKERNSEC
47608 +config GRKERNSEC_KMEM
47609 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
47610 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
47612 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
47613 + be written to or read from to modify or leak the contents of the running
47614 + kernel. /dev/port will also not be allowed to be opened. If you have module
47615 + support disabled, enabling this will close up four ways that are
47616 + currently used to insert malicious code into the running kernel.
47617 + Even with all these features enabled, we still highly recommend that
47618 + you use the RBAC system, as it is still possible for an attacker to
47619 + modify the running kernel through privileged I/O granted by ioperm/iopl.
47620 + If you are not using XFree86, you may be able to stop this additional
47621 + case by enabling the 'Disable privileged I/O' option. Though nothing
47622 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
47623 + but only to video memory, which is the only writing we allow in this
47624 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
47625 + not be allowed to mprotect it with PROT_WRITE later.
47626 + It is highly recommended that you say Y here if you meet all the
47627 + conditions above.
47629 +config GRKERNSEC_VM86
47630 + bool "Restrict VM86 mode"
47631 + depends on X86_32
47634 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
47635 + make use of a special execution mode on 32bit x86 processors called
47636 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
47637 + video cards and will still work with this option enabled. The purpose
47638 + of the option is to prevent exploitation of emulation errors in
47639 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
47640 + Nearly all users should be able to enable this option.
47642 +config GRKERNSEC_IO
47643 + bool "Disable privileged I/O"
47646 + select RTC_INTF_DEV
47647 + select RTC_DRV_CMOS
47650 + If you say Y here, all ioperm and iopl calls will return an error.
47651 + Ioperm and iopl can be used to modify the running kernel.
47652 + Unfortunately, some programs need this access to operate properly,
47653 + the most notable of which are XFree86 and hwclock. hwclock can be
47654 + remedied by having RTC support in the kernel, so real-time
47655 + clock support is enabled if this option is enabled, to ensure
47656 + that hwclock operates correctly. XFree86 still will not
47657 + operate correctly with this option enabled, so DO NOT CHOOSE Y
47658 + IF YOU USE XFree86. If you use XFree86 and you still want to
47659 + protect your kernel against modification, use the RBAC system.
47661 +config GRKERNSEC_PROC_MEMMAP
47662 + bool "Harden ASLR against information leaks and entropy reduction"
47663 + default y if (PAX_NOEXEC || PAX_ASLR)
47664 + depends on PAX_NOEXEC || PAX_ASLR
47666 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
47667 + give no information about the addresses of its mappings if
47668 + PaX features that rely on random addresses are enabled on the task.
47669 + In addition to sanitizing this information and disabling other
47670 + dangerous sources of information, this option causes reads of sensitive
47671 + /proc/<pid> entries where the file descriptor was opened in a different
47672 + task than the one performing the read. Such attempts are logged.
47673 + Finally, this option limits argv/env strings for suid/sgid binaries
47674 + to 1MB to prevent a complete exhaustion of the stack entropy provided
47676 + If you use PaX it is essential that you say Y here as it closes up
47677 + several holes that make full ASLR useless for suid/sgid binaries.
47679 +config GRKERNSEC_BRUTE
47680 + bool "Deter exploit bruteforcing"
47682 + If you say Y here, attempts to bruteforce exploits against forking
47683 + daemons such as apache or sshd, as well as against suid/sgid binaries
47684 + will be deterred. When a child of a forking daemon is killed by PaX
47685 + or crashes due to an illegal instruction or other suspicious signal,
47686 + the parent process will be delayed 30 seconds upon every subsequent
47687 + fork until the administrator is able to assess the situation and
47688 + restart the daemon.
47689 + In the suid/sgid case, the attempt is logged, the user has all their
47690 + processes terminated, and they are prevented from executing any further
47691 + processes for 15 minutes.
47692 + It is recommended that you also enable signal logging in the auditing
47693 + section so that logs are generated when a process triggers a suspicious
47695 + If the sysctl option is enabled, a sysctl option with name
47696 + "deter_bruteforce" is created.
47699 +config GRKERNSEC_MODHARDEN
47700 + bool "Harden module auto-loading"
47701 + depends on MODULES
47703 + If you say Y here, module auto-loading in response to use of some
47704 + feature implemented by an unloaded module will be restricted to
47705 + root users. Enabling this option helps defend against attacks
47706 + by unprivileged users who abuse the auto-loading behavior to
47707 + cause a vulnerable module to load that is then exploited.
47709 + If this option prevents a legitimate use of auto-loading for a
47710 + non-root user, the administrator can execute modprobe manually
47711 + with the exact name of the module mentioned in the alert log.
47712 + Alternatively, the administrator can add the module to the list
47713 + of modules loaded at boot by modifying init scripts.
47715 + Modification of init scripts will most likely be needed on
47716 + Ubuntu servers with encrypted home directory support enabled,
47717 + as the first non-root user logging in will cause the ecb(aes),
47718 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
47720 +config GRKERNSEC_HIDESYM
47721 + bool "Hide kernel symbols"
47723 + If you say Y here, getting information on loaded modules, and
47724 + displaying all kernel symbols through a syscall will be restricted
47725 + to users with CAP_SYS_MODULE. For software compatibility reasons,
47726 + /proc/kallsyms will be restricted to the root user. The RBAC
47727 + system can hide that entry even from root.
47729 + This option also prevents leaking of kernel addresses through
47730 + several /proc entries.
47732 + Note that this option is only effective provided the following
47733 + conditions are met:
47734 + 1) The kernel using grsecurity is not precompiled by some distribution
47735 + 2) You have also enabled GRKERNSEC_DMESG
47736 + 3) You are using the RBAC system and hiding other files such as your
47737 + kernel image and System.map. Alternatively, enabling this option
47738 + causes the permissions on /boot, /lib/modules, and the kernel
47739 + source directory to change at compile time to prevent
47740 + reading by non-root users.
47741 + If the above conditions are met, this option will aid in providing a
47742 + useful protection against local kernel exploitation of overflows
47743 + and arbitrary read/write vulnerabilities.
47745 +config GRKERNSEC_KERN_LOCKOUT
47746 + bool "Active kernel exploit response"
47747 + depends on X86 || ARM || PPC || SPARC
47749 + If you say Y here, when a PaX alert is triggered due to suspicious
47750 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
47751 + or an OOPs occurs due to bad memory accesses, instead of just
47752 + terminating the offending process (and potentially allowing
47753 + a subsequent exploit from the same user), we will take one of two
47755 + If the user was root, we will panic the system
47756 + If the user was non-root, we will log the attempt, terminate
47757 + all processes owned by the user, then prevent them from creating
47758 + any new processes until the system is restarted
47759 + This deters repeated kernel exploitation/bruteforcing attempts
47760 + and is useful for later forensics.
47763 +menu "Role Based Access Control Options"
47764 +depends on GRKERNSEC
47766 +config GRKERNSEC_RBAC_DEBUG
47769 +config GRKERNSEC_NO_RBAC
47770 + bool "Disable RBAC system"
47772 + If you say Y here, the /dev/grsec device will be removed from the kernel,
47773 + preventing the RBAC system from being enabled. You should only say Y
47774 + here if you have no intention of using the RBAC system, so as to prevent
47775 + an attacker with root access from misusing the RBAC system to hide files
47776 + and processes when loadable module support and /dev/[k]mem have been
47779 +config GRKERNSEC_ACL_HIDEKERN
47780 + bool "Hide kernel processes"
47782 + If you say Y here, all kernel threads will be hidden to all
47783 + processes but those whose subject has the "view hidden processes"
47786 +config GRKERNSEC_ACL_MAXTRIES
47787 + int "Maximum tries before password lockout"
47790 + This option enforces the maximum number of times a user can attempt
47791 + to authorize themselves with the grsecurity RBAC system before being
47792 + denied the ability to attempt authorization again for a specified time.
47793 + The lower the number, the harder it will be to brute-force a password.
47795 +config GRKERNSEC_ACL_TIMEOUT
47796 + int "Time to wait after max password tries, in seconds"
47799 + This option specifies the time the user must wait after attempting to
47800 + authorize to the RBAC system with the maximum number of invalid
47801 + passwords. The higher the number, the harder it will be to brute-force
47805 +menu "Filesystem Protections"
47806 +depends on GRKERNSEC
47808 +config GRKERNSEC_PROC
47809 + bool "Proc restrictions"
47811 + If you say Y here, the permissions of the /proc filesystem
47812 + will be altered to enhance system security and privacy. You MUST
47813 + choose either a user only restriction or a user and group restriction.
47814 + Depending upon the option you choose, you can either restrict users to
47815 + see only the processes they themselves run, or choose a group that can
47816 + view all processes and files normally restricted to root if you choose
47817 + the "restrict to user only" option. NOTE: If you're running identd as
47818 + a non-root user, you will have to run it as the group you specify here.
47820 +config GRKERNSEC_PROC_USER
47821 + bool "Restrict /proc to user only"
47822 + depends on GRKERNSEC_PROC
47824 + If you say Y here, non-root users will only be able to view their own
47825 + processes, and restricts them from viewing network-related information,
47826 + and viewing kernel symbol and module information.
47828 +config GRKERNSEC_PROC_USERGROUP
47829 + bool "Allow special group"
47830 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
47832 + If you say Y here, you will be able to select a group that will be
47833 + able to view all processes and network-related information. If you've
47834 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
47835 + remain hidden. This option is useful if you want to run identd as
47838 +config GRKERNSEC_PROC_GID
47839 + int "GID for special group"
47840 + depends on GRKERNSEC_PROC_USERGROUP
47843 +config GRKERNSEC_PROC_ADD
47844 + bool "Additional restrictions"
47845 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
47847 + If you say Y here, additional restrictions will be placed on
47848 + /proc that keep normal users from viewing device information and
47849 + slabinfo information that could be useful for exploits.
47851 +config GRKERNSEC_LINK
47852 + bool "Linking restrictions"
47854 + If you say Y here, /tmp race exploits will be prevented, since users
47855 + will no longer be able to follow symlinks owned by other users in
47856 + world-writable +t directories (e.g. /tmp), unless the owner of the
47857 + symlink is the owner of the directory. users will also not be
47858 + able to hardlink to files they do not own. If the sysctl option is
47859 + enabled, a sysctl option with name "linking_restrictions" is created.
47861 +config GRKERNSEC_FIFO
47862 + bool "FIFO restrictions"
47864 + If you say Y here, users will not be able to write to FIFOs they don't
47865 + own in world-writable +t directories (e.g. /tmp), unless the owner of
47866 + the FIFO is the same owner of the directory it's held in. If the sysctl
47867 + option is enabled, a sysctl option with name "fifo_restrictions" is
47870 +config GRKERNSEC_SYSFS_RESTRICT
47871 + bool "Sysfs/debugfs restriction"
47874 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
47875 + any filesystem normally mounted under it (e.g. debugfs) will be
47876 + mostly accessible only by root. These filesystems generally provide access
47877 + to hardware and debug information that isn't appropriate for unprivileged
47878 + users of the system. Sysfs and debugfs have also become a large source
47879 + of new vulnerabilities, ranging from infoleaks to local compromise.
47880 + There has been very little oversight with an eye toward security involved
47881 + in adding new exporters of information to these filesystems, so their
47882 + use is discouraged.
47883 + For reasons of compatibility, a few directories have been whitelisted
47884 + for access by non-root users:
47887 + /sys/devices/system/cpu
47889 +config GRKERNSEC_ROFS
47890 + bool "Runtime read-only mount protection"
47892 + If you say Y here, a sysctl option with name "romount_protect" will
47893 + be created. By setting this option to 1 at runtime, filesystems
47894 + will be protected in the following ways:
47895 + * No new writable mounts will be allowed
47896 + * Existing read-only mounts won't be able to be remounted read/write
47897 + * Write operations will be denied on all block devices
47898 + This option acts independently of grsec_lock: once it is set to 1,
47899 + it cannot be turned off. Therefore, please be mindful of the resulting
47900 + behavior if this option is enabled in an init script on a read-only
47901 + filesystem. This feature is mainly intended for secure embedded systems.
47903 +config GRKERNSEC_CHROOT
47904 + bool "Chroot jail restrictions"
47906 + If you say Y here, you will be able to choose several options that will
47907 + make breaking out of a chrooted jail much more difficult. If you
47908 + encounter no software incompatibilities with the following options, it
47909 + is recommended that you enable each one.
47911 +config GRKERNSEC_CHROOT_MOUNT
47912 + bool "Deny mounts"
47913 + depends on GRKERNSEC_CHROOT
47915 + If you say Y here, processes inside a chroot will not be able to
47916 + mount or remount filesystems. If the sysctl option is enabled, a
47917 + sysctl option with name "chroot_deny_mount" is created.
47919 +config GRKERNSEC_CHROOT_DOUBLE
47920 + bool "Deny double-chroots"
47921 + depends on GRKERNSEC_CHROOT
47923 + If you say Y here, processes inside a chroot will not be able to chroot
47924 + again outside the chroot. This is a widely used method of breaking
47925 + out of a chroot jail and should not be allowed. If the sysctl
47926 + option is enabled, a sysctl option with name
47927 + "chroot_deny_chroot" is created.
47929 +config GRKERNSEC_CHROOT_PIVOT
47930 + bool "Deny pivot_root in chroot"
47931 + depends on GRKERNSEC_CHROOT
47933 + If you say Y here, processes inside a chroot will not be able to use
47934 + a function called pivot_root() that was introduced in Linux 2.3.41. It
47935 + works similar to chroot in that it changes the root filesystem. This
47936 + function could be misused in a chrooted process to attempt to break out
47937 + of the chroot, and therefore should not be allowed. If the sysctl
47938 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
47941 +config GRKERNSEC_CHROOT_CHDIR
47942 + bool "Enforce chdir(\"/\") on all chroots"
47943 + depends on GRKERNSEC_CHROOT
47945 + If you say Y here, the current working directory of all newly-chrooted
47946 + applications will be set to the the root directory of the chroot.
47947 + The man page on chroot(2) states:
47948 + Note that this call does not change the current working
47949 + directory, so that `.' can be outside the tree rooted at
47950 + `/'. In particular, the super-user can escape from a
47951 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
47953 + It is recommended that you say Y here, since it's not known to break
47954 + any software. If the sysctl option is enabled, a sysctl option with
47955 + name "chroot_enforce_chdir" is created.
47957 +config GRKERNSEC_CHROOT_CHMOD
47958 + bool "Deny (f)chmod +s"
47959 + depends on GRKERNSEC_CHROOT
47961 + If you say Y here, processes inside a chroot will not be able to chmod
47962 + or fchmod files to make them have suid or sgid bits. This protects
47963 + against another published method of breaking a chroot. If the sysctl
47964 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
47967 +config GRKERNSEC_CHROOT_FCHDIR
47968 + bool "Deny fchdir out of chroot"
47969 + depends on GRKERNSEC_CHROOT
47971 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
47972 + to a file descriptor of the chrooting process that points to a directory
47973 + outside the filesystem will be stopped. If the sysctl option
47974 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
47976 +config GRKERNSEC_CHROOT_MKNOD
47977 + bool "Deny mknod"
47978 + depends on GRKERNSEC_CHROOT
47980 + If you say Y here, processes inside a chroot will not be allowed to
47981 + mknod. The problem with using mknod inside a chroot is that it
47982 + would allow an attacker to create a device entry that is the same
47983 + as one on the physical root of your system, which could range from
47984 + anything from the console device to a device for your harddrive (which
47985 + they could then use to wipe the drive or steal data). It is recommended
47986 + that you say Y here, unless you run into software incompatibilities.
47987 + If the sysctl option is enabled, a sysctl option with name
47988 + "chroot_deny_mknod" is created.
47990 +config GRKERNSEC_CHROOT_SHMAT
47991 + bool "Deny shmat() out of chroot"
47992 + depends on GRKERNSEC_CHROOT
47994 + If you say Y here, processes inside a chroot will not be able to attach
47995 + to shared memory segments that were created outside of the chroot jail.
47996 + It is recommended that you say Y here. If the sysctl option is enabled,
47997 + a sysctl option with name "chroot_deny_shmat" is created.
47999 +config GRKERNSEC_CHROOT_UNIX
48000 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
48001 + depends on GRKERNSEC_CHROOT
48003 + If you say Y here, processes inside a chroot will not be able to
48004 + connect to abstract (meaning not belonging to a filesystem) Unix
48005 + domain sockets that were bound outside of a chroot. It is recommended
48006 + that you say Y here. If the sysctl option is enabled, a sysctl option
48007 + with name "chroot_deny_unix" is created.
48009 +config GRKERNSEC_CHROOT_FINDTASK
48010 + bool "Protect outside processes"
48011 + depends on GRKERNSEC_CHROOT
48013 + If you say Y here, processes inside a chroot will not be able to
48014 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
48015 + getsid, or view any process outside of the chroot. If the sysctl
48016 + option is enabled, a sysctl option with name "chroot_findtask" is
48019 +config GRKERNSEC_CHROOT_NICE
48020 + bool "Restrict priority changes"
48021 + depends on GRKERNSEC_CHROOT
48023 + If you say Y here, processes inside a chroot will not be able to raise
48024 + the priority of processes in the chroot, or alter the priority of
48025 + processes outside the chroot. This provides more security than simply
48026 + removing CAP_SYS_NICE from the process' capability set. If the
48027 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
48030 +config GRKERNSEC_CHROOT_SYSCTL
48031 + bool "Deny sysctl writes"
48032 + depends on GRKERNSEC_CHROOT
48034 + If you say Y here, an attacker in a chroot will not be able to
48035 + write to sysctl entries, either by sysctl(2) or through a /proc
48036 + interface. It is strongly recommended that you say Y here. If the
48037 + sysctl option is enabled, a sysctl option with name
48038 + "chroot_deny_sysctl" is created.
48040 +config GRKERNSEC_CHROOT_CAPS
48041 + bool "Capability restrictions"
48042 + depends on GRKERNSEC_CHROOT
48044 + If you say Y here, the capabilities on all processes within a
48045 + chroot jail will be lowered to stop module insertion, raw i/o,
48046 + system and net admin tasks, rebooting the system, modifying immutable
48047 + files, modifying IPC owned by another, and changing the system time.
48048 + This is left an option because it can break some apps. Disable this
48049 + if your chrooted apps are having problems performing those kinds of
48050 + tasks. If the sysctl option is enabled, a sysctl option with
48051 + name "chroot_caps" is created.
48054 +menu "Kernel Auditing"
48055 +depends on GRKERNSEC
48057 +config GRKERNSEC_AUDIT_GROUP
48058 + bool "Single group for auditing"
48060 + If you say Y here, the exec, chdir, and (un)mount logging features
48061 + will only operate on a group you specify. This option is recommended
48062 + if you only want to watch certain users instead of having a large
48063 + amount of logs from the entire system. If the sysctl option is enabled,
48064 + a sysctl option with name "audit_group" is created.
48066 +config GRKERNSEC_AUDIT_GID
48067 + int "GID for auditing"
48068 + depends on GRKERNSEC_AUDIT_GROUP
48071 +config GRKERNSEC_EXECLOG
48072 + bool "Exec logging"
48074 + If you say Y here, all execve() calls will be logged (since the
48075 + other exec*() calls are frontends to execve(), all execution
48076 + will be logged). Useful for shell-servers that like to keep track
48077 + of their users. If the sysctl option is enabled, a sysctl option with
48078 + name "exec_logging" is created.
48079 + WARNING: This option when enabled will produce a LOT of logs, especially
48080 + on an active system.
48082 +config GRKERNSEC_RESLOG
48083 + bool "Resource logging"
48085 + If you say Y here, all attempts to overstep resource limits will
48086 + be logged with the resource name, the requested size, and the current
48087 + limit. It is highly recommended that you say Y here. If the sysctl
48088 + option is enabled, a sysctl option with name "resource_logging" is
48089 + created. If the RBAC system is enabled, the sysctl value is ignored.
48091 +config GRKERNSEC_CHROOT_EXECLOG
48092 + bool "Log execs within chroot"
48094 + If you say Y here, all executions inside a chroot jail will be logged
48095 + to syslog. This can cause a large amount of logs if certain
48096 + applications (eg. djb's daemontools) are installed on the system, and
48097 + is therefore left as an option. If the sysctl option is enabled, a
48098 + sysctl option with name "chroot_execlog" is created.
48100 +config GRKERNSEC_AUDIT_PTRACE
48101 + bool "Ptrace logging"
48103 + If you say Y here, all attempts to attach to a process via ptrace
48104 + will be logged. If the sysctl option is enabled, a sysctl option
48105 + with name "audit_ptrace" is created.
48107 +config GRKERNSEC_AUDIT_CHDIR
48108 + bool "Chdir logging"
48110 + If you say Y here, all chdir() calls will be logged. If the sysctl
48111 + option is enabled, a sysctl option with name "audit_chdir" is created.
48113 +config GRKERNSEC_AUDIT_MOUNT
48114 + bool "(Un)Mount logging"
48116 + If you say Y here, all mounts and unmounts will be logged. If the
48117 + sysctl option is enabled, a sysctl option with name "audit_mount" is
48120 +config GRKERNSEC_SIGNAL
48121 + bool "Signal logging"
48123 + If you say Y here, certain important signals will be logged, such as
48124 + SIGSEGV, which will as a result inform you of when a error in a program
48125 + occurred, which in some cases could mean a possible exploit attempt.
48126 + If the sysctl option is enabled, a sysctl option with name
48127 + "signal_logging" is created.
48129 +config GRKERNSEC_FORKFAIL
48130 + bool "Fork failure logging"
48132 + If you say Y here, all failed fork() attempts will be logged.
48133 + This could suggest a fork bomb, or someone attempting to overstep
48134 + their process limit. If the sysctl option is enabled, a sysctl option
48135 + with name "forkfail_logging" is created.
48137 +config GRKERNSEC_TIME
48138 + bool "Time change logging"
48140 + If you say Y here, any changes of the system clock will be logged.
48141 + If the sysctl option is enabled, a sysctl option with name
48142 + "timechange_logging" is created.
48144 +config GRKERNSEC_PROC_IPADDR
48145 + bool "/proc/<pid>/ipaddr support"
48147 + If you say Y here, a new entry will be added to each /proc/<pid>
48148 + directory that contains the IP address of the person using the task.
48149 + The IP is carried across local TCP and AF_UNIX stream sockets.
48150 + This information can be useful for IDS/IPSes to perform remote response
48151 + to a local attack. The entry is readable by only the owner of the
48152 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
48153 + the RBAC system), and thus does not create privacy concerns.
48155 +config GRKERNSEC_RWXMAP_LOG
48156 + bool 'Denied RWX mmap/mprotect logging'
48157 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
48159 + If you say Y here, calls to mmap() and mprotect() with explicit
48160 + usage of PROT_WRITE and PROT_EXEC together will be logged when
48161 + denied by the PAX_MPROTECT feature. If the sysctl option is
48162 + enabled, a sysctl option with name "rwxmap_logging" is created.
48164 +config GRKERNSEC_AUDIT_TEXTREL
48165 + bool 'ELF text relocations logging (READ HELP)'
48166 + depends on PAX_MPROTECT
48168 + If you say Y here, text relocations will be logged with the filename
48169 + of the offending library or binary. The purpose of the feature is
48170 + to help Linux distribution developers get rid of libraries and
48171 + binaries that need text relocations which hinder the future progress
48172 + of PaX. Only Linux distribution developers should say Y here, and
48173 + never on a production machine, as this option creates an information
48174 + leak that could aid an attacker in defeating the randomization of
48175 + a single memory region. If the sysctl option is enabled, a sysctl
48176 + option with name "audit_textrel" is created.
48180 +menu "Executable Protections"
48181 +depends on GRKERNSEC
48183 +config GRKERNSEC_DMESG
48184 + bool "Dmesg(8) restriction"
48186 + If you say Y here, non-root users will not be able to use dmesg(8)
48187 + to view up to the last 4kb of messages in the kernel's log buffer.
48188 + The kernel's log buffer often contains kernel addresses and other
48189 + identifying information useful to an attacker in fingerprinting a
48190 + system for a targeted exploit.
48191 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
48194 +config GRKERNSEC_HARDEN_PTRACE
48195 + bool "Deter ptrace-based process snooping"
48197 + If you say Y here, TTY sniffers and other malicious monitoring
48198 + programs implemented through ptrace will be defeated. If you
48199 + have been using the RBAC system, this option has already been
48200 + enabled for several years for all users, with the ability to make
48201 + fine-grained exceptions.
48203 + This option only affects the ability of non-root users to ptrace
48204 + processes that are not a descendent of the ptracing process.
48205 + This means that strace ./binary and gdb ./binary will still work,
48206 + but attaching to arbitrary processes will not. If the sysctl
48207 + option is enabled, a sysctl option with name "harden_ptrace" is
48210 +config GRKERNSEC_PTRACE_READEXEC
48211 + bool "Require read access to ptrace sensitive binaries"
48213 + If you say Y here, unprivileged users will not be able to ptrace unreadable
48214 + binaries. This option is useful in environments that
48215 + remove the read bits (e.g. file mode 4711) from suid binaries to
48216 + prevent infoleaking of their contents. This option adds
48217 + consistency to the use of that file mode, as the binary could normally
48218 + be read out when run without privileges while ptracing.
48220 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
48223 +config GRKERNSEC_SETXID
48224 + bool "Enforce consistent multithreaded privileges"
48226 + If you say Y here, a change from a root uid to a non-root uid
48227 + in a multithreaded application will cause the resulting uids,
48228 + gids, supplementary groups, and capabilities in that thread
48229 + to be propagated to the other threads of the process. In most
48230 + cases this is unnecessary, as glibc will emulate this behavior
48231 + on behalf of the application. Other libcs do not act in the
48232 + same way, allowing the other threads of the process to continue
48233 + running with root privileges. If the sysctl option is enabled,
48234 + a sysctl option with name "consistent_setxid" is created.
48236 +config GRKERNSEC_TPE
48237 + bool "Trusted Path Execution (TPE)"
48239 + If you say Y here, you will be able to choose a gid to add to the
48240 + supplementary groups of users you want to mark as "untrusted."
48241 + These users will not be able to execute any files that are not in
48242 + root-owned directories writable only by root. If the sysctl option
48243 + is enabled, a sysctl option with name "tpe" is created.
48245 +config GRKERNSEC_TPE_ALL
48246 + bool "Partially restrict all non-root users"
48247 + depends on GRKERNSEC_TPE
48249 + If you say Y here, all non-root users will be covered under
48250 + a weaker TPE restriction. This is separate from, and in addition to,
48251 + the main TPE options that you have selected elsewhere. Thus, if a
48252 + "trusted" GID is chosen, this restriction applies to even that GID.
48253 + Under this restriction, all non-root users will only be allowed to
48254 + execute files in directories they own that are not group or
48255 + world-writable, or in directories owned by root and writable only by
48256 + root. If the sysctl option is enabled, a sysctl option with name
48257 + "tpe_restrict_all" is created.
48259 +config GRKERNSEC_TPE_INVERT
48260 + bool "Invert GID option"
48261 + depends on GRKERNSEC_TPE
48263 + If you say Y here, the group you specify in the TPE configuration will
48264 + decide what group TPE restrictions will be *disabled* for. This
48265 + option is useful if you want TPE restrictions to be applied to most
48266 + users on the system. If the sysctl option is enabled, a sysctl option
48267 + with name "tpe_invert" is created. Unlike other sysctl options, this
48268 + entry will default to on for backward-compatibility.
48270 +config GRKERNSEC_TPE_GID
48271 + int "GID for untrusted users"
48272 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
48275 + Setting this GID determines what group TPE restrictions will be
48276 + *enabled* for. If the sysctl option is enabled, a sysctl option
48277 + with name "tpe_gid" is created.
48279 +config GRKERNSEC_TPE_GID
48280 + int "GID for trusted users"
48281 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
48284 + Setting this GID determines what group TPE restrictions will be
48285 + *disabled* for. If the sysctl option is enabled, a sysctl option
48286 + with name "tpe_gid" is created.
48289 +menu "Network Protections"
48290 +depends on GRKERNSEC
48292 +config GRKERNSEC_RANDNET
48293 + bool "Larger entropy pools"
48295 + If you say Y here, the entropy pools used for many features of Linux
48296 + and grsecurity will be doubled in size. Since several grsecurity
48297 + features use additional randomness, it is recommended that you say Y
48298 + here. Saying Y here has a similar effect as modifying
48299 + /proc/sys/kernel/random/poolsize.
48301 +config GRKERNSEC_BLACKHOLE
48302 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
48305 + If you say Y here, neither TCP resets nor ICMP
48306 + destination-unreachable packets will be sent in response to packets
48307 + sent to ports for which no associated listening process exists.
48308 + This feature supports both IPV4 and IPV6 and exempts the
48309 + loopback interface from blackholing. Enabling this feature
48310 + makes a host more resilient to DoS attacks and reduces network
48311 + visibility against scanners.
48313 + The blackhole feature as-implemented is equivalent to the FreeBSD
48314 + blackhole feature, as it prevents RST responses to all packets, not
48315 + just SYNs. Under most application behavior this causes no
48316 + problems, but applications (like haproxy) may not close certain
48317 + connections in a way that cleanly terminates them on the remote
48318 + end, leaving the remote host in LAST_ACK state. Because of this
48319 + side-effect and to prevent intentional LAST_ACK DoSes, this
48320 + feature also adds automatic mitigation against such attacks.
48321 + The mitigation drastically reduces the amount of time a socket
48322 + can spend in LAST_ACK state. If you're using haproxy and not
48323 + all servers it connects to have this option enabled, consider
48324 + disabling this feature on the haproxy host.
48326 + If the sysctl option is enabled, two sysctl options with names
48327 + "ip_blackhole" and "lastack_retries" will be created.
48328 + While "ip_blackhole" takes the standard zero/non-zero on/off
48329 + toggle, "lastack_retries" uses the same kinds of values as
48330 + "tcp_retries1" and "tcp_retries2". The default value of 4
48331 + prevents a socket from lasting more than 45 seconds in LAST_ACK
48334 +config GRKERNSEC_SOCKET
48335 + bool "Socket restrictions"
48338 + If you say Y here, you will be able to choose from several options.
48339 + If you assign a GID on your system and add it to the supplementary
48340 + groups of users you want to restrict socket access to, this patch
48341 + will perform up to three things, based on the option(s) you choose.
48343 +config GRKERNSEC_SOCKET_ALL
48344 + bool "Deny any sockets to group"
48345 + depends on GRKERNSEC_SOCKET
48347 + If you say Y here, you will be able to choose a GID of whose users will
48348 + be unable to connect to other hosts from your machine or run server
48349 + applications from your machine. If the sysctl option is enabled, a
48350 + sysctl option with name "socket_all" is created.
48352 +config GRKERNSEC_SOCKET_ALL_GID
48353 + int "GID to deny all sockets for"
48354 + depends on GRKERNSEC_SOCKET_ALL
48357 + Here you can choose the GID to disable socket access for. Remember to
48358 + add the users you want socket access disabled for to the GID
48359 + specified here. If the sysctl option is enabled, a sysctl option
48360 + with name "socket_all_gid" is created.
48362 +config GRKERNSEC_SOCKET_CLIENT
48363 + bool "Deny client sockets to group"
48364 + depends on GRKERNSEC_SOCKET
48366 + If you say Y here, you will be able to choose a GID of whose users will
48367 + be unable to connect to other hosts from your machine, but will be
48368 + able to run servers. If this option is enabled, all users in the group
48369 + you specify will have to use passive mode when initiating ftp transfers
48370 + from the shell on your machine. If the sysctl option is enabled, a
48371 + sysctl option with name "socket_client" is created.
48373 +config GRKERNSEC_SOCKET_CLIENT_GID
48374 + int "GID to deny client sockets for"
48375 + depends on GRKERNSEC_SOCKET_CLIENT
48378 + Here you can choose the GID to disable client socket access for.
48379 + Remember to add the users you want client socket access disabled for to
48380 + the GID specified here. If the sysctl option is enabled, a sysctl
48381 + option with name "socket_client_gid" is created.
48383 +config GRKERNSEC_SOCKET_SERVER
48384 + bool "Deny server sockets to group"
48385 + depends on GRKERNSEC_SOCKET
48387 + If you say Y here, you will be able to choose a GID of whose users will
48388 + be unable to run server applications from your machine. If the sysctl
48389 + option is enabled, a sysctl option with name "socket_server" is created.
48391 +config GRKERNSEC_SOCKET_SERVER_GID
48392 + int "GID to deny server sockets for"
48393 + depends on GRKERNSEC_SOCKET_SERVER
48396 + Here you can choose the GID to disable server socket access for.
48397 + Remember to add the users you want server socket access disabled for to
48398 + the GID specified here. If the sysctl option is enabled, a sysctl
48399 + option with name "socket_server_gid" is created.
48402 +menu "Sysctl support"
48403 +depends on GRKERNSEC && SYSCTL
48405 +config GRKERNSEC_SYSCTL
48406 + bool "Sysctl support"
48408 + If you say Y here, you will be able to change the options that
48409 + grsecurity runs with at bootup, without having to recompile your
48410 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
48411 + to enable (1) or disable (0) various features. All the sysctl entries
48412 + are mutable until the "grsec_lock" entry is set to a non-zero value.
48413 + All features enabled in the kernel configuration are disabled at boot
48414 + if you do not say Y to the "Turn on features by default" option.
48415 + All options should be set at startup, and the grsec_lock entry should
48416 + be set to a non-zero value after all the options are set.
48417 + *THIS IS EXTREMELY IMPORTANT*
48419 +config GRKERNSEC_SYSCTL_DISTRO
48420 + bool "Extra sysctl support for distro makers (READ HELP)"
48421 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
48423 + If you say Y here, additional sysctl options will be created
48424 + for features that affect processes running as root. Therefore,
48425 + it is critical when using this option that the grsec_lock entry be
48426 + enabled after boot. Only distros with prebuilt kernel packages
48427 + with this option enabled that can ensure grsec_lock is enabled
48428 + after boot should use this option.
48429 + *Failure to set grsec_lock after boot makes all grsec features
48430 + this option covers useless*
48432 + Currently this option creates the following sysctl entries:
48433 + "Disable Privileged I/O": "disable_priv_io"
48435 +config GRKERNSEC_SYSCTL_ON
48436 + bool "Turn on features by default"
48437 + depends on GRKERNSEC_SYSCTL
48439 + If you say Y here, instead of having all features enabled in the
48440 + kernel configuration disabled at boot time, the features will be
48441 + enabled at boot time. It is recommended you say Y here unless
48442 + there is some reason you would want all sysctl-tunable features to
48443 + be disabled by default. As mentioned elsewhere, it is important
48444 + to enable the grsec_lock entry once you have finished modifying
48445 + the sysctl entries.
48448 +menu "Logging Options"
48449 +depends on GRKERNSEC
48451 +config GRKERNSEC_FLOODTIME
48452 + int "Seconds in between log messages (minimum)"
48455 + This option allows you to enforce the number of seconds between
48456 + grsecurity log messages. The default should be suitable for most
48457 + people, however, if you choose to change it, choose a value small enough
48458 + to allow informative logs to be produced, but large enough to
48459 + prevent flooding.
48461 +config GRKERNSEC_FLOODBURST
48462 + int "Number of messages in a burst (maximum)"
48465 + This option allows you to choose the maximum number of messages allowed
48466 + within the flood time interval you chose in a separate option. The
48467 + default should be suitable for most people, however if you find that
48468 + many of your logs are being interpreted as flooding, you may want to
48469 + raise this value.
48474 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
48475 new file mode 100644
48476 index 0000000..496e60d
48478 +++ b/grsecurity/Makefile
48480 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
48481 +# during 2001-2009 it has been completely redesigned by Brad Spengler
48482 +# into an RBAC system
48484 +# All code in this directory and various hooks inserted throughout the kernel
48485 +# are copyright Brad Spengler - Open Source Security, Inc., and released
48486 +# under the GPL v2 or higher
48488 +ifndef CONFIG_IA64
48489 +KBUILD_CFLAGS += -Werror
48492 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
48493 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
48494 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
48496 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
48497 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
48498 + gracl_learn.o grsec_log.o
48499 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
48502 +obj-y += grsec_sock.o
48503 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
48506 +ifndef CONFIG_GRKERNSEC
48507 +obj-y += grsec_disabled.o
48510 +ifdef CONFIG_GRKERNSEC_HIDESYM
48511 +extra-y := grsec_hidesym.o
48512 +$(obj)/grsec_hidesym.o:
48513 + @-chmod -f 500 /boot
48514 + @-chmod -f 500 /lib/modules
48515 + @-chmod -f 500 /lib64/modules
48516 + @-chmod -f 500 /lib32/modules
48518 + @echo ' grsec: protected kernel image paths'
48520 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
48521 new file mode 100644
48522 index 0000000..2733872
48524 +++ b/grsecurity/gracl.c
48526 +#include <linux/kernel.h>
48527 +#include <linux/module.h>
48528 +#include <linux/sched.h>
48529 +#include <linux/mm.h>
48530 +#include <linux/file.h>
48531 +#include <linux/fs.h>
48532 +#include <linux/namei.h>
48533 +#include <linux/mount.h>
48534 +#include <linux/tty.h>
48535 +#include <linux/proc_fs.h>
48536 +#include <linux/lglock.h>
48537 +#include <linux/slab.h>
48538 +#include <linux/vmalloc.h>
48539 +#include <linux/types.h>
48540 +#include <linux/sysctl.h>
48541 +#include <linux/netdevice.h>
48542 +#include <linux/ptrace.h>
48543 +#include <linux/gracl.h>
48544 +#include <linux/gralloc.h>
48545 +#include <linux/security.h>
48546 +#include <linux/grinternal.h>
48547 +#include <linux/pid_namespace.h>
48548 +#include <linux/fdtable.h>
48549 +#include <linux/percpu.h>
48551 +#include <asm/uaccess.h>
48552 +#include <asm/errno.h>
48553 +#include <asm/mman.h>
48555 +static struct acl_role_db acl_role_set;
48556 +static struct name_db name_set;
48557 +static struct inodev_db inodev_set;
48559 +/* for keeping track of userspace pointers used for subjects, so we
48560 + can share references in the kernel as well
48563 +static struct path real_root;
48565 +static struct acl_subj_map_db subj_map_set;
48567 +static struct acl_role_label *default_role;
48569 +static struct acl_role_label *role_list;
48571 +static u16 acl_sp_role_value;
48573 +extern char *gr_shared_page[4];
48574 +static DEFINE_MUTEX(gr_dev_mutex);
48575 +DEFINE_RWLOCK(gr_inode_lock);
48577 +struct gr_arg *gr_usermode;
48579 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
48581 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
48582 +extern void gr_clear_learn_entries(void);
48584 +#ifdef CONFIG_GRKERNSEC_RESLOG
48585 +extern void gr_log_resource(const struct task_struct *task,
48586 + const int res, const unsigned long wanted, const int gt);
48589 +unsigned char *gr_system_salt;
48590 +unsigned char *gr_system_sum;
48592 +static struct sprole_pw **acl_special_roles = NULL;
48593 +static __u16 num_sprole_pws = 0;
48595 +static struct acl_role_label *kernel_role = NULL;
48597 +static unsigned int gr_auth_attempts = 0;
48598 +static unsigned long gr_auth_expires = 0UL;
48601 +extern struct vfsmount *sock_mnt;
48604 +extern struct vfsmount *pipe_mnt;
48605 +extern struct vfsmount *shm_mnt;
48606 +#ifdef CONFIG_HUGETLBFS
48607 +extern struct vfsmount *hugetlbfs_vfsmount;
48610 +static struct acl_object_label *fakefs_obj_rw;
48611 +static struct acl_object_label *fakefs_obj_rwx;
48613 +extern int gr_init_uidset(void);
48614 +extern void gr_free_uidset(void);
48615 +extern void gr_remove_uid(uid_t uid);
48616 +extern int gr_find_uid(uid_t uid);
48618 +DECLARE_BRLOCK(vfsmount_lock);
48621 +gr_acl_is_enabled(void)
48623 + return (gr_status & GR_READY);
48626 +#ifdef CONFIG_BTRFS_FS
48627 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
48628 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
48631 +static inline dev_t __get_dev(const struct dentry *dentry)
48633 +#ifdef CONFIG_BTRFS_FS
48634 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
48635 + return get_btrfs_dev_from_inode(dentry->d_inode);
48638 + return dentry->d_inode->i_sb->s_dev;
48641 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
48643 + return __get_dev(dentry);
48646 +static char gr_task_roletype_to_char(struct task_struct *task)
48648 + switch (task->role->roletype &
48649 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
48650 + GR_ROLE_SPECIAL)) {
48651 + case GR_ROLE_DEFAULT:
48653 + case GR_ROLE_USER:
48655 + case GR_ROLE_GROUP:
48657 + case GR_ROLE_SPECIAL:
48664 +char gr_roletype_to_char(void)
48666 + return gr_task_roletype_to_char(current);
48670 +gr_acl_tpe_check(void)
48672 + if (unlikely(!(gr_status & GR_READY)))
48674 + if (current->role->roletype & GR_ROLE_TPE)
48681 +gr_handle_rawio(const struct inode *inode)
48683 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
48684 + if (inode && S_ISBLK(inode->i_mode) &&
48685 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
48686 + !capable(CAP_SYS_RAWIO))
48693 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
48695 + if (likely(lena != lenb))
48698 + return !memcmp(a, b, lena);
48701 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
48703 + *buflen -= namelen;
48705 + return -ENAMETOOLONG;
48706 + *buffer -= namelen;
48707 + memcpy(*buffer, str, namelen);
48711 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
48713 + return prepend(buffer, buflen, name->name, name->len);
48716 +static int prepend_path(const struct path *path, struct path *root,
48717 + char **buffer, int *buflen)
48719 + struct dentry *dentry = path->dentry;
48720 + struct vfsmount *vfsmnt = path->mnt;
48721 + bool slash = false;
48724 + while (dentry != root->dentry || vfsmnt != root->mnt) {
48725 + struct dentry * parent;
48727 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
48728 + /* Global root? */
48729 + if (vfsmnt->mnt_parent == vfsmnt) {
48732 + dentry = vfsmnt->mnt_mountpoint;
48733 + vfsmnt = vfsmnt->mnt_parent;
48736 + parent = dentry->d_parent;
48737 + prefetch(parent);
48738 + spin_lock(&dentry->d_lock);
48739 + error = prepend_name(buffer, buflen, &dentry->d_name);
48740 + spin_unlock(&dentry->d_lock);
48742 + error = prepend(buffer, buflen, "/", 1);
48751 + if (!error && !slash)
48752 + error = prepend(buffer, buflen, "/", 1);
48757 +/* this must be called with vfsmount_lock and rename_lock held */
48759 +static char *__our_d_path(const struct path *path, struct path *root,
48760 + char *buf, int buflen)
48762 + char *res = buf + buflen;
48765 + prepend(&res, &buflen, "\0", 1);
48766 + error = prepend_path(path, root, &res, &buflen);
48768 + return ERR_PTR(error);
48774 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
48778 + retval = __our_d_path(path, root, buf, buflen);
48779 + if (unlikely(IS_ERR(retval)))
48780 + retval = strcpy(buf, "<path too long>");
48781 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
48782 + retval[1] = '\0';
48788 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48789 + char *buf, int buflen)
48791 + struct path path;
48794 + path.dentry = (struct dentry *)dentry;
48795 + path.mnt = (struct vfsmount *)vfsmnt;
48797 + /* we can use real_root.dentry, real_root.mnt, because this is only called
48798 + by the RBAC system */
48799 + res = gen_full_path(&path, &real_root, buf, buflen);
48805 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48806 + char *buf, int buflen)
48809 + struct path path;
48810 + struct path root;
48811 + struct task_struct *reaper = &init_task;
48813 + path.dentry = (struct dentry *)dentry;
48814 + path.mnt = (struct vfsmount *)vfsmnt;
48816 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
48817 + get_fs_root(reaper->fs, &root);
48819 + write_seqlock(&rename_lock);
48820 + br_read_lock(vfsmount_lock);
48821 + res = gen_full_path(&path, &root, buf, buflen);
48822 + br_read_unlock(vfsmount_lock);
48823 + write_sequnlock(&rename_lock);
48830 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48833 + write_seqlock(&rename_lock);
48834 + br_read_lock(vfsmount_lock);
48835 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48837 + br_read_unlock(vfsmount_lock);
48838 + write_sequnlock(&rename_lock);
48843 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48849 + write_seqlock(&rename_lock);
48850 + br_read_lock(vfsmount_lock);
48851 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
48852 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
48853 + buflen = (int)(ret - buf);
48855 + prepend(&ret, &buflen, "/proc", 5);
48857 + ret = strcpy(buf, "<path too long>");
48858 + br_read_unlock(vfsmount_lock);
48859 + write_sequnlock(&rename_lock);
48864 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
48866 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48871 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
48873 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
48878 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
48880 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
48885 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
48887 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
48892 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
48894 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
48899 +to_gr_audit(const __u32 reqmode)
48901 + /* masks off auditable permission flags, then shifts them to create
48902 + auditing flags, and adds the special case of append auditing if
48903 + we're requesting write */
48904 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
48907 +struct acl_subject_label *
48908 +lookup_subject_map(const struct acl_subject_label *userp)
48910 + unsigned int index = shash(userp, subj_map_set.s_size);
48911 + struct subject_map *match;
48913 + match = subj_map_set.s_hash[index];
48915 + while (match && match->user != userp)
48916 + match = match->next;
48918 + if (match != NULL)
48919 + return match->kernel;
48925 +insert_subj_map_entry(struct subject_map *subjmap)
48927 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
48928 + struct subject_map **curr;
48930 + subjmap->prev = NULL;
48932 + curr = &subj_map_set.s_hash[index];
48933 + if (*curr != NULL)
48934 + (*curr)->prev = subjmap;
48936 + subjmap->next = *curr;
48942 +static struct acl_role_label *
48943 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
48946 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
48947 + struct acl_role_label *match;
48948 + struct role_allowed_ip *ipp;
48950 + u32 curr_ip = task->signal->curr_ip;
48952 + task->signal->saved_ip = curr_ip;
48954 + match = acl_role_set.r_hash[index];
48957 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
48958 + for (x = 0; x < match->domain_child_num; x++) {
48959 + if (match->domain_children[x] == uid)
48962 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
48964 + match = match->next;
48967 + if (match == NULL) {
48969 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
48970 + match = acl_role_set.r_hash[index];
48973 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
48974 + for (x = 0; x < match->domain_child_num; x++) {
48975 + if (match->domain_children[x] == gid)
48978 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
48980 + match = match->next;
48983 + if (match == NULL)
48984 + match = default_role;
48985 + if (match->allowed_ips == NULL)
48988 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48990 + ((ntohl(curr_ip) & ipp->netmask) ==
48991 + (ntohl(ipp->addr) & ipp->netmask)))
48994 + match = default_role;
48996 + } else if (match->allowed_ips == NULL) {
48999 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
49001 + ((ntohl(curr_ip) & ipp->netmask) ==
49002 + (ntohl(ipp->addr) & ipp->netmask)))
49011 +struct acl_subject_label *
49012 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
49013 + const struct acl_role_label *role)
49015 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
49016 + struct acl_subject_label *match;
49018 + match = role->subj_hash[index];
49020 + while (match && (match->inode != ino || match->device != dev ||
49021 + (match->mode & GR_DELETED))) {
49022 + match = match->next;
49025 + if (match && !(match->mode & GR_DELETED))
49031 +struct acl_subject_label *
49032 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
49033 + const struct acl_role_label *role)
49035 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
49036 + struct acl_subject_label *match;
49038 + match = role->subj_hash[index];
49040 + while (match && (match->inode != ino || match->device != dev ||
49041 + !(match->mode & GR_DELETED))) {
49042 + match = match->next;
49045 + if (match && (match->mode & GR_DELETED))
49051 +static struct acl_object_label *
49052 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
49053 + const struct acl_subject_label *subj)
49055 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
49056 + struct acl_object_label *match;
49058 + match = subj->obj_hash[index];
49060 + while (match && (match->inode != ino || match->device != dev ||
49061 + (match->mode & GR_DELETED))) {
49062 + match = match->next;
49065 + if (match && !(match->mode & GR_DELETED))
49071 +static struct acl_object_label *
49072 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
49073 + const struct acl_subject_label *subj)
49075 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
49076 + struct acl_object_label *match;
49078 + match = subj->obj_hash[index];
49080 + while (match && (match->inode != ino || match->device != dev ||
49081 + !(match->mode & GR_DELETED))) {
49082 + match = match->next;
49085 + if (match && (match->mode & GR_DELETED))
49088 + match = subj->obj_hash[index];
49090 + while (match && (match->inode != ino || match->device != dev ||
49091 + (match->mode & GR_DELETED))) {
49092 + match = match->next;
49095 + if (match && !(match->mode & GR_DELETED))
49101 +static struct name_entry *
49102 +lookup_name_entry(const char *name)
49104 + unsigned int len = strlen(name);
49105 + unsigned int key = full_name_hash(name, len);
49106 + unsigned int index = key % name_set.n_size;
49107 + struct name_entry *match;
49109 + match = name_set.n_hash[index];
49111 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
49112 + match = match->next;
49117 +static struct name_entry *
49118 +lookup_name_entry_create(const char *name)
49120 + unsigned int len = strlen(name);
49121 + unsigned int key = full_name_hash(name, len);
49122 + unsigned int index = key % name_set.n_size;
49123 + struct name_entry *match;
49125 + match = name_set.n_hash[index];
49127 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
49128 + !match->deleted))
49129 + match = match->next;
49131 + if (match && match->deleted)
49134 + match = name_set.n_hash[index];
49136 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
49138 + match = match->next;
49140 + if (match && !match->deleted)
49146 +static struct inodev_entry *
49147 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
49149 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
49150 + struct inodev_entry *match;
49152 + match = inodev_set.i_hash[index];
49154 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
49155 + match = match->next;
49161 +insert_inodev_entry(struct inodev_entry *entry)
49163 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
49164 + inodev_set.i_size);
49165 + struct inodev_entry **curr;
49167 + entry->prev = NULL;
49169 + curr = &inodev_set.i_hash[index];
49170 + if (*curr != NULL)
49171 + (*curr)->prev = entry;
49173 + entry->next = *curr;
49180 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
49182 + unsigned int index =
49183 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
49184 + struct acl_role_label **curr;
49185 + struct acl_role_label *tmp;
49187 + curr = &acl_role_set.r_hash[index];
49189 + /* if role was already inserted due to domains and already has
49190 + a role in the same bucket as it attached, then we need to
49191 + combine these two buckets
49193 + if (role->next) {
49194 + tmp = role->next;
49195 + while (tmp->next)
49197 + tmp->next = *curr;
49199 + role->next = *curr;
49206 +insert_acl_role_label(struct acl_role_label *role)
49210 + if (role_list == NULL) {
49211 + role_list = role;
49212 + role->prev = NULL;
49214 + role->prev = role_list;
49215 + role_list = role;
49218 + /* used for hash chains */
49219 + role->next = NULL;
49221 + if (role->roletype & GR_ROLE_DOMAIN) {
49222 + for (i = 0; i < role->domain_child_num; i++)
49223 + __insert_acl_role_label(role, role->domain_children[i]);
49225 + __insert_acl_role_label(role, role->uidgid);
49229 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
49231 + struct name_entry **curr, *nentry;
49232 + struct inodev_entry *ientry;
49233 + unsigned int len = strlen(name);
49234 + unsigned int key = full_name_hash(name, len);
49235 + unsigned int index = key % name_set.n_size;
49237 + curr = &name_set.n_hash[index];
49239 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
49240 + curr = &((*curr)->next);
49242 + if (*curr != NULL)
49245 + nentry = acl_alloc(sizeof (struct name_entry));
49246 + if (nentry == NULL)
49248 + ientry = acl_alloc(sizeof (struct inodev_entry));
49249 + if (ientry == NULL)
49251 + ientry->nentry = nentry;
49253 + nentry->key = key;
49254 + nentry->name = name;
49255 + nentry->inode = inode;
49256 + nentry->device = device;
49257 + nentry->len = len;
49258 + nentry->deleted = deleted;
49260 + nentry->prev = NULL;
49261 + curr = &name_set.n_hash[index];
49262 + if (*curr != NULL)
49263 + (*curr)->prev = nentry;
49264 + nentry->next = *curr;
49267 + /* insert us into the table searchable by inode/dev */
49268 + insert_inodev_entry(ientry);
49274 +insert_acl_obj_label(struct acl_object_label *obj,
49275 + struct acl_subject_label *subj)
49277 + unsigned int index =
49278 + fhash(obj->inode, obj->device, subj->obj_hash_size);
49279 + struct acl_object_label **curr;
49282 + obj->prev = NULL;
49284 + curr = &subj->obj_hash[index];
49285 + if (*curr != NULL)
49286 + (*curr)->prev = obj;
49288 + obj->next = *curr;
49295 +insert_acl_subj_label(struct acl_subject_label *obj,
49296 + struct acl_role_label *role)
49298 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
49299 + struct acl_subject_label **curr;
49301 + obj->prev = NULL;
49303 + curr = &role->subj_hash[index];
49304 + if (*curr != NULL)
49305 + (*curr)->prev = obj;
49307 + obj->next = *curr;
49313 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
49316 +create_table(__u32 * len, int elementsize)
49318 + unsigned int table_sizes[] = {
49319 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
49320 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
49321 + 4194301, 8388593, 16777213, 33554393, 67108859
49323 + void *newtable = NULL;
49324 + unsigned int pwr = 0;
49326 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
49327 + table_sizes[pwr] <= *len)
49330 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
49333 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
49335 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
49337 + newtable = vmalloc(table_sizes[pwr] * elementsize);
49339 + *len = table_sizes[pwr];
49345 +init_variables(const struct gr_arg *arg)
49347 + struct task_struct *reaper = &init_task;
49348 + unsigned int stacksize;
49350 + subj_map_set.s_size = arg->role_db.num_subjects;
49351 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
49352 + name_set.n_size = arg->role_db.num_objects;
49353 + inodev_set.i_size = arg->role_db.num_objects;
49355 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
49356 + !name_set.n_size || !inodev_set.i_size)
49359 + if (!gr_init_uidset())
49362 + /* set up the stack that holds allocation info */
49364 + stacksize = arg->role_db.num_pointers + 5;
49366 + if (!acl_alloc_stack_init(stacksize))
49369 + /* grab reference for the real root dentry and vfsmount */
49370 + get_fs_root(reaper->fs, &real_root);
49372 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49373 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
49376 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
49377 + if (fakefs_obj_rw == NULL)
49379 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
49381 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
49382 + if (fakefs_obj_rwx == NULL)
49384 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
49386 + subj_map_set.s_hash =
49387 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
49388 + acl_role_set.r_hash =
49389 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
49390 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
49391 + inodev_set.i_hash =
49392 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
49394 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
49395 + !name_set.n_hash || !inodev_set.i_hash)
49398 + memset(subj_map_set.s_hash, 0,
49399 + sizeof(struct subject_map *) * subj_map_set.s_size);
49400 + memset(acl_role_set.r_hash, 0,
49401 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
49402 + memset(name_set.n_hash, 0,
49403 + sizeof (struct name_entry *) * name_set.n_size);
49404 + memset(inodev_set.i_hash, 0,
49405 + sizeof (struct inodev_entry *) * inodev_set.i_size);
49410 +/* free information not needed after startup
49411 + currently contains user->kernel pointer mappings for subjects
49415 +free_init_variables(void)
49419 + if (subj_map_set.s_hash) {
49420 + for (i = 0; i < subj_map_set.s_size; i++) {
49421 + if (subj_map_set.s_hash[i]) {
49422 + kfree(subj_map_set.s_hash[i]);
49423 + subj_map_set.s_hash[i] = NULL;
49427 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
49429 + kfree(subj_map_set.s_hash);
49431 + vfree(subj_map_set.s_hash);
49438 +free_variables(void)
49440 + struct acl_subject_label *s;
49441 + struct acl_role_label *r;
49442 + struct task_struct *task, *task2;
49445 + gr_clear_learn_entries();
49447 + read_lock(&tasklist_lock);
49448 + do_each_thread(task2, task) {
49449 + task->acl_sp_role = 0;
49450 + task->acl_role_id = 0;
49451 + task->acl = NULL;
49452 + task->role = NULL;
49453 + } while_each_thread(task2, task);
49454 + read_unlock(&tasklist_lock);
49456 + /* release the reference to the real root dentry and vfsmount */
49457 + path_put(&real_root);
49459 + /* free all object hash tables */
49461 + FOR_EACH_ROLE_START(r)
49462 + if (r->subj_hash == NULL)
49464 + FOR_EACH_SUBJECT_START(r, s, x)
49465 + if (s->obj_hash == NULL)
49467 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49468 + kfree(s->obj_hash);
49470 + vfree(s->obj_hash);
49471 + FOR_EACH_SUBJECT_END(s, x)
49472 + FOR_EACH_NESTED_SUBJECT_START(r, s)
49473 + if (s->obj_hash == NULL)
49475 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49476 + kfree(s->obj_hash);
49478 + vfree(s->obj_hash);
49479 + FOR_EACH_NESTED_SUBJECT_END(s)
49480 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
49481 + kfree(r->subj_hash);
49483 + vfree(r->subj_hash);
49484 + r->subj_hash = NULL;
49486 + FOR_EACH_ROLE_END(r)
49490 + if (acl_role_set.r_hash) {
49491 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
49493 + kfree(acl_role_set.r_hash);
49495 + vfree(acl_role_set.r_hash);
49497 + if (name_set.n_hash) {
49498 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
49500 + kfree(name_set.n_hash);
49502 + vfree(name_set.n_hash);
49505 + if (inodev_set.i_hash) {
49506 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
49508 + kfree(inodev_set.i_hash);
49510 + vfree(inodev_set.i_hash);
49513 + gr_free_uidset();
49515 + memset(&name_set, 0, sizeof (struct name_db));
49516 + memset(&inodev_set, 0, sizeof (struct inodev_db));
49517 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
49518 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
49520 + default_role = NULL;
49521 + role_list = NULL;
49527 +count_user_objs(struct acl_object_label *userp)
49529 + struct acl_object_label o_tmp;
49533 + if (copy_from_user(&o_tmp, userp,
49534 + sizeof (struct acl_object_label)))
49537 + userp = o_tmp.prev;
49544 +static struct acl_subject_label *
49545 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
49548 +copy_user_glob(struct acl_object_label *obj)
49550 + struct acl_object_label *g_tmp, **guser;
49551 + unsigned int len;
49554 + if (obj->globbed == NULL)
49557 + guser = &obj->globbed;
49559 + g_tmp = (struct acl_object_label *)
49560 + acl_alloc(sizeof (struct acl_object_label));
49561 + if (g_tmp == NULL)
49564 + if (copy_from_user(g_tmp, *guser,
49565 + sizeof (struct acl_object_label)))
49568 + len = strnlen_user(g_tmp->filename, PATH_MAX);
49570 + if (!len || len >= PATH_MAX)
49573 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49576 + if (copy_from_user(tmp, g_tmp->filename, len))
49578 + tmp[len-1] = '\0';
49579 + g_tmp->filename = tmp;
49582 + guser = &(g_tmp->next);
49589 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
49590 + struct acl_role_label *role)
49592 + struct acl_object_label *o_tmp;
49593 + unsigned int len;
49598 + if ((o_tmp = (struct acl_object_label *)
49599 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
49602 + if (copy_from_user(o_tmp, userp,
49603 + sizeof (struct acl_object_label)))
49606 + userp = o_tmp->prev;
49608 + len = strnlen_user(o_tmp->filename, PATH_MAX);
49610 + if (!len || len >= PATH_MAX)
49613 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49616 + if (copy_from_user(tmp, o_tmp->filename, len))
49618 + tmp[len-1] = '\0';
49619 + o_tmp->filename = tmp;
49621 + insert_acl_obj_label(o_tmp, subj);
49622 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
49623 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
49626 + ret = copy_user_glob(o_tmp);
49630 + if (o_tmp->nested) {
49631 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
49632 + if (IS_ERR(o_tmp->nested))
49633 + return PTR_ERR(o_tmp->nested);
49635 + /* insert into nested subject list */
49636 + o_tmp->nested->next = role->hash->first;
49637 + role->hash->first = o_tmp->nested;
49645 +count_user_subjs(struct acl_subject_label *userp)
49647 + struct acl_subject_label s_tmp;
49651 + if (copy_from_user(&s_tmp, userp,
49652 + sizeof (struct acl_subject_label)))
49655 + userp = s_tmp.prev;
49656 + /* do not count nested subjects against this count, since
49657 + they are not included in the hash table, but are
49658 + attached to objects. We have already counted
49659 + the subjects in userspace for the allocation
49662 + if (!(s_tmp.mode & GR_NESTED))
49670 +copy_user_allowedips(struct acl_role_label *rolep)
49672 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
49674 + ruserip = rolep->allowed_ips;
49676 + while (ruserip) {
49679 + if ((rtmp = (struct role_allowed_ip *)
49680 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
49683 + if (copy_from_user(rtmp, ruserip,
49684 + sizeof (struct role_allowed_ip)))
49687 + ruserip = rtmp->prev;
49690 + rtmp->prev = NULL;
49691 + rolep->allowed_ips = rtmp;
49693 + rlast->next = rtmp;
49694 + rtmp->prev = rlast;
49698 + rtmp->next = NULL;
49705 +copy_user_transitions(struct acl_role_label *rolep)
49707 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
49709 + unsigned int len;
49712 + rusertp = rolep->transitions;
49714 + while (rusertp) {
49717 + if ((rtmp = (struct role_transition *)
49718 + acl_alloc(sizeof (struct role_transition))) == NULL)
49721 + if (copy_from_user(rtmp, rusertp,
49722 + sizeof (struct role_transition)))
49725 + rusertp = rtmp->prev;
49727 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
49729 + if (!len || len >= GR_SPROLE_LEN)
49732 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49735 + if (copy_from_user(tmp, rtmp->rolename, len))
49737 + tmp[len-1] = '\0';
49738 + rtmp->rolename = tmp;
49741 + rtmp->prev = NULL;
49742 + rolep->transitions = rtmp;
49744 + rlast->next = rtmp;
49745 + rtmp->prev = rlast;
49749 + rtmp->next = NULL;
49755 +static struct acl_subject_label *
49756 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
49758 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
49759 + unsigned int len;
49762 + struct acl_ip_label **i_tmp, *i_utmp2;
49763 + struct gr_hash_struct ghash;
49764 + struct subject_map *subjmap;
49765 + unsigned int i_num;
49768 + s_tmp = lookup_subject_map(userp);
49770 + /* we've already copied this subject into the kernel, just return
49771 + the reference to it, and don't copy it over again
49776 + if ((s_tmp = (struct acl_subject_label *)
49777 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
49778 + return ERR_PTR(-ENOMEM);
49780 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
49781 + if (subjmap == NULL)
49782 + return ERR_PTR(-ENOMEM);
49784 + subjmap->user = userp;
49785 + subjmap->kernel = s_tmp;
49786 + insert_subj_map_entry(subjmap);
49788 + if (copy_from_user(s_tmp, userp,
49789 + sizeof (struct acl_subject_label)))
49790 + return ERR_PTR(-EFAULT);
49792 + len = strnlen_user(s_tmp->filename, PATH_MAX);
49794 + if (!len || len >= PATH_MAX)
49795 + return ERR_PTR(-EINVAL);
49797 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49798 + return ERR_PTR(-ENOMEM);
49800 + if (copy_from_user(tmp, s_tmp->filename, len))
49801 + return ERR_PTR(-EFAULT);
49802 + tmp[len-1] = '\0';
49803 + s_tmp->filename = tmp;
49805 + if (!strcmp(s_tmp->filename, "/"))
49806 + role->root_label = s_tmp;
49808 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
49809 + return ERR_PTR(-EFAULT);
49811 + /* copy user and group transition tables */
49813 + if (s_tmp->user_trans_num) {
49816 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
49817 + if (uidlist == NULL)
49818 + return ERR_PTR(-ENOMEM);
49819 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
49820 + return ERR_PTR(-EFAULT);
49822 + s_tmp->user_transitions = uidlist;
49825 + if (s_tmp->group_trans_num) {
49828 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
49829 + if (gidlist == NULL)
49830 + return ERR_PTR(-ENOMEM);
49831 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
49832 + return ERR_PTR(-EFAULT);
49834 + s_tmp->group_transitions = gidlist;
49837 + /* set up object hash table */
49838 + num_objs = count_user_objs(ghash.first);
49840 + s_tmp->obj_hash_size = num_objs;
49841 + s_tmp->obj_hash =
49842 + (struct acl_object_label **)
49843 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
49845 + if (!s_tmp->obj_hash)
49846 + return ERR_PTR(-ENOMEM);
49848 + memset(s_tmp->obj_hash, 0,
49849 + s_tmp->obj_hash_size *
49850 + sizeof (struct acl_object_label *));
49852 + /* add in objects */
49853 + err = copy_user_objs(ghash.first, s_tmp, role);
49856 + return ERR_PTR(err);
49858 + /* set pointer for parent subject */
49859 + if (s_tmp->parent_subject) {
49860 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
49862 + if (IS_ERR(s_tmp2))
49865 + s_tmp->parent_subject = s_tmp2;
49868 + /* add in ip acls */
49870 + if (!s_tmp->ip_num) {
49871 + s_tmp->ips = NULL;
49876 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
49877 + sizeof (struct acl_ip_label *));
49880 + return ERR_PTR(-ENOMEM);
49882 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
49883 + *(i_tmp + i_num) =
49884 + (struct acl_ip_label *)
49885 + acl_alloc(sizeof (struct acl_ip_label));
49886 + if (!*(i_tmp + i_num))
49887 + return ERR_PTR(-ENOMEM);
49889 + if (copy_from_user
49890 + (&i_utmp2, s_tmp->ips + i_num,
49891 + sizeof (struct acl_ip_label *)))
49892 + return ERR_PTR(-EFAULT);
49894 + if (copy_from_user
49895 + (*(i_tmp + i_num), i_utmp2,
49896 + sizeof (struct acl_ip_label)))
49897 + return ERR_PTR(-EFAULT);
49899 + if ((*(i_tmp + i_num))->iface == NULL)
49902 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
49903 + if (!len || len >= IFNAMSIZ)
49904 + return ERR_PTR(-EINVAL);
49905 + tmp = acl_alloc(len);
49907 + return ERR_PTR(-ENOMEM);
49908 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
49909 + return ERR_PTR(-EFAULT);
49910 + (*(i_tmp + i_num))->iface = tmp;
49913 + s_tmp->ips = i_tmp;
49916 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
49917 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
49918 + return ERR_PTR(-ENOMEM);
49924 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
49926 + struct acl_subject_label s_pre;
49927 + struct acl_subject_label * ret;
49931 + if (copy_from_user(&s_pre, userp,
49932 + sizeof (struct acl_subject_label)))
49935 + /* do not add nested subjects here, add
49936 + while parsing objects
49939 + if (s_pre.mode & GR_NESTED) {
49940 + userp = s_pre.prev;
49944 + ret = do_copy_user_subj(userp, role);
49946 + err = PTR_ERR(ret);
49950 + insert_acl_subj_label(ret, role);
49952 + userp = s_pre.prev;
49959 +copy_user_acl(struct gr_arg *arg)
49961 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
49962 + struct sprole_pw *sptmp;
49963 + struct gr_hash_struct *ghash;
49964 + uid_t *domainlist;
49965 + unsigned int r_num;
49966 + unsigned int len;
49972 + /* we need a default and kernel role */
49973 + if (arg->role_db.num_roles < 2)
49976 + /* copy special role authentication info from userspace */
49978 + num_sprole_pws = arg->num_sprole_pws;
49979 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
49981 + if (!acl_special_roles) {
49986 + for (i = 0; i < num_sprole_pws; i++) {
49987 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
49992 + if (copy_from_user(sptmp, arg->sprole_pws + i,
49993 + sizeof (struct sprole_pw))) {
49999 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
50001 + if (!len || len >= GR_SPROLE_LEN) {
50006 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
50011 + if (copy_from_user(tmp, sptmp->rolename, len)) {
50015 + tmp[len-1] = '\0';
50016 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50017 + printk(KERN_ALERT "Copying special role %s\n", tmp);
50019 + sptmp->rolename = tmp;
50020 + acl_special_roles[i] = sptmp;
50023 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
50025 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
50026 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
50033 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
50034 + sizeof (struct acl_role_label *))) {
50039 + if (copy_from_user(r_tmp, r_utmp2,
50040 + sizeof (struct acl_role_label))) {
50045 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
50047 + if (!len || len >= PATH_MAX) {
50052 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
50056 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
50060 + tmp[len-1] = '\0';
50061 + r_tmp->rolename = tmp;
50063 + if (!strcmp(r_tmp->rolename, "default")
50064 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
50065 + default_role = r_tmp;
50066 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
50067 + kernel_role = r_tmp;
50070 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
50074 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
50079 + r_tmp->hash = ghash;
50081 + num_subjs = count_user_subjs(r_tmp->hash->first);
50083 + r_tmp->subj_hash_size = num_subjs;
50084 + r_tmp->subj_hash =
50085 + (struct acl_subject_label **)
50086 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
50088 + if (!r_tmp->subj_hash) {
50093 + err = copy_user_allowedips(r_tmp);
50097 + /* copy domain info */
50098 + if (r_tmp->domain_children != NULL) {
50099 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
50100 + if (domainlist == NULL) {
50104 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
50108 + r_tmp->domain_children = domainlist;
50111 + err = copy_user_transitions(r_tmp);
50115 + memset(r_tmp->subj_hash, 0,
50116 + r_tmp->subj_hash_size *
50117 + sizeof (struct acl_subject_label *));
50119 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
50124 + /* set nested subject list to null */
50125 + r_tmp->hash->first = NULL;
50127 + insert_acl_role_label(r_tmp);
50132 + free_variables();
50139 +gracl_init(struct gr_arg *args)
50143 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
50144 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
50146 + if (init_variables(args)) {
50147 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
50149 + free_variables();
50153 + error = copy_user_acl(args);
50154 + free_init_variables();
50156 + free_variables();
50160 + if ((error = gr_set_acls(0))) {
50161 + free_variables();
50165 + pax_open_kernel();
50166 + gr_status |= GR_READY;
50167 + pax_close_kernel();
50173 +/* derived from glibc fnmatch() 0: match, 1: no match*/
50176 +glob_match(const char *p, const char *n)
50180 + while ((c = *p++) != '\0') {
50185 + else if (*n == '/')
50193 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
50196 + else if (c == '?') {
50206 + const char *endp;
50208 + if ((endp = strchr(n, '/')) == NULL)
50209 + endp = n + strlen(n);
50212 + for (--p; n < endp; ++n)
50213 + if (!glob_match(p, n))
50215 + } else if (c == '/') {
50216 + while (*n != '\0' && *n != '/')
50218 + if (*n == '/' && !glob_match(p, n + 1))
50221 + for (--p; n < endp; ++n)
50222 + if (*n == c && !glob_match(p, n))
50233 + if (*n == '\0' || *n == '/')
50236 + not = (*p == '!' || *p == '^');
50242 + unsigned char fn = (unsigned char)*n;
50252 + if (c == '-' && *p != ']') {
50253 + unsigned char cend = *p++;
50255 + if (cend == '\0')
50258 + if (cold <= fn && fn <= cend)
50272 + while (c != ']') {
50299 +static struct acl_object_label *
50300 +chk_glob_label(struct acl_object_label *globbed,
50301 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
50303 + struct acl_object_label *tmp;
50305 + if (*path == NULL)
50306 + *path = gr_to_filename_nolock(dentry, mnt);
50311 + if (!glob_match(tmp->filename, *path))
50319 +static struct acl_object_label *
50320 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50321 + const ino_t curr_ino, const dev_t curr_dev,
50322 + const struct acl_subject_label *subj, char **path, const int checkglob)
50324 + struct acl_subject_label *tmpsubj;
50325 + struct acl_object_label *retval;
50326 + struct acl_object_label *retval2;
50328 + tmpsubj = (struct acl_subject_label *) subj;
50329 + read_lock(&gr_inode_lock);
50331 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
50333 + if (checkglob && retval->globbed) {
50334 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
50336 + retval = retval2;
50340 + } while ((tmpsubj = tmpsubj->parent_subject));
50341 + read_unlock(&gr_inode_lock);
50346 +static __inline__ struct acl_object_label *
50347 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50348 + struct dentry *curr_dentry,
50349 + const struct acl_subject_label *subj, char **path, const int checkglob)
50351 + int newglob = checkglob;
50355 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
50356 + as we don't want a / * rule to match instead of the / object
50357 + don't do this for create lookups that call this function though, since they're looking up
50358 + on the parent and thus need globbing checks on all paths
50360 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
50361 + newglob = GR_NO_GLOB;
50363 + spin_lock(&curr_dentry->d_lock);
50364 + inode = curr_dentry->d_inode->i_ino;
50365 + device = __get_dev(curr_dentry);
50366 + spin_unlock(&curr_dentry->d_lock);
50368 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
50371 +static struct acl_object_label *
50372 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50373 + const struct acl_subject_label *subj, char *path, const int checkglob)
50375 + struct dentry *dentry = (struct dentry *) l_dentry;
50376 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50377 + struct acl_object_label *retval;
50378 + struct dentry *parent;
50380 + write_seqlock(&rename_lock);
50381 + br_read_lock(vfsmount_lock);
50383 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
50385 + mnt == sock_mnt ||
50387 +#ifdef CONFIG_HUGETLBFS
50388 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
50390 + /* ignore Eric Biederman */
50391 + IS_PRIVATE(l_dentry->d_inode))) {
50392 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
50397 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50400 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50401 + if (mnt->mnt_parent == mnt)
50404 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50405 + if (retval != NULL)
50408 + dentry = mnt->mnt_mountpoint;
50409 + mnt = mnt->mnt_parent;
50413 + parent = dentry->d_parent;
50414 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50415 + if (retval != NULL)
50421 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50423 + /* real_root is pinned so we don't have to hold a reference */
50424 + if (retval == NULL)
50425 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
50427 + br_read_unlock(vfsmount_lock);
50428 + write_sequnlock(&rename_lock);
50430 + BUG_ON(retval == NULL);
50435 +static __inline__ struct acl_object_label *
50436 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50437 + const struct acl_subject_label *subj)
50439 + char *path = NULL;
50440 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
50443 +static __inline__ struct acl_object_label *
50444 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50445 + const struct acl_subject_label *subj)
50447 + char *path = NULL;
50448 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
50451 +static __inline__ struct acl_object_label *
50452 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50453 + const struct acl_subject_label *subj, char *path)
50455 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
50458 +static struct acl_subject_label *
50459 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50460 + const struct acl_role_label *role)
50462 + struct dentry *dentry = (struct dentry *) l_dentry;
50463 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50464 + struct acl_subject_label *retval;
50465 + struct dentry *parent;
50467 + write_seqlock(&rename_lock);
50468 + br_read_lock(vfsmount_lock);
50471 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50473 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50474 + if (mnt->mnt_parent == mnt)
50477 + spin_lock(&dentry->d_lock);
50478 + read_lock(&gr_inode_lock);
50480 + lookup_acl_subj_label(dentry->d_inode->i_ino,
50481 + __get_dev(dentry), role);
50482 + read_unlock(&gr_inode_lock);
50483 + spin_unlock(&dentry->d_lock);
50484 + if (retval != NULL)
50487 + dentry = mnt->mnt_mountpoint;
50488 + mnt = mnt->mnt_parent;
50492 + spin_lock(&dentry->d_lock);
50493 + read_lock(&gr_inode_lock);
50494 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50495 + __get_dev(dentry), role);
50496 + read_unlock(&gr_inode_lock);
50497 + parent = dentry->d_parent;
50498 + spin_unlock(&dentry->d_lock);
50500 + if (retval != NULL)
50506 + spin_lock(&dentry->d_lock);
50507 + read_lock(&gr_inode_lock);
50508 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50509 + __get_dev(dentry), role);
50510 + read_unlock(&gr_inode_lock);
50511 + spin_unlock(&dentry->d_lock);
50513 + if (unlikely(retval == NULL)) {
50514 + /* real_root is pinned, we don't need to hold a reference */
50515 + read_lock(&gr_inode_lock);
50516 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
50517 + __get_dev(real_root.dentry), role);
50518 + read_unlock(&gr_inode_lock);
50521 + br_read_unlock(vfsmount_lock);
50522 + write_sequnlock(&rename_lock);
50524 + BUG_ON(retval == NULL);
50530 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
50532 + struct task_struct *task = current;
50533 + const struct cred *cred = current_cred();
50535 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50536 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50537 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50538 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
50544 +gr_log_learn_sysctl(const char *path, const __u32 mode)
50546 + struct task_struct *task = current;
50547 + const struct cred *cred = current_cred();
50549 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50550 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50551 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50552 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
50558 +gr_log_learn_id_change(const char type, const unsigned int real,
50559 + const unsigned int effective, const unsigned int fs)
50561 + struct task_struct *task = current;
50562 + const struct cred *cred = current_cred();
50564 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
50565 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50566 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50567 + type, real, effective, fs, &task->signal->saved_ip);
50573 +gr_search_file(const struct dentry * dentry, const __u32 mode,
50574 + const struct vfsmount * mnt)
50576 + __u32 retval = mode;
50577 + struct acl_subject_label *curracl;
50578 + struct acl_object_label *currobj;
50580 + if (unlikely(!(gr_status & GR_READY)))
50581 + return (mode & ~GR_AUDITS);
50583 + curracl = current->acl;
50585 + currobj = chk_obj_label(dentry, mnt, curracl);
50586 + retval = currobj->mode & mode;
50588 + /* if we're opening a specified transfer file for writing
50589 + (e.g. /dev/initctl), then transfer our role to init
50591 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
50592 + current->role->roletype & GR_ROLE_PERSIST)) {
50593 + struct task_struct *task = init_pid_ns.child_reaper;
50595 + if (task->role != current->role) {
50596 + task->acl_sp_role = 0;
50597 + task->acl_role_id = current->acl_role_id;
50598 + task->role = current->role;
50600 + read_lock(&grsec_exec_file_lock);
50601 + gr_apply_subject_to_task(task);
50602 + read_unlock(&grsec_exec_file_lock);
50603 + rcu_read_unlock();
50604 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
50609 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
50610 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
50611 + __u32 new_mode = mode;
50613 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50615 + retval = new_mode;
50617 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
50618 + new_mode |= GR_INHERIT;
50620 + if (!(mode & GR_NOLEARN))
50621 + gr_log_learn(dentry, mnt, new_mode);
50627 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
50628 + const struct dentry *parent,
50629 + const struct vfsmount *mnt)
50631 + struct name_entry *match;
50632 + struct acl_object_label *matchpo;
50633 + struct acl_subject_label *curracl;
50636 + if (unlikely(!(gr_status & GR_READY)))
50639 + preempt_disable();
50640 + path = gr_to_filename_rbac(new_dentry, mnt);
50641 + match = lookup_name_entry_create(path);
50643 + curracl = current->acl;
50646 + read_lock(&gr_inode_lock);
50647 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
50648 + read_unlock(&gr_inode_lock);
50651 + preempt_enable();
50658 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
50660 + preempt_enable();
50665 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
50666 + const struct vfsmount * mnt, const __u32 mode)
50668 + struct acl_object_label *matchpo;
50671 + if (unlikely(!(gr_status & GR_READY)))
50672 + return (mode & ~GR_AUDITS);
50674 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
50676 + retval = matchpo->mode & mode;
50678 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
50679 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
50680 + __u32 new_mode = mode;
50682 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50684 + gr_log_learn(new_dentry, mnt, new_mode);
50692 +gr_check_link(const struct dentry * new_dentry,
50693 + const struct dentry * parent_dentry,
50694 + const struct vfsmount * parent_mnt,
50695 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
50697 + struct acl_object_label *obj;
50698 + __u32 oldmode, newmode;
50700 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
50701 + GR_DELETE | GR_INHERIT;
50703 + if (unlikely(!(gr_status & GR_READY)))
50704 + return (GR_CREATE | GR_LINK);
50706 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
50707 + oldmode = obj->mode;
50709 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
50710 + newmode = obj->mode;
50712 + needmode = newmode & checkmodes;
50714 + // old name for hardlink must have at least the permissions of the new name
50715 + if ((oldmode & needmode) != needmode)
50718 + // if old name had restrictions/auditing, make sure the new name does as well
50719 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
50721 + // don't allow hardlinking of suid/sgid files without permission
50722 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50723 + needmode |= GR_SETID;
50725 + if ((newmode & needmode) != needmode)
50728 + // enforce minimum permissions
50729 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
50732 + needmode = oldmode;
50733 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50734 + needmode |= GR_SETID;
50736 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
50737 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
50738 + return (GR_CREATE | GR_LINK);
50739 + } else if (newmode & GR_SUPPRESS)
50740 + return GR_SUPPRESS;
50746 +gr_check_hidden_task(const struct task_struct *task)
50748 + if (unlikely(!(gr_status & GR_READY)))
50751 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
50758 +gr_check_protected_task(const struct task_struct *task)
50760 + if (unlikely(!(gr_status & GR_READY) || !task))
50763 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50764 + task->acl != current->acl)
50771 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
50773 + struct task_struct *p;
50776 + if (unlikely(!(gr_status & GR_READY) || !pid))
50779 + read_lock(&tasklist_lock);
50780 + do_each_pid_task(pid, type, p) {
50781 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50782 + p->acl != current->acl) {
50786 + } while_each_pid_task(pid, type, p);
50788 + read_unlock(&tasklist_lock);
50794 +gr_copy_label(struct task_struct *tsk)
50796 + /* plain copying of fields is already done by dup_task_struct */
50797 + tsk->signal->used_accept = 0;
50798 + tsk->acl_sp_role = 0;
50799 + //tsk->acl_role_id = current->acl_role_id;
50800 + //tsk->acl = current->acl;
50801 + //tsk->role = current->role;
50802 + tsk->signal->curr_ip = current->signal->curr_ip;
50803 + tsk->signal->saved_ip = current->signal->saved_ip;
50804 + if (current->exec_file)
50805 + get_file(current->exec_file);
50806 + //tsk->exec_file = current->exec_file;
50807 + //tsk->is_writable = current->is_writable;
50808 + if (unlikely(current->signal->used_accept)) {
50809 + current->signal->curr_ip = 0;
50810 + current->signal->saved_ip = 0;
50817 +gr_set_proc_res(struct task_struct *task)
50819 + struct acl_subject_label *proc;
50820 + unsigned short i;
50822 + proc = task->acl;
50824 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
50827 + for (i = 0; i < RLIM_NLIMITS; i++) {
50828 + if (!(proc->resmask & (1 << i)))
50831 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
50832 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
50838 +extern int __gr_process_user_ban(struct user_struct *user);
50841 +gr_check_user_change(int real, int effective, int fs)
50848 + int effectiveok = 0;
50851 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
50852 + struct user_struct *user;
50857 + user = find_user(real);
50858 + if (user == NULL)
50861 + if (__gr_process_user_ban(user)) {
50862 + /* for find_user */
50867 + /* for find_user */
50873 + if (unlikely(!(gr_status & GR_READY)))
50876 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50877 + gr_log_learn_id_change('u', real, effective, fs);
50879 + num = current->acl->user_trans_num;
50880 + uidlist = current->acl->user_transitions;
50882 + if (uidlist == NULL)
50887 + if (effective == -1)
50892 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
50893 + for (i = 0; i < num; i++) {
50894 + curuid = (int)uidlist[i];
50895 + if (real == curuid)
50897 + if (effective == curuid)
50899 + if (fs == curuid)
50902 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
50903 + for (i = 0; i < num; i++) {
50904 + curuid = (int)uidlist[i];
50905 + if (real == curuid)
50907 + if (effective == curuid)
50909 + if (fs == curuid)
50912 + /* not in deny list */
50920 + if (realok && effectiveok && fsok)
50923 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50929 +gr_check_group_change(int real, int effective, int fs)
50936 + int effectiveok = 0;
50939 + if (unlikely(!(gr_status & GR_READY)))
50942 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50943 + gr_log_learn_id_change('g', real, effective, fs);
50945 + num = current->acl->group_trans_num;
50946 + gidlist = current->acl->group_transitions;
50948 + if (gidlist == NULL)
50953 + if (effective == -1)
50958 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
50959 + for (i = 0; i < num; i++) {
50960 + curgid = (int)gidlist[i];
50961 + if (real == curgid)
50963 + if (effective == curgid)
50965 + if (fs == curgid)
50968 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
50969 + for (i = 0; i < num; i++) {
50970 + curgid = (int)gidlist[i];
50971 + if (real == curgid)
50973 + if (effective == curgid)
50975 + if (fs == curgid)
50978 + /* not in deny list */
50986 + if (realok && effectiveok && fsok)
50989 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50994 +extern int gr_acl_is_capable(const int cap);
50997 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
50999 + struct acl_role_label *role = task->role;
51000 + struct acl_subject_label *subj = NULL;
51001 + struct acl_object_label *obj;
51002 + struct file *filp;
51004 + if (unlikely(!(gr_status & GR_READY)))
51007 + filp = task->exec_file;
51009 + /* kernel process, we'll give them the kernel role */
51010 + if (unlikely(!filp)) {
51011 + task->role = kernel_role;
51012 + task->acl = kernel_role->root_label;
51014 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
51015 + role = lookup_acl_role_label(task, uid, gid);
51017 + /* don't change the role if we're not a privileged process */
51018 + if (role && task->role != role &&
51019 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
51020 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
51023 + /* perform subject lookup in possibly new role
51024 + we can use this result below in the case where role == task->role
51026 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
51028 + /* if we changed uid/gid, but result in the same role
51029 + and are using inheritance, don't lose the inherited subject
51030 + if current subject is other than what normal lookup
51031 + would result in, we arrived via inheritance, don't
51034 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
51035 + (subj == task->acl)))
51036 + task->acl = subj;
51038 + task->role = role;
51040 + task->is_writable = 0;
51042 + /* ignore additional mmap checks for processes that are writable
51043 + by the default ACL */
51044 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51045 + if (unlikely(obj->mode & GR_WRITE))
51046 + task->is_writable = 1;
51047 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
51048 + if (unlikely(obj->mode & GR_WRITE))
51049 + task->is_writable = 1;
51051 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51052 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
51055 + gr_set_proc_res(task);
51061 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
51062 + const int unsafe_flags)
51064 + struct task_struct *task = current;
51065 + struct acl_subject_label *newacl;
51066 + struct acl_object_label *obj;
51069 + if (unlikely(!(gr_status & GR_READY)))
51072 + newacl = chk_subj_label(dentry, mnt, task->role);
51075 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
51076 + !(task->role->roletype & GR_ROLE_GOD) &&
51077 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
51078 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
51079 + task_unlock(task);
51080 + if (unsafe_flags & LSM_UNSAFE_SHARE)
51081 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
51083 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
51086 + task_unlock(task);
51088 + obj = chk_obj_label(dentry, mnt, task->acl);
51089 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
51091 + if (!(task->acl->mode & GR_INHERITLEARN) &&
51092 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
51094 + task->acl = obj->nested;
51096 + task->acl = newacl;
51097 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
51098 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
51100 + task->is_writable = 0;
51102 + /* ignore additional mmap checks for processes that are writable
51103 + by the default ACL */
51104 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
51105 + if (unlikely(obj->mode & GR_WRITE))
51106 + task->is_writable = 1;
51107 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
51108 + if (unlikely(obj->mode & GR_WRITE))
51109 + task->is_writable = 1;
51111 + gr_set_proc_res(task);
51113 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51114 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
51119 +/* always called with valid inodev ptr */
51121 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
51123 + struct acl_object_label *matchpo;
51124 + struct acl_subject_label *matchps;
51125 + struct acl_subject_label *subj;
51126 + struct acl_role_label *role;
51129 + FOR_EACH_ROLE_START(role)
51130 + FOR_EACH_SUBJECT_START(role, subj, x)
51131 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
51132 + matchpo->mode |= GR_DELETED;
51133 + FOR_EACH_SUBJECT_END(subj,x)
51134 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
51135 + if (subj->inode == ino && subj->device == dev)
51136 + subj->mode |= GR_DELETED;
51137 + FOR_EACH_NESTED_SUBJECT_END(subj)
51138 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
51139 + matchps->mode |= GR_DELETED;
51140 + FOR_EACH_ROLE_END(role)
51142 + inodev->nentry->deleted = 1;
51148 +gr_handle_delete(const ino_t ino, const dev_t dev)
51150 + struct inodev_entry *inodev;
51152 + if (unlikely(!(gr_status & GR_READY)))
51155 + write_lock(&gr_inode_lock);
51156 + inodev = lookup_inodev_entry(ino, dev);
51157 + if (inodev != NULL)
51158 + do_handle_delete(inodev, ino, dev);
51159 + write_unlock(&gr_inode_lock);
51165 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
51166 + const ino_t newinode, const dev_t newdevice,
51167 + struct acl_subject_label *subj)
51169 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
51170 + struct acl_object_label *match;
51172 + match = subj->obj_hash[index];
51174 + while (match && (match->inode != oldinode ||
51175 + match->device != olddevice ||
51176 + !(match->mode & GR_DELETED)))
51177 + match = match->next;
51179 + if (match && (match->inode == oldinode)
51180 + && (match->device == olddevice)
51181 + && (match->mode & GR_DELETED)) {
51182 + if (match->prev == NULL) {
51183 + subj->obj_hash[index] = match->next;
51184 + if (match->next != NULL)
51185 + match->next->prev = NULL;
51187 + match->prev->next = match->next;
51188 + if (match->next != NULL)
51189 + match->next->prev = match->prev;
51191 + match->prev = NULL;
51192 + match->next = NULL;
51193 + match->inode = newinode;
51194 + match->device = newdevice;
51195 + match->mode &= ~GR_DELETED;
51197 + insert_acl_obj_label(match, subj);
51204 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
51205 + const ino_t newinode, const dev_t newdevice,
51206 + struct acl_role_label *role)
51208 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
51209 + struct acl_subject_label *match;
51211 + match = role->subj_hash[index];
51213 + while (match && (match->inode != oldinode ||
51214 + match->device != olddevice ||
51215 + !(match->mode & GR_DELETED)))
51216 + match = match->next;
51218 + if (match && (match->inode == oldinode)
51219 + && (match->device == olddevice)
51220 + && (match->mode & GR_DELETED)) {
51221 + if (match->prev == NULL) {
51222 + role->subj_hash[index] = match->next;
51223 + if (match->next != NULL)
51224 + match->next->prev = NULL;
51226 + match->prev->next = match->next;
51227 + if (match->next != NULL)
51228 + match->next->prev = match->prev;
51230 + match->prev = NULL;
51231 + match->next = NULL;
51232 + match->inode = newinode;
51233 + match->device = newdevice;
51234 + match->mode &= ~GR_DELETED;
51236 + insert_acl_subj_label(match, role);
51243 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
51244 + const ino_t newinode, const dev_t newdevice)
51246 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
51247 + struct inodev_entry *match;
51249 + match = inodev_set.i_hash[index];
51251 + while (match && (match->nentry->inode != oldinode ||
51252 + match->nentry->device != olddevice || !match->nentry->deleted))
51253 + match = match->next;
51255 + if (match && (match->nentry->inode == oldinode)
51256 + && (match->nentry->device == olddevice) &&
51257 + match->nentry->deleted) {
51258 + if (match->prev == NULL) {
51259 + inodev_set.i_hash[index] = match->next;
51260 + if (match->next != NULL)
51261 + match->next->prev = NULL;
51263 + match->prev->next = match->next;
51264 + if (match->next != NULL)
51265 + match->next->prev = match->prev;
51267 + match->prev = NULL;
51268 + match->next = NULL;
51269 + match->nentry->inode = newinode;
51270 + match->nentry->device = newdevice;
51271 + match->nentry->deleted = 0;
51273 + insert_inodev_entry(match);
51280 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
51282 + struct acl_subject_label *subj;
51283 + struct acl_role_label *role;
51286 + FOR_EACH_ROLE_START(role)
51287 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
51289 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
51290 + if ((subj->inode == ino) && (subj->device == dev)) {
51291 + subj->inode = ino;
51292 + subj->device = dev;
51294 + FOR_EACH_NESTED_SUBJECT_END(subj)
51295 + FOR_EACH_SUBJECT_START(role, subj, x)
51296 + update_acl_obj_label(matchn->inode, matchn->device,
51298 + FOR_EACH_SUBJECT_END(subj,x)
51299 + FOR_EACH_ROLE_END(role)
51301 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
51307 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
51308 + const struct vfsmount *mnt)
51310 + ino_t ino = dentry->d_inode->i_ino;
51311 + dev_t dev = __get_dev(dentry);
51313 + __do_handle_create(matchn, ino, dev);
51319 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
51321 + struct name_entry *matchn;
51323 + if (unlikely(!(gr_status & GR_READY)))
51326 + preempt_disable();
51327 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
51329 + if (unlikely((unsigned long)matchn)) {
51330 + write_lock(&gr_inode_lock);
51331 + do_handle_create(matchn, dentry, mnt);
51332 + write_unlock(&gr_inode_lock);
51334 + preempt_enable();
51340 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
51342 + struct name_entry *matchn;
51344 + if (unlikely(!(gr_status & GR_READY)))
51347 + preempt_disable();
51348 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
51350 + if (unlikely((unsigned long)matchn)) {
51351 + write_lock(&gr_inode_lock);
51352 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
51353 + write_unlock(&gr_inode_lock);
51355 + preempt_enable();
51361 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
51362 + struct dentry *old_dentry,
51363 + struct dentry *new_dentry,
51364 + struct vfsmount *mnt, const __u8 replace)
51366 + struct name_entry *matchn;
51367 + struct inodev_entry *inodev;
51368 + struct inode *inode = new_dentry->d_inode;
51369 + ino_t old_ino = old_dentry->d_inode->i_ino;
51370 + dev_t old_dev = __get_dev(old_dentry);
51372 + /* vfs_rename swaps the name and parent link for old_dentry and
51374 + at this point, old_dentry has the new name, parent link, and inode
51375 + for the renamed file
51376 + if a file is being replaced by a rename, new_dentry has the inode
51377 + and name for the replaced file
51380 + if (unlikely(!(gr_status & GR_READY)))
51383 + preempt_disable();
51384 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
51386 + /* we wouldn't have to check d_inode if it weren't for
51387 + NFS silly-renaming
51390 + write_lock(&gr_inode_lock);
51391 + if (unlikely(replace && inode)) {
51392 + ino_t new_ino = inode->i_ino;
51393 + dev_t new_dev = __get_dev(new_dentry);
51395 + inodev = lookup_inodev_entry(new_ino, new_dev);
51396 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
51397 + do_handle_delete(inodev, new_ino, new_dev);
51400 + inodev = lookup_inodev_entry(old_ino, old_dev);
51401 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
51402 + do_handle_delete(inodev, old_ino, old_dev);
51404 + if (unlikely((unsigned long)matchn))
51405 + do_handle_create(matchn, old_dentry, mnt);
51407 + write_unlock(&gr_inode_lock);
51408 + preempt_enable();
51414 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
51415 + unsigned char **sum)
51417 + struct acl_role_label *r;
51418 + struct role_allowed_ip *ipp;
51419 + struct role_transition *trans;
51422 + u32 curr_ip = current->signal->curr_ip;
51424 + current->signal->saved_ip = curr_ip;
51426 + /* check transition table */
51428 + for (trans = current->role->transitions; trans; trans = trans->next) {
51429 + if (!strcmp(rolename, trans->rolename)) {
51438 + /* handle special roles that do not require authentication
51441 + FOR_EACH_ROLE_START(r)
51442 + if (!strcmp(rolename, r->rolename) &&
51443 + (r->roletype & GR_ROLE_SPECIAL)) {
51445 + if (r->allowed_ips != NULL) {
51446 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
51447 + if ((ntohl(curr_ip) & ipp->netmask) ==
51448 + (ntohl(ipp->addr) & ipp->netmask))
51456 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
51457 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
51463 + FOR_EACH_ROLE_END(r)
51465 + for (i = 0; i < num_sprole_pws; i++) {
51466 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
51467 + *salt = acl_special_roles[i]->salt;
51468 + *sum = acl_special_roles[i]->sum;
51477 +assign_special_role(char *rolename)
51479 + struct acl_object_label *obj;
51480 + struct acl_role_label *r;
51481 + struct acl_role_label *assigned = NULL;
51482 + struct task_struct *tsk;
51483 + struct file *filp;
51485 + FOR_EACH_ROLE_START(r)
51486 + if (!strcmp(rolename, r->rolename) &&
51487 + (r->roletype & GR_ROLE_SPECIAL)) {
51491 + FOR_EACH_ROLE_END(r)
51496 + read_lock(&tasklist_lock);
51497 + read_lock(&grsec_exec_file_lock);
51499 + tsk = current->real_parent;
51503 + filp = tsk->exec_file;
51504 + if (filp == NULL)
51507 + tsk->is_writable = 0;
51509 + tsk->acl_sp_role = 1;
51510 + tsk->acl_role_id = ++acl_sp_role_value;
51511 + tsk->role = assigned;
51512 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
51514 + /* ignore additional mmap checks for processes that are writable
51515 + by the default ACL */
51516 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51517 + if (unlikely(obj->mode & GR_WRITE))
51518 + tsk->is_writable = 1;
51519 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
51520 + if (unlikely(obj->mode & GR_WRITE))
51521 + tsk->is_writable = 1;
51523 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51524 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
51528 + read_unlock(&grsec_exec_file_lock);
51529 + read_unlock(&tasklist_lock);
51533 +int gr_check_secure_terminal(struct task_struct *task)
51535 + struct task_struct *p, *p2, *p3;
51536 + struct files_struct *files;
51537 + struct fdtable *fdt;
51538 + struct file *our_file = NULL, *file;
51541 + if (task->signal->tty == NULL)
51544 + files = get_files_struct(task);
51545 + if (files != NULL) {
51547 + fdt = files_fdtable(files);
51548 + for (i=0; i < fdt->max_fds; i++) {
51549 + file = fcheck_files(files, i);
51550 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
51555 + rcu_read_unlock();
51556 + put_files_struct(files);
51559 + if (our_file == NULL)
51562 + read_lock(&tasklist_lock);
51563 + do_each_thread(p2, p) {
51564 + files = get_files_struct(p);
51565 + if (files == NULL ||
51566 + (p->signal && p->signal->tty == task->signal->tty)) {
51567 + if (files != NULL)
51568 + put_files_struct(files);
51572 + fdt = files_fdtable(files);
51573 + for (i=0; i < fdt->max_fds; i++) {
51574 + file = fcheck_files(files, i);
51575 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
51576 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
51578 + while (p3->pid > 0) {
51581 + p3 = p3->real_parent;
51585 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
51586 + gr_handle_alertkill(p);
51587 + rcu_read_unlock();
51588 + put_files_struct(files);
51589 + read_unlock(&tasklist_lock);
51594 + rcu_read_unlock();
51595 + put_files_struct(files);
51596 + } while_each_thread(p2, p);
51597 + read_unlock(&tasklist_lock);
51604 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
51606 + struct gr_arg_wrapper uwrap;
51607 + unsigned char *sprole_salt = NULL;
51608 + unsigned char *sprole_sum = NULL;
51609 + int error = sizeof (struct gr_arg_wrapper);
51612 + mutex_lock(&gr_dev_mutex);
51614 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
51619 + if (count != sizeof (struct gr_arg_wrapper)) {
51620 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
51626 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
51627 + gr_auth_expires = 0;
51628 + gr_auth_attempts = 0;
51631 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
51636 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
51641 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
51646 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51647 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51648 + time_after(gr_auth_expires, get_seconds())) {
51653 + /* if non-root trying to do anything other than use a special role,
51654 + do not attempt authentication, do not count towards authentication
51658 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
51659 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51665 + /* ensure pw and special role name are null terminated */
51667 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
51668 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
51671 + * We have our enough of the argument structure..(we have yet
51672 + * to copy_from_user the tables themselves) . Copy the tables
51673 + * only if we need them, i.e. for loading operations. */
51675 + switch (gr_usermode->mode) {
51677 + if (gr_status & GR_READY) {
51679 + if (!gr_check_secure_terminal(current))
51684 + case GR_SHUTDOWN:
51685 + if ((gr_status & GR_READY)
51686 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51687 + pax_open_kernel();
51688 + gr_status &= ~GR_READY;
51689 + pax_close_kernel();
51691 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
51692 + free_variables();
51693 + memset(gr_usermode, 0, sizeof (struct gr_arg));
51694 + memset(gr_system_salt, 0, GR_SALT_LEN);
51695 + memset(gr_system_sum, 0, GR_SHA_LEN);
51696 + } else if (gr_status & GR_READY) {
51697 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
51700 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
51705 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
51706 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
51708 + if (gr_status & GR_READY)
51712 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
51716 + if (!(gr_status & GR_READY)) {
51717 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
51719 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51720 + preempt_disable();
51722 + pax_open_kernel();
51723 + gr_status &= ~GR_READY;
51724 + pax_close_kernel();
51726 + free_variables();
51727 + if (!(error2 = gracl_init(gr_usermode))) {
51728 + preempt_enable();
51729 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
51731 + preempt_enable();
51733 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51736 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51741 + if (unlikely(!(gr_status & GR_READY))) {
51742 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
51747 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51748 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
51749 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
51750 + struct acl_subject_label *segvacl;
51752 + lookup_acl_subj_label(gr_usermode->segv_inode,
51753 + gr_usermode->segv_device,
51756 + segvacl->crashes = 0;
51757 + segvacl->expires = 0;
51759 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
51760 + gr_remove_uid(gr_usermode->segv_uid);
51763 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
51768 + case GR_SPROLEPAM:
51769 + if (unlikely(!(gr_status & GR_READY))) {
51770 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
51775 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
51776 + current->role->expires = 0;
51777 + current->role->auth_attempts = 0;
51780 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51781 + time_after(current->role->expires, get_seconds())) {
51786 + if (lookup_special_role_auth
51787 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
51788 + && ((!sprole_salt && !sprole_sum)
51789 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
51791 + assign_special_role(gr_usermode->sp_role);
51792 + read_lock(&tasklist_lock);
51793 + if (current->real_parent)
51794 + p = current->real_parent->role->rolename;
51795 + read_unlock(&tasklist_lock);
51796 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
51797 + p, acl_sp_role_value);
51799 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
51801 + if(!(current->role->auth_attempts++))
51802 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51807 + case GR_UNSPROLE:
51808 + if (unlikely(!(gr_status & GR_READY))) {
51809 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
51814 + if (current->role->roletype & GR_ROLE_SPECIAL) {
51818 + read_lock(&tasklist_lock);
51819 + if (current->real_parent) {
51820 + p = current->real_parent->role->rolename;
51821 + i = current->real_parent->acl_role_id;
51823 + read_unlock(&tasklist_lock);
51825 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
51833 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
51838 + if (error != -EPERM)
51841 + if(!(gr_auth_attempts++))
51842 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51845 + mutex_unlock(&gr_dev_mutex);
51849 +/* must be called with
51851 + read_lock(&tasklist_lock);
51852 + read_lock(&grsec_exec_file_lock);
51854 +int gr_apply_subject_to_task(struct task_struct *task)
51856 + struct acl_object_label *obj;
51858 + struct acl_subject_label *tmpsubj;
51859 + struct file *filp;
51860 + struct name_entry *nmatch;
51862 + filp = task->exec_file;
51863 + if (filp == NULL)
51866 + /* the following is to apply the correct subject
51867 + on binaries running when the RBAC system
51868 + is enabled, when the binaries have been
51869 + replaced or deleted since their execution
51871 + when the RBAC system starts, the inode/dev
51872 + from exec_file will be one the RBAC system
51873 + is unaware of. It only knows the inode/dev
51874 + of the present file on disk, or the absence
51877 + preempt_disable();
51878 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
51880 + nmatch = lookup_name_entry(tmpname);
51881 + preempt_enable();
51884 + if (nmatch->deleted)
51885 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
51887 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
51888 + if (tmpsubj != NULL)
51889 + task->acl = tmpsubj;
51891 + if (tmpsubj == NULL)
51892 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
51895 + task->is_writable = 0;
51896 + /* ignore additional mmap checks for processes that are writable
51897 + by the default ACL */
51898 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51899 + if (unlikely(obj->mode & GR_WRITE))
51900 + task->is_writable = 1;
51901 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
51902 + if (unlikely(obj->mode & GR_WRITE))
51903 + task->is_writable = 1;
51905 + gr_set_proc_res(task);
51907 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51908 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
51918 +gr_set_acls(const int type)
51920 + struct task_struct *task, *task2;
51921 + struct acl_role_label *role = current->role;
51922 + __u16 acl_role_id = current->acl_role_id;
51923 + const struct cred *cred;
51927 + read_lock(&tasklist_lock);
51928 + read_lock(&grsec_exec_file_lock);
51929 + do_each_thread(task2, task) {
51930 + /* check to see if we're called from the exit handler,
51931 + if so, only replace ACLs that have inherited the admin
51934 + if (type && (task->role != role ||
51935 + task->acl_role_id != acl_role_id))
51938 + task->acl_role_id = 0;
51939 + task->acl_sp_role = 0;
51941 + if (task->exec_file) {
51942 + cred = __task_cred(task);
51943 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
51944 + ret = gr_apply_subject_to_task(task);
51946 + read_unlock(&grsec_exec_file_lock);
51947 + read_unlock(&tasklist_lock);
51948 + rcu_read_unlock();
51949 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
51953 + // it's a kernel process
51954 + task->role = kernel_role;
51955 + task->acl = kernel_role->root_label;
51956 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
51957 + task->acl->mode &= ~GR_PROCFIND;
51960 + } while_each_thread(task2, task);
51961 + read_unlock(&grsec_exec_file_lock);
51962 + read_unlock(&tasklist_lock);
51963 + rcu_read_unlock();
51969 +gr_learn_resource(const struct task_struct *task,
51970 + const int res, const unsigned long wanted, const int gt)
51972 + struct acl_subject_label *acl;
51973 + const struct cred *cred;
51975 + if (unlikely((gr_status & GR_READY) &&
51976 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
51977 + goto skip_reslog;
51979 +#ifdef CONFIG_GRKERNSEC_RESLOG
51980 + gr_log_resource(task, res, wanted, gt);
51984 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
51989 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
51990 + !(acl->resmask & (1 << (unsigned short) res))))
51993 + if (wanted >= acl->res[res].rlim_cur) {
51994 + unsigned long res_add;
51996 + res_add = wanted;
51999 + res_add += GR_RLIM_CPU_BUMP;
52001 + case RLIMIT_FSIZE:
52002 + res_add += GR_RLIM_FSIZE_BUMP;
52004 + case RLIMIT_DATA:
52005 + res_add += GR_RLIM_DATA_BUMP;
52007 + case RLIMIT_STACK:
52008 + res_add += GR_RLIM_STACK_BUMP;
52010 + case RLIMIT_CORE:
52011 + res_add += GR_RLIM_CORE_BUMP;
52014 + res_add += GR_RLIM_RSS_BUMP;
52016 + case RLIMIT_NPROC:
52017 + res_add += GR_RLIM_NPROC_BUMP;
52019 + case RLIMIT_NOFILE:
52020 + res_add += GR_RLIM_NOFILE_BUMP;
52022 + case RLIMIT_MEMLOCK:
52023 + res_add += GR_RLIM_MEMLOCK_BUMP;
52026 + res_add += GR_RLIM_AS_BUMP;
52028 + case RLIMIT_LOCKS:
52029 + res_add += GR_RLIM_LOCKS_BUMP;
52031 + case RLIMIT_SIGPENDING:
52032 + res_add += GR_RLIM_SIGPENDING_BUMP;
52034 + case RLIMIT_MSGQUEUE:
52035 + res_add += GR_RLIM_MSGQUEUE_BUMP;
52037 + case RLIMIT_NICE:
52038 + res_add += GR_RLIM_NICE_BUMP;
52040 + case RLIMIT_RTPRIO:
52041 + res_add += GR_RLIM_RTPRIO_BUMP;
52043 + case RLIMIT_RTTIME:
52044 + res_add += GR_RLIM_RTTIME_BUMP;
52048 + acl->res[res].rlim_cur = res_add;
52050 + if (wanted > acl->res[res].rlim_max)
52051 + acl->res[res].rlim_max = res_add;
52053 + /* only log the subject filename, since resource logging is supported for
52054 + single-subject learning only */
52056 + cred = __task_cred(task);
52057 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
52058 + task->role->roletype, cred->uid, cred->gid, acl->filename,
52059 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
52060 + "", (unsigned long) res, &task->signal->saved_ip);
52061 + rcu_read_unlock();
52067 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
52069 +pax_set_initial_flags(struct linux_binprm *bprm)
52071 + struct task_struct *task = current;
52072 + struct acl_subject_label *proc;
52073 + unsigned long flags;
52075 + if (unlikely(!(gr_status & GR_READY)))
52078 + flags = pax_get_flags(task);
52080 + proc = task->acl;
52082 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
52083 + flags &= ~MF_PAX_PAGEEXEC;
52084 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
52085 + flags &= ~MF_PAX_SEGMEXEC;
52086 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
52087 + flags &= ~MF_PAX_RANDMMAP;
52088 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
52089 + flags &= ~MF_PAX_EMUTRAMP;
52090 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
52091 + flags &= ~MF_PAX_MPROTECT;
52093 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
52094 + flags |= MF_PAX_PAGEEXEC;
52095 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
52096 + flags |= MF_PAX_SEGMEXEC;
52097 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
52098 + flags |= MF_PAX_RANDMMAP;
52099 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
52100 + flags |= MF_PAX_EMUTRAMP;
52101 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
52102 + flags |= MF_PAX_MPROTECT;
52104 + pax_set_flags(task, flags);
52110 +#ifdef CONFIG_SYSCTL
52111 +/* Eric Biederman likes breaking userland ABI and every inode-based security
52112 + system to save 35kb of memory */
52114 +/* we modify the passed in filename, but adjust it back before returning */
52115 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
52117 + struct name_entry *nmatch;
52118 + char *p, *lastp = NULL;
52119 + struct acl_object_label *obj = NULL, *tmp;
52120 + struct acl_subject_label *tmpsubj;
52123 + read_lock(&gr_inode_lock);
52125 + p = name + len - 1;
52127 + nmatch = lookup_name_entry(name);
52128 + if (lastp != NULL)
52131 + if (nmatch == NULL)
52132 + goto next_component;
52133 + tmpsubj = current->acl;
52135 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
52136 + if (obj != NULL) {
52137 + tmp = obj->globbed;
52139 + if (!glob_match(tmp->filename, name)) {
52147 + } while ((tmpsubj = tmpsubj->parent_subject));
52153 + while (*p != '/')
52165 + read_unlock(&gr_inode_lock);
52166 + /* obj returned will always be non-null */
52170 +/* returns 0 when allowing, non-zero on error
52171 + op of 0 is used for readdir, so we don't log the names of hidden files
52174 +gr_handle_sysctl(const struct ctl_table *table, const int op)
52176 + struct ctl_table *tmp;
52177 + const char *proc_sys = "/proc/sys";
52179 + struct acl_object_label *obj;
52180 + unsigned short len = 0, pos = 0, depth = 0, i;
52184 + if (unlikely(!(gr_status & GR_READY)))
52187 + /* for now, ignore operations on non-sysctl entries if it's not a
52189 + if (table->child != NULL && op != 0)
52193 + /* it's only a read if it's an entry, read on dirs is for readdir */
52194 + if (op & MAY_READ)
52196 + if (op & MAY_WRITE)
52197 + mode |= GR_WRITE;
52199 + preempt_disable();
52201 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52203 + /* it's only a read/write if it's an actual entry, not a dir
52204 + (which are opened for readdir)
52207 + /* convert the requested sysctl entry into a pathname */
52209 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
52210 + len += strlen(tmp->procname);
52215 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
52220 + memset(path, 0, PAGE_SIZE);
52222 + memcpy(path, proc_sys, strlen(proc_sys));
52224 + pos += strlen(proc_sys);
52226 + for (; depth > 0; depth--) {
52229 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
52230 + if (depth == i) {
52231 + memcpy(path + pos, tmp->procname,
52232 + strlen(tmp->procname));
52233 + pos += strlen(tmp->procname);
52239 + obj = gr_lookup_by_name(path, pos);
52240 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
52242 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
52243 + ((err & mode) != mode))) {
52244 + __u32 new_mode = mode;
52246 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52249 + gr_log_learn_sysctl(path, new_mode);
52250 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
52251 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
52253 + } else if (!(err & GR_FIND)) {
52255 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
52256 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
52257 + path, (mode & GR_READ) ? " reading" : "",
52258 + (mode & GR_WRITE) ? " writing" : "");
52260 + } else if ((err & mode) != mode) {
52262 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
52263 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
52264 + path, (mode & GR_READ) ? " reading" : "",
52265 + (mode & GR_WRITE) ? " writing" : "");
52271 + preempt_enable();
52278 +gr_handle_proc_ptrace(struct task_struct *task)
52280 + struct file *filp;
52281 + struct task_struct *tmp = task;
52282 + struct task_struct *curtemp = current;
52285 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52286 + if (unlikely(!(gr_status & GR_READY)))
52290 + read_lock(&tasklist_lock);
52291 + read_lock(&grsec_exec_file_lock);
52292 + filp = task->exec_file;
52294 + while (tmp->pid > 0) {
52295 + if (tmp == curtemp)
52297 + tmp = tmp->real_parent;
52300 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52301 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
52302 + read_unlock(&grsec_exec_file_lock);
52303 + read_unlock(&tasklist_lock);
52307 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52308 + if (!(gr_status & GR_READY)) {
52309 + read_unlock(&grsec_exec_file_lock);
52310 + read_unlock(&tasklist_lock);
52315 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
52316 + read_unlock(&grsec_exec_file_lock);
52317 + read_unlock(&tasklist_lock);
52319 + if (retmode & GR_NOPTRACE)
52322 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
52323 + && (current->acl != task->acl || (current->acl != current->role->root_label
52324 + && current->pid != task->pid)))
52330 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
52332 + if (unlikely(!(gr_status & GR_READY)))
52335 + if (!(current->role->roletype & GR_ROLE_GOD))
52338 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
52339 + p->role->rolename, gr_task_roletype_to_char(p),
52340 + p->acl->filename);
52344 +gr_handle_ptrace(struct task_struct *task, const long request)
52346 + struct task_struct *tmp = task;
52347 + struct task_struct *curtemp = current;
52350 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52351 + if (unlikely(!(gr_status & GR_READY)))
52355 + read_lock(&tasklist_lock);
52356 + while (tmp->pid > 0) {
52357 + if (tmp == curtemp)
52359 + tmp = tmp->real_parent;
52362 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52363 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
52364 + read_unlock(&tasklist_lock);
52365 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52368 + read_unlock(&tasklist_lock);
52370 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52371 + if (!(gr_status & GR_READY))
52375 + read_lock(&grsec_exec_file_lock);
52376 + if (unlikely(!task->exec_file)) {
52377 + read_unlock(&grsec_exec_file_lock);
52381 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
52382 + read_unlock(&grsec_exec_file_lock);
52384 + if (retmode & GR_NOPTRACE) {
52385 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52389 + if (retmode & GR_PTRACERD) {
52390 + switch (request) {
52391 + case PTRACE_SEIZE:
52392 + case PTRACE_POKETEXT:
52393 + case PTRACE_POKEDATA:
52394 + case PTRACE_POKEUSR:
52395 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
52396 + case PTRACE_SETREGS:
52397 + case PTRACE_SETFPREGS:
52400 + case PTRACE_SETFPXREGS:
52402 +#ifdef CONFIG_ALTIVEC
52403 + case PTRACE_SETVRREGS:
52409 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
52410 + !(current->role->roletype & GR_ROLE_GOD) &&
52411 + (current->acl != task->acl)) {
52412 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52419 +static int is_writable_mmap(const struct file *filp)
52421 + struct task_struct *task = current;
52422 + struct acl_object_label *obj, *obj2;
52424 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
52425 + !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))) {
52426 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52427 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
52428 + task->role->root_label);
52429 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
52430 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
52438 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
52442 + if (unlikely(!file || !(prot & PROT_EXEC)))
52445 + if (is_writable_mmap(file))
52449 + gr_search_file(file->f_path.dentry,
52450 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52451 + file->f_path.mnt);
52453 + if (!gr_tpe_allow(file))
52456 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52457 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52459 + } else if (unlikely(!(mode & GR_EXEC))) {
52461 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52462 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52470 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
52474 + if (unlikely(!file || !(prot & PROT_EXEC)))
52477 + if (is_writable_mmap(file))
52481 + gr_search_file(file->f_path.dentry,
52482 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52483 + file->f_path.mnt);
52485 + if (!gr_tpe_allow(file))
52488 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52489 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52491 + } else if (unlikely(!(mode & GR_EXEC))) {
52493 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52494 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52502 +gr_acl_handle_psacct(struct task_struct *task, const long code)
52504 + unsigned long runtime;
52505 + unsigned long cputime;
52506 + unsigned int wday, cday;
52510 + struct timespec timeval;
52512 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
52513 + !(task->acl->mode & GR_PROCACCT)))
52516 + do_posix_clock_monotonic_gettime(&timeval);
52517 + runtime = timeval.tv_sec - task->start_time.tv_sec;
52518 + wday = runtime / (3600 * 24);
52519 + runtime -= wday * (3600 * 24);
52520 + whr = runtime / 3600;
52521 + runtime -= whr * 3600;
52522 + wmin = runtime / 60;
52523 + runtime -= wmin * 60;
52526 + cputime = (task->utime + task->stime) / HZ;
52527 + cday = cputime / (3600 * 24);
52528 + cputime -= cday * (3600 * 24);
52529 + chr = cputime / 3600;
52530 + cputime -= chr * 3600;
52531 + cmin = cputime / 60;
52532 + cputime -= cmin * 60;
52535 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
52540 +void gr_set_kernel_label(struct task_struct *task)
52542 + if (gr_status & GR_READY) {
52543 + task->role = kernel_role;
52544 + task->acl = kernel_role->root_label;
52549 +#ifdef CONFIG_TASKSTATS
52550 +int gr_is_taskstats_denied(int pid)
52552 + struct task_struct *task;
52553 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52554 + const struct cred *cred;
52558 + /* restrict taskstats viewing to un-chrooted root users
52559 + who have the 'view' subject flag if the RBAC system is enabled
52563 + read_lock(&tasklist_lock);
52564 + task = find_task_by_vpid(pid);
52566 +#ifdef CONFIG_GRKERNSEC_CHROOT
52567 + if (proc_is_chrooted(task))
52570 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52571 + cred = __task_cred(task);
52572 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52573 + if (cred->uid != 0)
52575 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52576 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
52580 + if (gr_status & GR_READY) {
52581 + if (!(task->acl->mode & GR_VIEW))
52587 + read_unlock(&tasklist_lock);
52588 + rcu_read_unlock();
52594 +/* AUXV entries are filled via a descendant of search_binary_handler
52595 + after we've already applied the subject for the target
52597 +int gr_acl_enable_at_secure(void)
52599 + if (unlikely(!(gr_status & GR_READY)))
52602 + if (current->acl->mode & GR_ATSECURE)
52608 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
52610 + struct task_struct *task = current;
52611 + struct dentry *dentry = file->f_path.dentry;
52612 + struct vfsmount *mnt = file->f_path.mnt;
52613 + struct acl_object_label *obj, *tmp;
52614 + struct acl_subject_label *subj;
52615 + unsigned int bufsize;
52618 + dev_t dev = __get_dev(dentry);
52620 + if (unlikely(!(gr_status & GR_READY)))
52623 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52626 + /* ignore Eric Biederman */
52627 + if (IS_PRIVATE(dentry->d_inode))
52630 + subj = task->acl;
52632 + obj = lookup_acl_obj_label(ino, dev, subj);
52634 + return (obj->mode & GR_FIND) ? 1 : 0;
52635 + } while ((subj = subj->parent_subject));
52637 + /* this is purely an optimization since we're looking for an object
52638 + for the directory we're doing a readdir on
52639 + if it's possible for any globbed object to match the entry we're
52640 + filling into the directory, then the object we find here will be
52641 + an anchor point with attached globbed objects
52643 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
52644 + if (obj->globbed == NULL)
52645 + return (obj->mode & GR_FIND) ? 1 : 0;
52647 + is_not_root = ((obj->filename[0] == '/') &&
52648 + (obj->filename[1] == '\0')) ? 0 : 1;
52649 + bufsize = PAGE_SIZE - namelen - is_not_root;
52651 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
52652 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
52655 + preempt_disable();
52656 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52659 + bufsize = strlen(path);
52661 + /* if base is "/", don't append an additional slash */
52663 + *(path + bufsize) = '/';
52664 + memcpy(path + bufsize + is_not_root, name, namelen);
52665 + *(path + bufsize + namelen + is_not_root) = '\0';
52667 + tmp = obj->globbed;
52669 + if (!glob_match(tmp->filename, path)) {
52670 + preempt_enable();
52671 + return (tmp->mode & GR_FIND) ? 1 : 0;
52675 + preempt_enable();
52676 + return (obj->mode & GR_FIND) ? 1 : 0;
52679 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
52680 +EXPORT_SYMBOL(gr_acl_is_enabled);
52682 +EXPORT_SYMBOL(gr_learn_resource);
52683 +EXPORT_SYMBOL(gr_set_kernel_label);
52684 +#ifdef CONFIG_SECURITY
52685 +EXPORT_SYMBOL(gr_check_user_change);
52686 +EXPORT_SYMBOL(gr_check_group_change);
52689 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
52690 new file mode 100644
52691 index 0000000..34fefda
52693 +++ b/grsecurity/gracl_alloc.c
52695 +#include <linux/kernel.h>
52696 +#include <linux/mm.h>
52697 +#include <linux/slab.h>
52698 +#include <linux/vmalloc.h>
52699 +#include <linux/gracl.h>
52700 +#include <linux/grsecurity.h>
52702 +static unsigned long alloc_stack_next = 1;
52703 +static unsigned long alloc_stack_size = 1;
52704 +static void **alloc_stack;
52706 +static __inline__ int
52709 + if (alloc_stack_next == 1)
52712 + kfree(alloc_stack[alloc_stack_next - 2]);
52714 + alloc_stack_next--;
52719 +static __inline__ int
52720 +alloc_push(void *buf)
52722 + if (alloc_stack_next >= alloc_stack_size)
52725 + alloc_stack[alloc_stack_next - 1] = buf;
52727 + alloc_stack_next++;
52733 +acl_alloc(unsigned long len)
52735 + void *ret = NULL;
52737 + if (!len || len > PAGE_SIZE)
52740 + ret = kmalloc(len, GFP_KERNEL);
52743 + if (alloc_push(ret)) {
52754 +acl_alloc_num(unsigned long num, unsigned long len)
52756 + if (!len || (num > (PAGE_SIZE / len)))
52759 + return acl_alloc(num * len);
52763 +acl_free_all(void)
52765 + if (gr_acl_is_enabled() || !alloc_stack)
52768 + while (alloc_pop()) ;
52770 + if (alloc_stack) {
52771 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
52772 + kfree(alloc_stack);
52774 + vfree(alloc_stack);
52777 + alloc_stack = NULL;
52778 + alloc_stack_size = 1;
52779 + alloc_stack_next = 1;
52785 +acl_alloc_stack_init(unsigned long size)
52787 + if ((size * sizeof (void *)) <= PAGE_SIZE)
52789 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
52791 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
52793 + alloc_stack_size = size;
52795 + if (!alloc_stack)
52800 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
52801 new file mode 100644
52802 index 0000000..955ddfb
52804 +++ b/grsecurity/gracl_cap.c
52806 +#include <linux/kernel.h>
52807 +#include <linux/module.h>
52808 +#include <linux/sched.h>
52809 +#include <linux/gracl.h>
52810 +#include <linux/grsecurity.h>
52811 +#include <linux/grinternal.h>
52813 +extern const char *captab_log[];
52814 +extern int captab_log_entries;
52817 +gr_acl_is_capable(const int cap)
52819 + struct task_struct *task = current;
52820 + const struct cred *cred = current_cred();
52821 + struct acl_subject_label *curracl;
52822 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52823 + kernel_cap_t cap_audit = __cap_empty_set;
52825 + if (!gr_acl_is_enabled())
52828 + curracl = task->acl;
52830 + cap_drop = curracl->cap_lower;
52831 + cap_mask = curracl->cap_mask;
52832 + cap_audit = curracl->cap_invert_audit;
52834 + while ((curracl = curracl->parent_subject)) {
52835 + /* if the cap isn't specified in the current computed mask but is specified in the
52836 + current level subject, and is lowered in the current level subject, then add
52837 + it to the set of dropped capabilities
52838 + otherwise, add the current level subject's mask to the current computed mask
52840 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52841 + cap_raise(cap_mask, cap);
52842 + if (cap_raised(curracl->cap_lower, cap))
52843 + cap_raise(cap_drop, cap);
52844 + if (cap_raised(curracl->cap_invert_audit, cap))
52845 + cap_raise(cap_audit, cap);
52849 + if (!cap_raised(cap_drop, cap)) {
52850 + if (cap_raised(cap_audit, cap))
52851 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
52855 + curracl = task->acl;
52857 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
52858 + && cap_raised(cred->cap_effective, cap)) {
52859 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
52860 + task->role->roletype, cred->uid,
52861 + cred->gid, task->exec_file ?
52862 + gr_to_filename(task->exec_file->f_path.dentry,
52863 + task->exec_file->f_path.mnt) : curracl->filename,
52864 + curracl->filename, 0UL,
52865 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
52869 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
52870 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
52875 +gr_acl_is_capable_nolog(const int cap)
52877 + struct acl_subject_label *curracl;
52878 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52880 + if (!gr_acl_is_enabled())
52883 + curracl = current->acl;
52885 + cap_drop = curracl->cap_lower;
52886 + cap_mask = curracl->cap_mask;
52888 + while ((curracl = curracl->parent_subject)) {
52889 + /* if the cap isn't specified in the current computed mask but is specified in the
52890 + current level subject, and is lowered in the current level subject, then add
52891 + it to the set of dropped capabilities
52892 + otherwise, add the current level subject's mask to the current computed mask
52894 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52895 + cap_raise(cap_mask, cap);
52896 + if (cap_raised(curracl->cap_lower, cap))
52897 + cap_raise(cap_drop, cap);
52901 + if (!cap_raised(cap_drop, cap))
52907 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
52908 new file mode 100644
52909 index 0000000..88d0e87
52911 +++ b/grsecurity/gracl_fs.c
52913 +#include <linux/kernel.h>
52914 +#include <linux/sched.h>
52915 +#include <linux/types.h>
52916 +#include <linux/fs.h>
52917 +#include <linux/file.h>
52918 +#include <linux/stat.h>
52919 +#include <linux/grsecurity.h>
52920 +#include <linux/grinternal.h>
52921 +#include <linux/gracl.h>
52924 +gr_acl_umask(void)
52926 + if (unlikely(!gr_acl_is_enabled()))
52929 + return current->role->umask;
52933 +gr_acl_handle_hidden_file(const struct dentry * dentry,
52934 + const struct vfsmount * mnt)
52938 + if (unlikely(!dentry->d_inode))
52942 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
52944 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
52945 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52947 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
52948 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52950 + } else if (unlikely(!(mode & GR_FIND)))
52957 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
52960 + __u32 reqmode = GR_FIND;
52963 + if (unlikely(!dentry->d_inode))
52966 + if (acc_mode & MAY_APPEND)
52967 + reqmode |= GR_APPEND;
52968 + else if (acc_mode & MAY_WRITE)
52969 + reqmode |= GR_WRITE;
52970 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
52971 + reqmode |= GR_READ;
52974 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52977 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52978 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52979 + reqmode & GR_READ ? " reading" : "",
52980 + reqmode & GR_WRITE ? " writing" : reqmode &
52981 + GR_APPEND ? " appending" : "");
52984 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52986 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52987 + reqmode & GR_READ ? " reading" : "",
52988 + reqmode & GR_WRITE ? " writing" : reqmode &
52989 + GR_APPEND ? " appending" : "");
52991 + } else if (unlikely((mode & reqmode) != reqmode))
52998 +gr_acl_handle_creat(const struct dentry * dentry,
52999 + const struct dentry * p_dentry,
53000 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
53003 + __u32 reqmode = GR_WRITE | GR_CREATE;
53006 + if (acc_mode & MAY_APPEND)
53007 + reqmode |= GR_APPEND;
53008 + // if a directory was required or the directory already exists, then
53009 + // don't count this open as a read
53010 + if ((acc_mode & MAY_READ) &&
53011 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
53012 + reqmode |= GR_READ;
53013 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
53014 + reqmode |= GR_SETID;
53017 + gr_check_create(dentry, p_dentry, p_mnt,
53018 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
53020 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
53021 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
53022 + reqmode & GR_READ ? " reading" : "",
53023 + reqmode & GR_WRITE ? " writing" : reqmode &
53024 + GR_APPEND ? " appending" : "");
53027 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
53029 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
53030 + reqmode & GR_READ ? " reading" : "",
53031 + reqmode & GR_WRITE ? " writing" : reqmode &
53032 + GR_APPEND ? " appending" : "");
53034 + } else if (unlikely((mode & reqmode) != reqmode))
53041 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
53044 + __u32 mode, reqmode = GR_FIND;
53046 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
53047 + reqmode |= GR_EXEC;
53048 + if (fmode & S_IWOTH)
53049 + reqmode |= GR_WRITE;
53050 + if (fmode & S_IROTH)
53051 + reqmode |= GR_READ;
53054 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
53057 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
53058 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
53059 + reqmode & GR_READ ? " reading" : "",
53060 + reqmode & GR_WRITE ? " writing" : "",
53061 + reqmode & GR_EXEC ? " executing" : "");
53064 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
53066 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
53067 + reqmode & GR_READ ? " reading" : "",
53068 + reqmode & GR_WRITE ? " writing" : "",
53069 + reqmode & GR_EXEC ? " executing" : "");
53071 + } else if (unlikely((mode & reqmode) != reqmode))
53077 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
53081 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
53083 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
53084 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
53086 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
53087 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
53089 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
53092 + return (reqmode);
53096 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
53098 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
53102 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
53104 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
53108 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
53110 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
53114 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
53116 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
53120 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
53121 + umode_t *modeptr)
53125 + *modeptr &= ~gr_acl_umask();
53128 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
53131 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
53132 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
53133 + GR_CHMOD_ACL_MSG);
53135 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
53140 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
53142 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
53146 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
53148 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
53152 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
53154 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
53158 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
53160 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
53161 + GR_UNIXCONNECT_ACL_MSG);
53164 +/* hardlinks require at minimum create and link permission,
53165 + any additional privilege required is based on the
53166 + privilege of the file being linked to
53169 +gr_acl_handle_link(const struct dentry * new_dentry,
53170 + const struct dentry * parent_dentry,
53171 + const struct vfsmount * parent_mnt,
53172 + const struct dentry * old_dentry,
53173 + const struct vfsmount * old_mnt, const char *to)
53176 + __u32 needmode = GR_CREATE | GR_LINK;
53177 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
53180 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
53183 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
53184 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
53186 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
53187 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
53189 + } else if (unlikely((mode & needmode) != needmode))
53196 +gr_acl_handle_symlink(const struct dentry * new_dentry,
53197 + const struct dentry * parent_dentry,
53198 + const struct vfsmount * parent_mnt, const char *from)
53200 + __u32 needmode = GR_WRITE | GR_CREATE;
53204 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
53205 + GR_CREATE | GR_AUDIT_CREATE |
53206 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
53208 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
53209 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
53211 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
53212 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
53214 + } else if (unlikely((mode & needmode) != needmode))
53217 + return (GR_WRITE | GR_CREATE);
53220 +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)
53224 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
53226 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
53227 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
53229 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
53230 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
53232 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
53235 + return (reqmode);
53239 +gr_acl_handle_mknod(const struct dentry * new_dentry,
53240 + const struct dentry * parent_dentry,
53241 + const struct vfsmount * parent_mnt,
53244 + __u32 reqmode = GR_WRITE | GR_CREATE;
53245 + if (unlikely(mode & (S_ISUID | S_ISGID)))
53246 + reqmode |= GR_SETID;
53248 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
53249 + reqmode, GR_MKNOD_ACL_MSG);
53253 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
53254 + const struct dentry *parent_dentry,
53255 + const struct vfsmount *parent_mnt)
53257 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
53258 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
53261 +#define RENAME_CHECK_SUCCESS(old, new) \
53262 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
53263 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
53266 +gr_acl_handle_rename(struct dentry *new_dentry,
53267 + struct dentry *parent_dentry,
53268 + const struct vfsmount *parent_mnt,
53269 + struct dentry *old_dentry,
53270 + struct inode *old_parent_inode,
53271 + struct vfsmount *old_mnt, const char *newname)
53273 + __u32 comp1, comp2;
53276 + if (unlikely(!gr_acl_is_enabled()))
53279 + if (!new_dentry->d_inode) {
53280 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
53281 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
53282 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
53283 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
53284 + GR_DELETE | GR_AUDIT_DELETE |
53285 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53286 + GR_SUPPRESS, old_mnt);
53288 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
53289 + GR_CREATE | GR_DELETE |
53290 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
53291 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53292 + GR_SUPPRESS, parent_mnt);
53294 + gr_search_file(old_dentry,
53295 + GR_READ | GR_WRITE | GR_AUDIT_READ |
53296 + GR_DELETE | GR_AUDIT_DELETE |
53297 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
53300 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
53301 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
53302 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53303 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
53304 + && !(comp2 & GR_SUPPRESS)) {
53305 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53307 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
53314 +gr_acl_handle_exit(void)
53318 + struct file *exec_file;
53320 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
53321 + !(current->role->roletype & GR_ROLE_PERSIST))) {
53322 + id = current->acl_role_id;
53323 + rolename = current->role->rolename;
53325 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
53328 + write_lock(&grsec_exec_file_lock);
53329 + exec_file = current->exec_file;
53330 + current->exec_file = NULL;
53331 + write_unlock(&grsec_exec_file_lock);
53338 +gr_acl_handle_procpidmem(const struct task_struct *task)
53340 + if (unlikely(!gr_acl_is_enabled()))
53343 + if (task != current && task->acl->mode & GR_PROTPROCFD)
53348 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
53349 new file mode 100644
53350 index 0000000..17050ca
53352 +++ b/grsecurity/gracl_ip.c
53354 +#include <linux/kernel.h>
53355 +#include <asm/uaccess.h>
53356 +#include <asm/errno.h>
53357 +#include <net/sock.h>
53358 +#include <linux/file.h>
53359 +#include <linux/fs.h>
53360 +#include <linux/net.h>
53361 +#include <linux/in.h>
53362 +#include <linux/skbuff.h>
53363 +#include <linux/ip.h>
53364 +#include <linux/udp.h>
53365 +#include <linux/types.h>
53366 +#include <linux/sched.h>
53367 +#include <linux/netdevice.h>
53368 +#include <linux/inetdevice.h>
53369 +#include <linux/gracl.h>
53370 +#include <linux/grsecurity.h>
53371 +#include <linux/grinternal.h>
53373 +#define GR_BIND 0x01
53374 +#define GR_CONNECT 0x02
53375 +#define GR_INVERT 0x04
53376 +#define GR_BINDOVERRIDE 0x08
53377 +#define GR_CONNECTOVERRIDE 0x10
53378 +#define GR_SOCK_FAMILY 0x20
53380 +static const char * gr_protocols[IPPROTO_MAX] = {
53381 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
53382 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
53383 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
53384 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
53385 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
53386 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
53387 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
53388 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
53389 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
53390 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
53391 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
53392 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
53393 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
53394 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
53395 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
53396 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
53397 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
53398 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
53399 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
53400 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
53401 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
53402 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
53403 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
53404 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
53405 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
53406 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
53407 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
53408 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
53409 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
53410 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
53411 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
53412 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
53415 +static const char * gr_socktypes[SOCK_MAX] = {
53416 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
53417 + "unknown:7", "unknown:8", "unknown:9", "packet"
53420 +static const char * gr_sockfamilies[AF_MAX+1] = {
53421 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
53422 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
53423 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
53424 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
53428 +gr_proto_to_name(unsigned char proto)
53430 + return gr_protocols[proto];
53434 +gr_socktype_to_name(unsigned char type)
53436 + return gr_socktypes[type];
53440 +gr_sockfamily_to_name(unsigned char family)
53442 + return gr_sockfamilies[family];
53446 +gr_search_socket(const int domain, const int type, const int protocol)
53448 + struct acl_subject_label *curr;
53449 + const struct cred *cred = current_cred();
53451 + if (unlikely(!gr_acl_is_enabled()))
53454 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
53455 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
53456 + goto exit; // let the kernel handle it
53458 + curr = current->acl;
53460 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
53461 + /* the family is allowed, if this is PF_INET allow it only if
53462 + the extra sock type/protocol checks pass */
53463 + if (domain == PF_INET)
53467 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53468 + __u32 fakeip = 0;
53469 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53470 + current->role->roletype, cred->uid,
53471 + cred->gid, current->exec_file ?
53472 + gr_to_filename(current->exec_file->f_path.dentry,
53473 + current->exec_file->f_path.mnt) :
53474 + curr->filename, curr->filename,
53475 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
53476 + ¤t->signal->saved_ip);
53483 + /* the rest of this checking is for IPv4 only */
53487 + if ((curr->ip_type & (1 << type)) &&
53488 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
53491 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53492 + /* we don't place acls on raw sockets , and sometimes
53493 + dgram/ip sockets are opened for ioctl and not
53494 + bind/connect, so we'll fake a bind learn log */
53495 + if (type == SOCK_RAW || type == SOCK_PACKET) {
53496 + __u32 fakeip = 0;
53497 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53498 + current->role->roletype, cred->uid,
53499 + cred->gid, current->exec_file ?
53500 + gr_to_filename(current->exec_file->f_path.dentry,
53501 + current->exec_file->f_path.mnt) :
53502 + curr->filename, curr->filename,
53503 + &fakeip, 0, type,
53504 + protocol, GR_CONNECT, ¤t->signal->saved_ip);
53505 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
53506 + __u32 fakeip = 0;
53507 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53508 + current->role->roletype, cred->uid,
53509 + cred->gid, current->exec_file ?
53510 + gr_to_filename(current->exec_file->f_path.dentry,
53511 + current->exec_file->f_path.mnt) :
53512 + curr->filename, curr->filename,
53513 + &fakeip, 0, type,
53514 + protocol, GR_BIND, ¤t->signal->saved_ip);
53516 + /* we'll log when they use connect or bind */
53521 + if (domain == PF_INET)
53522 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
53523 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
53525 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
53526 + gr_socktype_to_name(type), protocol);
53533 +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)
53535 + if ((ip->mode & mode) &&
53536 + (ip_port >= ip->low) &&
53537 + (ip_port <= ip->high) &&
53538 + ((ntohl(ip_addr) & our_netmask) ==
53539 + (ntohl(our_addr) & our_netmask))
53540 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
53541 + && (ip->type & (1 << type))) {
53542 + if (ip->mode & GR_INVERT)
53543 + return 2; // specifically denied
53545 + return 1; // allowed
53548 + return 0; // not specifically allowed, may continue parsing
53552 +gr_search_connectbind(const int full_mode, struct sock *sk,
53553 + struct sockaddr_in *addr, const int type)
53555 + char iface[IFNAMSIZ] = {0};
53556 + struct acl_subject_label *curr;
53557 + struct acl_ip_label *ip;
53558 + struct inet_sock *isk;
53559 + struct net_device *dev;
53560 + struct in_device *idev;
53563 + int mode = full_mode & (GR_BIND | GR_CONNECT);
53564 + __u32 ip_addr = 0;
53566 + __u32 our_netmask;
53568 + __u16 ip_port = 0;
53569 + const struct cred *cred = current_cred();
53571 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
53574 + curr = current->acl;
53575 + isk = inet_sk(sk);
53577 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
53578 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
53579 + addr->sin_addr.s_addr = curr->inaddr_any_override;
53580 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
53581 + struct sockaddr_in saddr;
53584 + saddr.sin_family = AF_INET;
53585 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
53586 + saddr.sin_port = isk->inet_sport;
53588 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53592 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53600 + ip_addr = addr->sin_addr.s_addr;
53601 + ip_port = ntohs(addr->sin_port);
53603 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53604 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53605 + current->role->roletype, cred->uid,
53606 + cred->gid, current->exec_file ?
53607 + gr_to_filename(current->exec_file->f_path.dentry,
53608 + current->exec_file->f_path.mnt) :
53609 + curr->filename, curr->filename,
53610 + &ip_addr, ip_port, type,
53611 + sk->sk_protocol, mode, ¤t->signal->saved_ip);
53615 + for (i = 0; i < curr->ip_num; i++) {
53616 + ip = *(curr->ips + i);
53617 + if (ip->iface != NULL) {
53618 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
53619 + p = strchr(iface, ':');
53622 + dev = dev_get_by_name(sock_net(sk), iface);
53625 + idev = in_dev_get(dev);
53626 + if (idev == NULL) {
53632 + if (!strcmp(ip->iface, ifa->ifa_label)) {
53633 + our_addr = ifa->ifa_address;
53634 + our_netmask = 0xffffffff;
53635 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53637 + rcu_read_unlock();
53638 + in_dev_put(idev);
53641 + } else if (ret == 2) {
53642 + rcu_read_unlock();
53643 + in_dev_put(idev);
53648 + } endfor_ifa(idev);
53649 + rcu_read_unlock();
53650 + in_dev_put(idev);
53653 + our_addr = ip->addr;
53654 + our_netmask = ip->netmask;
53655 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53658 + else if (ret == 2)
53664 + if (mode == GR_BIND)
53665 + 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));
53666 + else if (mode == GR_CONNECT)
53667 + 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));
53673 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
53675 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
53679 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
53681 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
53684 +int gr_search_listen(struct socket *sock)
53686 + struct sock *sk = sock->sk;
53687 + struct sockaddr_in addr;
53689 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53690 + addr.sin_port = inet_sk(sk)->inet_sport;
53692 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53695 +int gr_search_accept(struct socket *sock)
53697 + struct sock *sk = sock->sk;
53698 + struct sockaddr_in addr;
53700 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53701 + addr.sin_port = inet_sk(sk)->inet_sport;
53703 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53707 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
53710 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
53712 + struct sockaddr_in sin;
53713 + const struct inet_sock *inet = inet_sk(sk);
53715 + sin.sin_addr.s_addr = inet->inet_daddr;
53716 + sin.sin_port = inet->inet_dport;
53718 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53723 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
53725 + struct sockaddr_in sin;
53727 + if (unlikely(skb->len < sizeof (struct udphdr)))
53728 + return 0; // skip this packet
53730 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
53731 + sin.sin_port = udp_hdr(skb)->source;
53733 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53735 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
53736 new file mode 100644
53737 index 0000000..25f54ef
53739 +++ b/grsecurity/gracl_learn.c
53741 +#include <linux/kernel.h>
53742 +#include <linux/mm.h>
53743 +#include <linux/sched.h>
53744 +#include <linux/poll.h>
53745 +#include <linux/string.h>
53746 +#include <linux/file.h>
53747 +#include <linux/types.h>
53748 +#include <linux/vmalloc.h>
53749 +#include <linux/grinternal.h>
53751 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
53752 + size_t count, loff_t *ppos);
53753 +extern int gr_acl_is_enabled(void);
53755 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
53756 +static int gr_learn_attached;
53758 +/* use a 512k buffer */
53759 +#define LEARN_BUFFER_SIZE (512 * 1024)
53761 +static DEFINE_SPINLOCK(gr_learn_lock);
53762 +static DEFINE_MUTEX(gr_learn_user_mutex);
53764 +/* we need to maintain two buffers, so that the kernel context of grlearn
53765 + uses a semaphore around the userspace copying, and the other kernel contexts
53766 + use a spinlock when copying into the buffer, since they cannot sleep
53768 +static char *learn_buffer;
53769 +static char *learn_buffer_user;
53770 +static int learn_buffer_len;
53771 +static int learn_buffer_user_len;
53774 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
53776 + DECLARE_WAITQUEUE(wait, current);
53777 + ssize_t retval = 0;
53779 + add_wait_queue(&learn_wait, &wait);
53780 + set_current_state(TASK_INTERRUPTIBLE);
53782 + mutex_lock(&gr_learn_user_mutex);
53783 + spin_lock(&gr_learn_lock);
53784 + if (learn_buffer_len)
53786 + spin_unlock(&gr_learn_lock);
53787 + mutex_unlock(&gr_learn_user_mutex);
53788 + if (file->f_flags & O_NONBLOCK) {
53789 + retval = -EAGAIN;
53792 + if (signal_pending(current)) {
53793 + retval = -ERESTARTSYS;
53800 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
53801 + learn_buffer_user_len = learn_buffer_len;
53802 + retval = learn_buffer_len;
53803 + learn_buffer_len = 0;
53805 + spin_unlock(&gr_learn_lock);
53807 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
53808 + retval = -EFAULT;
53810 + mutex_unlock(&gr_learn_user_mutex);
53812 + set_current_state(TASK_RUNNING);
53813 + remove_wait_queue(&learn_wait, &wait);
53817 +static unsigned int
53818 +poll_learn(struct file * file, poll_table * wait)
53820 + poll_wait(file, &learn_wait, wait);
53822 + if (learn_buffer_len)
53823 + return (POLLIN | POLLRDNORM);
53829 +gr_clear_learn_entries(void)
53833 + mutex_lock(&gr_learn_user_mutex);
53834 + spin_lock(&gr_learn_lock);
53835 + tmp = learn_buffer;
53836 + learn_buffer = NULL;
53837 + spin_unlock(&gr_learn_lock);
53840 + if (learn_buffer_user != NULL) {
53841 + vfree(learn_buffer_user);
53842 + learn_buffer_user = NULL;
53844 + learn_buffer_len = 0;
53845 + mutex_unlock(&gr_learn_user_mutex);
53851 +gr_add_learn_entry(const char *fmt, ...)
53854 + unsigned int len;
53856 + if (!gr_learn_attached)
53859 + spin_lock(&gr_learn_lock);
53861 + /* leave a gap at the end so we know when it's "full" but don't have to
53862 + compute the exact length of the string we're trying to append
53864 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
53865 + spin_unlock(&gr_learn_lock);
53866 + wake_up_interruptible(&learn_wait);
53869 + if (learn_buffer == NULL) {
53870 + spin_unlock(&gr_learn_lock);
53874 + va_start(args, fmt);
53875 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
53878 + learn_buffer_len += len + 1;
53880 + spin_unlock(&gr_learn_lock);
53881 + wake_up_interruptible(&learn_wait);
53887 +open_learn(struct inode *inode, struct file *file)
53889 + if (file->f_mode & FMODE_READ && gr_learn_attached)
53891 + if (file->f_mode & FMODE_READ) {
53893 + mutex_lock(&gr_learn_user_mutex);
53894 + if (learn_buffer == NULL)
53895 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
53896 + if (learn_buffer_user == NULL)
53897 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
53898 + if (learn_buffer == NULL) {
53899 + retval = -ENOMEM;
53902 + if (learn_buffer_user == NULL) {
53903 + retval = -ENOMEM;
53906 + learn_buffer_len = 0;
53907 + learn_buffer_user_len = 0;
53908 + gr_learn_attached = 1;
53910 + mutex_unlock(&gr_learn_user_mutex);
53917 +close_learn(struct inode *inode, struct file *file)
53919 + if (file->f_mode & FMODE_READ) {
53920 + char *tmp = NULL;
53921 + mutex_lock(&gr_learn_user_mutex);
53922 + spin_lock(&gr_learn_lock);
53923 + tmp = learn_buffer;
53924 + learn_buffer = NULL;
53925 + spin_unlock(&gr_learn_lock);
53928 + if (learn_buffer_user != NULL) {
53929 + vfree(learn_buffer_user);
53930 + learn_buffer_user = NULL;
53932 + learn_buffer_len = 0;
53933 + learn_buffer_user_len = 0;
53934 + gr_learn_attached = 0;
53935 + mutex_unlock(&gr_learn_user_mutex);
53941 +const struct file_operations grsec_fops = {
53942 + .read = read_learn,
53943 + .write = write_grsec_handler,
53944 + .open = open_learn,
53945 + .release = close_learn,
53946 + .poll = poll_learn,
53948 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
53949 new file mode 100644
53950 index 0000000..39645c9
53952 +++ b/grsecurity/gracl_res.c
53954 +#include <linux/kernel.h>
53955 +#include <linux/sched.h>
53956 +#include <linux/gracl.h>
53957 +#include <linux/grinternal.h>
53959 +static const char *restab_log[] = {
53960 + [RLIMIT_CPU] = "RLIMIT_CPU",
53961 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
53962 + [RLIMIT_DATA] = "RLIMIT_DATA",
53963 + [RLIMIT_STACK] = "RLIMIT_STACK",
53964 + [RLIMIT_CORE] = "RLIMIT_CORE",
53965 + [RLIMIT_RSS] = "RLIMIT_RSS",
53966 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
53967 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
53968 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
53969 + [RLIMIT_AS] = "RLIMIT_AS",
53970 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
53971 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
53972 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
53973 + [RLIMIT_NICE] = "RLIMIT_NICE",
53974 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
53975 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
53976 + [GR_CRASH_RES] = "RLIMIT_CRASH"
53980 +gr_log_resource(const struct task_struct *task,
53981 + const int res, const unsigned long wanted, const int gt)
53983 + const struct cred *cred;
53984 + unsigned long rlim;
53986 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
53989 + // not yet supported resource
53990 + if (unlikely(!restab_log[res]))
53993 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
53994 + rlim = task_rlimit_max(task, res);
53996 + rlim = task_rlimit(task, res);
53998 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
54002 + cred = __task_cred(task);
54004 + if (res == RLIMIT_NPROC &&
54005 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
54006 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
54007 + goto out_rcu_unlock;
54008 + else if (res == RLIMIT_MEMLOCK &&
54009 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
54010 + goto out_rcu_unlock;
54011 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
54012 + goto out_rcu_unlock;
54013 + rcu_read_unlock();
54015 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
54019 + rcu_read_unlock();
54022 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
54023 new file mode 100644
54024 index 0000000..5556be3
54026 +++ b/grsecurity/gracl_segv.c
54028 +#include <linux/kernel.h>
54029 +#include <linux/mm.h>
54030 +#include <asm/uaccess.h>
54031 +#include <asm/errno.h>
54032 +#include <asm/mman.h>
54033 +#include <net/sock.h>
54034 +#include <linux/file.h>
54035 +#include <linux/fs.h>
54036 +#include <linux/net.h>
54037 +#include <linux/in.h>
54038 +#include <linux/slab.h>
54039 +#include <linux/types.h>
54040 +#include <linux/sched.h>
54041 +#include <linux/timer.h>
54042 +#include <linux/gracl.h>
54043 +#include <linux/grsecurity.h>
54044 +#include <linux/grinternal.h>
54046 +static struct crash_uid *uid_set;
54047 +static unsigned short uid_used;
54048 +static DEFINE_SPINLOCK(gr_uid_lock);
54049 +extern rwlock_t gr_inode_lock;
54050 +extern struct acl_subject_label *
54051 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
54052 + struct acl_role_label *role);
54054 +#ifdef CONFIG_BTRFS_FS
54055 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54056 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54059 +static inline dev_t __get_dev(const struct dentry *dentry)
54061 +#ifdef CONFIG_BTRFS_FS
54062 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54063 + return get_btrfs_dev_from_inode(dentry->d_inode);
54066 + return dentry->d_inode->i_sb->s_dev;
54070 +gr_init_uidset(void)
54073 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
54076 + return uid_set ? 1 : 0;
54080 +gr_free_uidset(void)
54089 +gr_find_uid(const uid_t uid)
54091 + struct crash_uid *tmp = uid_set;
54093 + int low = 0, high = uid_used - 1, mid;
54095 + while (high >= low) {
54096 + mid = (low + high) >> 1;
54097 + buid = tmp[mid].uid;
54109 +static __inline__ void
54110 +gr_insertsort(void)
54112 + unsigned short i, j;
54113 + struct crash_uid index;
54115 + for (i = 1; i < uid_used; i++) {
54116 + index = uid_set[i];
54118 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
54119 + uid_set[j] = uid_set[j - 1];
54122 + uid_set[j] = index;
54128 +static __inline__ void
54129 +gr_insert_uid(const uid_t uid, const unsigned long expires)
54133 + if (uid_used == GR_UIDTABLE_MAX)
54136 + loc = gr_find_uid(uid);
54139 + uid_set[loc].expires = expires;
54143 + uid_set[uid_used].uid = uid;
54144 + uid_set[uid_used].expires = expires;
54153 +gr_remove_uid(const unsigned short loc)
54155 + unsigned short i;
54157 + for (i = loc + 1; i < uid_used; i++)
54158 + uid_set[i - 1] = uid_set[i];
54166 +gr_check_crash_uid(const uid_t uid)
54171 + if (unlikely(!gr_acl_is_enabled()))
54174 + spin_lock(&gr_uid_lock);
54175 + loc = gr_find_uid(uid);
54180 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
54181 + gr_remove_uid(loc);
54186 + spin_unlock(&gr_uid_lock);
54190 +static __inline__ int
54191 +proc_is_setxid(const struct cred *cred)
54193 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
54194 + cred->uid != cred->fsuid)
54196 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
54197 + cred->gid != cred->fsgid)
54203 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
54206 +gr_handle_crash(struct task_struct *task, const int sig)
54208 + struct acl_subject_label *curr;
54209 + struct task_struct *tsk, *tsk2;
54210 + const struct cred *cred;
54211 + const struct cred *cred2;
54213 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
54216 + if (unlikely(!gr_acl_is_enabled()))
54219 + curr = task->acl;
54221 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
54224 + if (time_before_eq(curr->expires, get_seconds())) {
54225 + curr->expires = 0;
54226 + curr->crashes = 0;
54231 + if (!curr->expires)
54232 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
54234 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54235 + time_after(curr->expires, get_seconds())) {
54237 + cred = __task_cred(task);
54238 + if (cred->uid && proc_is_setxid(cred)) {
54239 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
54240 + spin_lock(&gr_uid_lock);
54241 + gr_insert_uid(cred->uid, curr->expires);
54242 + spin_unlock(&gr_uid_lock);
54243 + curr->expires = 0;
54244 + curr->crashes = 0;
54245 + read_lock(&tasklist_lock);
54246 + do_each_thread(tsk2, tsk) {
54247 + cred2 = __task_cred(tsk);
54248 + if (tsk != task && cred2->uid == cred->uid)
54249 + gr_fake_force_sig(SIGKILL, tsk);
54250 + } while_each_thread(tsk2, tsk);
54251 + read_unlock(&tasklist_lock);
54253 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
54254 + read_lock(&tasklist_lock);
54255 + read_lock(&grsec_exec_file_lock);
54256 + do_each_thread(tsk2, tsk) {
54257 + if (likely(tsk != task)) {
54258 + // if this thread has the same subject as the one that triggered
54259 + // RES_CRASH and it's the same binary, kill it
54260 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
54261 + gr_fake_force_sig(SIGKILL, tsk);
54263 + } while_each_thread(tsk2, tsk);
54264 + read_unlock(&grsec_exec_file_lock);
54265 + read_unlock(&tasklist_lock);
54267 + rcu_read_unlock();
54274 +gr_check_crash_exec(const struct file *filp)
54276 + struct acl_subject_label *curr;
54278 + if (unlikely(!gr_acl_is_enabled()))
54281 + read_lock(&gr_inode_lock);
54282 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
54283 + __get_dev(filp->f_path.dentry),
54285 + read_unlock(&gr_inode_lock);
54287 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
54288 + (!curr->crashes && !curr->expires))
54291 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54292 + time_after(curr->expires, get_seconds()))
54294 + else if (time_before_eq(curr->expires, get_seconds())) {
54295 + curr->crashes = 0;
54296 + curr->expires = 0;
54303 +gr_handle_alertkill(struct task_struct *task)
54305 + struct acl_subject_label *curracl;
54307 + struct task_struct *p, *p2;
54309 + if (unlikely(!gr_acl_is_enabled()))
54312 + curracl = task->acl;
54313 + curr_ip = task->signal->curr_ip;
54315 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
54316 + read_lock(&tasklist_lock);
54317 + do_each_thread(p2, p) {
54318 + if (p->signal->curr_ip == curr_ip)
54319 + gr_fake_force_sig(SIGKILL, p);
54320 + } while_each_thread(p2, p);
54321 + read_unlock(&tasklist_lock);
54322 + } else if (curracl->mode & GR_KILLPROC)
54323 + gr_fake_force_sig(SIGKILL, task);
54327 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
54328 new file mode 100644
54329 index 0000000..9d83a69
54331 +++ b/grsecurity/gracl_shm.c
54333 +#include <linux/kernel.h>
54334 +#include <linux/mm.h>
54335 +#include <linux/sched.h>
54336 +#include <linux/file.h>
54337 +#include <linux/ipc.h>
54338 +#include <linux/gracl.h>
54339 +#include <linux/grsecurity.h>
54340 +#include <linux/grinternal.h>
54343 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54344 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54346 + struct task_struct *task;
54348 + if (!gr_acl_is_enabled())
54352 + read_lock(&tasklist_lock);
54354 + task = find_task_by_vpid(shm_cprid);
54356 + if (unlikely(!task))
54357 + task = find_task_by_vpid(shm_lapid);
54359 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
54360 + (task->pid == shm_lapid)) &&
54361 + (task->acl->mode & GR_PROTSHM) &&
54362 + (task->acl != current->acl))) {
54363 + read_unlock(&tasklist_lock);
54364 + rcu_read_unlock();
54365 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
54368 + read_unlock(&tasklist_lock);
54369 + rcu_read_unlock();
54373 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
54374 new file mode 100644
54375 index 0000000..bc0be01
54377 +++ b/grsecurity/grsec_chdir.c
54379 +#include <linux/kernel.h>
54380 +#include <linux/sched.h>
54381 +#include <linux/fs.h>
54382 +#include <linux/file.h>
54383 +#include <linux/grsecurity.h>
54384 +#include <linux/grinternal.h>
54387 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
54389 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
54390 + if ((grsec_enable_chdir && grsec_enable_group &&
54391 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
54392 + !grsec_enable_group)) {
54393 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
54398 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
54399 new file mode 100644
54400 index 0000000..a2dc675
54402 +++ b/grsecurity/grsec_chroot.c
54404 +#include <linux/kernel.h>
54405 +#include <linux/module.h>
54406 +#include <linux/sched.h>
54407 +#include <linux/file.h>
54408 +#include <linux/fs.h>
54409 +#include <linux/mount.h>
54410 +#include <linux/types.h>
54411 +#include <linux/pid_namespace.h>
54412 +#include <linux/grsecurity.h>
54413 +#include <linux/grinternal.h>
54415 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
54417 +#ifdef CONFIG_GRKERNSEC
54418 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
54419 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
54420 + task->gr_is_chrooted = 1;
54422 + task->gr_is_chrooted = 0;
54424 + task->gr_chroot_dentry = path->dentry;
54429 +void gr_clear_chroot_entries(struct task_struct *task)
54431 +#ifdef CONFIG_GRKERNSEC
54432 + task->gr_is_chrooted = 0;
54433 + task->gr_chroot_dentry = NULL;
54439 +gr_handle_chroot_unix(const pid_t pid)
54441 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
54442 + struct task_struct *p;
54444 + if (unlikely(!grsec_enable_chroot_unix))
54447 + if (likely(!proc_is_chrooted(current)))
54451 + read_lock(&tasklist_lock);
54452 + p = find_task_by_vpid_unrestricted(pid);
54453 + if (unlikely(p && !have_same_root(current, p))) {
54454 + read_unlock(&tasklist_lock);
54455 + rcu_read_unlock();
54456 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
54459 + read_unlock(&tasklist_lock);
54460 + rcu_read_unlock();
54466 +gr_handle_chroot_nice(void)
54468 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54469 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
54470 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
54478 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
54480 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54481 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
54482 + && proc_is_chrooted(current)) {
54483 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
54491 +gr_handle_chroot_rawio(const struct inode *inode)
54493 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54494 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54495 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
54502 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
54504 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54505 + struct task_struct *p;
54507 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
54510 + read_lock(&tasklist_lock);
54511 + do_each_pid_task(pid, type, p) {
54512 + if (!have_same_root(current, p)) {
54516 + } while_each_pid_task(pid, type, p);
54518 + read_unlock(&tasklist_lock);
54525 +gr_pid_is_chrooted(struct task_struct *p)
54527 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54528 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
54531 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
54532 + !have_same_root(current, p)) {
54539 +EXPORT_SYMBOL(gr_pid_is_chrooted);
54541 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
54542 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
54544 + struct path path, currentroot;
54547 + path.dentry = (struct dentry *)u_dentry;
54548 + path.mnt = (struct vfsmount *)u_mnt;
54549 + get_fs_root(current->fs, ¤troot);
54550 + if (path_is_under(&path, ¤troot))
54552 + path_put(¤troot);
54559 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
54561 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
54562 + if (!grsec_enable_chroot_fchdir)
54565 + if (!proc_is_chrooted(current))
54567 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
54568 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
54576 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54577 + const time_t shm_createtime)
54579 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
54580 + struct task_struct *p;
54581 + time_t starttime;
54583 + if (unlikely(!grsec_enable_chroot_shmat))
54586 + if (likely(!proc_is_chrooted(current)))
54590 + read_lock(&tasklist_lock);
54592 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
54593 + starttime = p->start_time.tv_sec;
54594 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
54595 + if (have_same_root(current, p)) {
54598 + read_unlock(&tasklist_lock);
54599 + rcu_read_unlock();
54600 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54604 + /* creator exited, pid reuse, fall through to next check */
54606 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
54607 + if (unlikely(!have_same_root(current, p))) {
54608 + read_unlock(&tasklist_lock);
54609 + rcu_read_unlock();
54610 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54616 + read_unlock(&tasklist_lock);
54617 + rcu_read_unlock();
54623 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
54625 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
54626 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
54627 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
54633 +gr_handle_chroot_mknod(const struct dentry *dentry,
54634 + const struct vfsmount *mnt, const int mode)
54636 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
54637 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
54638 + proc_is_chrooted(current)) {
54639 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
54647 +gr_handle_chroot_mount(const struct dentry *dentry,
54648 + const struct vfsmount *mnt, const char *dev_name)
54650 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
54651 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
54652 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
54660 +gr_handle_chroot_pivot(void)
54662 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
54663 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
54664 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
54672 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
54674 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
54675 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
54676 + !gr_is_outside_chroot(dentry, mnt)) {
54677 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
54684 +extern const char *captab_log[];
54685 +extern int captab_log_entries;
54688 +gr_chroot_is_capable(const int cap)
54690 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54691 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54692 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54693 + if (cap_raised(chroot_caps, cap)) {
54694 + const struct cred *creds = current_cred();
54695 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
54696 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
54706 +gr_chroot_is_capable_nolog(const int cap)
54708 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54709 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54710 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54711 + if (cap_raised(chroot_caps, cap)) {
54720 +gr_handle_chroot_sysctl(const int op)
54722 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
54723 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
54724 + proc_is_chrooted(current))
54731 +gr_handle_chroot_chdir(struct path *path)
54733 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
54734 + if (grsec_enable_chroot_chdir)
54735 + set_fs_pwd(current->fs, path);
54741 +gr_handle_chroot_chmod(const struct dentry *dentry,
54742 + const struct vfsmount *mnt, const int mode)
54744 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
54745 + /* allow chmod +s on directories, but not files */
54746 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
54747 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
54748 + proc_is_chrooted(current)) {
54749 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
54755 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
54756 new file mode 100644
54757 index 0000000..213ad8b
54759 +++ b/grsecurity/grsec_disabled.c
54761 +#include <linux/kernel.h>
54762 +#include <linux/module.h>
54763 +#include <linux/sched.h>
54764 +#include <linux/file.h>
54765 +#include <linux/fs.h>
54766 +#include <linux/kdev_t.h>
54767 +#include <linux/net.h>
54768 +#include <linux/in.h>
54769 +#include <linux/ip.h>
54770 +#include <linux/skbuff.h>
54771 +#include <linux/sysctl.h>
54773 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54775 +pax_set_initial_flags(struct linux_binprm *bprm)
54781 +#ifdef CONFIG_SYSCTL
54783 +gr_handle_sysctl(const struct ctl_table * table, const int op)
54789 +#ifdef CONFIG_TASKSTATS
54790 +int gr_is_taskstats_denied(int pid)
54797 +gr_acl_is_enabled(void)
54803 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54809 +gr_handle_rawio(const struct inode *inode)
54815 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54821 +gr_handle_ptrace(struct task_struct *task, const long request)
54827 +gr_handle_proc_ptrace(struct task_struct *task)
54833 +gr_learn_resource(const struct task_struct *task,
54834 + const int res, const unsigned long wanted, const int gt)
54840 +gr_set_acls(const int type)
54846 +gr_check_hidden_task(const struct task_struct *tsk)
54852 +gr_check_protected_task(const struct task_struct *task)
54858 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54864 +gr_copy_label(struct task_struct *tsk)
54870 +gr_set_pax_flags(struct task_struct *task)
54876 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54877 + const int unsafe_share)
54883 +gr_handle_delete(const ino_t ino, const dev_t dev)
54889 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54895 +gr_handle_crash(struct task_struct *task, const int sig)
54901 +gr_check_crash_exec(const struct file *filp)
54907 +gr_check_crash_uid(const uid_t uid)
54913 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54914 + struct dentry *old_dentry,
54915 + struct dentry *new_dentry,
54916 + struct vfsmount *mnt, const __u8 replace)
54922 +gr_search_socket(const int family, const int type, const int protocol)
54928 +gr_search_connectbind(const int mode, const struct socket *sock,
54929 + const struct sockaddr_in *addr)
54935 +gr_handle_alertkill(struct task_struct *task)
54941 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
54947 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54948 + const struct vfsmount * mnt)
54954 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54961 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54967 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
54973 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
54974 + unsigned int *vm_flags)
54980 +gr_acl_handle_truncate(const struct dentry * dentry,
54981 + const struct vfsmount * mnt)
54987 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
54993 +gr_acl_handle_access(const struct dentry * dentry,
54994 + const struct vfsmount * mnt, const int fmode)
55000 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
55007 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
55013 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
55019 +grsecurity_init(void)
55024 +umode_t gr_acl_umask(void)
55030 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55031 + const struct dentry * parent_dentry,
55032 + const struct vfsmount * parent_mnt,
55039 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
55040 + const struct dentry * parent_dentry,
55041 + const struct vfsmount * parent_mnt)
55047 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55048 + const struct dentry * parent_dentry,
55049 + const struct vfsmount * parent_mnt, const char *from)
55055 +gr_acl_handle_link(const struct dentry * new_dentry,
55056 + const struct dentry * parent_dentry,
55057 + const struct vfsmount * parent_mnt,
55058 + const struct dentry * old_dentry,
55059 + const struct vfsmount * old_mnt, const char *to)
55065 +gr_acl_handle_rename(const struct dentry *new_dentry,
55066 + const struct dentry *parent_dentry,
55067 + const struct vfsmount *parent_mnt,
55068 + const struct dentry *old_dentry,
55069 + const struct inode *old_parent_inode,
55070 + const struct vfsmount *old_mnt, const char *newname)
55076 +gr_acl_handle_filldir(const struct file *file, const char *name,
55077 + const int namelen, const ino_t ino)
55083 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55084 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55090 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
55096 +gr_search_accept(const struct socket *sock)
55102 +gr_search_listen(const struct socket *sock)
55108 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
55114 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
55120 +gr_acl_handle_creat(const struct dentry * dentry,
55121 + const struct dentry * p_dentry,
55122 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55129 +gr_acl_handle_exit(void)
55135 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55141 +gr_set_role_label(const uid_t uid, const gid_t gid)
55147 +gr_acl_handle_procpidmem(const struct task_struct *task)
55153 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
55159 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
55165 +gr_set_kernel_label(struct task_struct *task)
55171 +gr_check_user_change(int real, int effective, int fs)
55177 +gr_check_group_change(int real, int effective, int fs)
55182 +int gr_acl_enable_at_secure(void)
55187 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55189 + return dentry->d_inode->i_sb->s_dev;
55192 +EXPORT_SYMBOL(gr_learn_resource);
55193 +EXPORT_SYMBOL(gr_set_kernel_label);
55194 +#ifdef CONFIG_SECURITY
55195 +EXPORT_SYMBOL(gr_check_user_change);
55196 +EXPORT_SYMBOL(gr_check_group_change);
55198 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
55199 new file mode 100644
55200 index 0000000..2b05ada
55202 +++ b/grsecurity/grsec_exec.c
55204 +#include <linux/kernel.h>
55205 +#include <linux/sched.h>
55206 +#include <linux/file.h>
55207 +#include <linux/binfmts.h>
55208 +#include <linux/fs.h>
55209 +#include <linux/types.h>
55210 +#include <linux/grdefs.h>
55211 +#include <linux/grsecurity.h>
55212 +#include <linux/grinternal.h>
55213 +#include <linux/capability.h>
55214 +#include <linux/module.h>
55216 +#include <asm/uaccess.h>
55218 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55219 +static char gr_exec_arg_buf[132];
55220 +static DEFINE_MUTEX(gr_exec_arg_mutex);
55223 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
55226 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
55228 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55229 + char *grarg = gr_exec_arg_buf;
55230 + unsigned int i, x, execlen = 0;
55233 + if (!((grsec_enable_execlog && grsec_enable_group &&
55234 + in_group_p(grsec_audit_gid))
55235 + || (grsec_enable_execlog && !grsec_enable_group)))
55238 + mutex_lock(&gr_exec_arg_mutex);
55239 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
55241 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
55242 + const char __user *p;
55243 + unsigned int len;
55245 + p = get_user_arg_ptr(argv, i);
55249 + len = strnlen_user(p, 128 - execlen);
55250 + if (len > 128 - execlen)
55251 + len = 128 - execlen;
55252 + else if (len > 0)
55254 + if (copy_from_user(grarg + execlen, p, len))
55257 + /* rewrite unprintable characters */
55258 + for (x = 0; x < len; x++) {
55259 + c = *(grarg + execlen + x);
55260 + if (c < 32 || c > 126)
55261 + *(grarg + execlen + x) = ' ';
55265 + *(grarg + execlen) = ' ';
55266 + *(grarg + execlen + 1) = '\0';
55271 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
55272 + bprm->file->f_path.mnt, grarg);
55273 + mutex_unlock(&gr_exec_arg_mutex);
55278 +#ifdef CONFIG_GRKERNSEC
55279 +extern int gr_acl_is_capable(const int cap);
55280 +extern int gr_acl_is_capable_nolog(const int cap);
55281 +extern int gr_chroot_is_capable(const int cap);
55282 +extern int gr_chroot_is_capable_nolog(const int cap);
55285 +const char *captab_log[] = {
55287 + "CAP_DAC_OVERRIDE",
55288 + "CAP_DAC_READ_SEARCH",
55295 + "CAP_LINUX_IMMUTABLE",
55296 + "CAP_NET_BIND_SERVICE",
55297 + "CAP_NET_BROADCAST",
55302 + "CAP_SYS_MODULE",
55304 + "CAP_SYS_CHROOT",
55305 + "CAP_SYS_PTRACE",
55310 + "CAP_SYS_RESOURCE",
55312 + "CAP_SYS_TTY_CONFIG",
55315 + "CAP_AUDIT_WRITE",
55316 + "CAP_AUDIT_CONTROL",
55318 + "CAP_MAC_OVERRIDE",
55324 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
55326 +int gr_is_capable(const int cap)
55328 +#ifdef CONFIG_GRKERNSEC
55329 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
55337 +int gr_is_capable_nolog(const int cap)
55339 +#ifdef CONFIG_GRKERNSEC
55340 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
55348 +EXPORT_SYMBOL(gr_is_capable);
55349 +EXPORT_SYMBOL(gr_is_capable_nolog);
55350 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
55351 new file mode 100644
55352 index 0000000..d3ee748
55354 +++ b/grsecurity/grsec_fifo.c
55356 +#include <linux/kernel.h>
55357 +#include <linux/sched.h>
55358 +#include <linux/fs.h>
55359 +#include <linux/file.h>
55360 +#include <linux/grinternal.h>
55363 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
55364 + const struct dentry *dir, const int flag, const int acc_mode)
55366 +#ifdef CONFIG_GRKERNSEC_FIFO
55367 + const struct cred *cred = current_cred();
55369 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
55370 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
55371 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
55372 + (cred->fsuid != dentry->d_inode->i_uid)) {
55373 + if (!inode_permission(dentry->d_inode, acc_mode))
55374 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
55380 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
55381 new file mode 100644
55382 index 0000000..8ca18bf
55384 +++ b/grsecurity/grsec_fork.c
55386 +#include <linux/kernel.h>
55387 +#include <linux/sched.h>
55388 +#include <linux/grsecurity.h>
55389 +#include <linux/grinternal.h>
55390 +#include <linux/errno.h>
55393 +gr_log_forkfail(const int retval)
55395 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55396 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
55397 + switch (retval) {
55399 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
55402 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
55409 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
55410 new file mode 100644
55411 index 0000000..01ddde4
55413 +++ b/grsecurity/grsec_init.c
55415 +#include <linux/kernel.h>
55416 +#include <linux/sched.h>
55417 +#include <linux/mm.h>
55418 +#include <linux/gracl.h>
55419 +#include <linux/slab.h>
55420 +#include <linux/vmalloc.h>
55421 +#include <linux/percpu.h>
55422 +#include <linux/module.h>
55424 +int grsec_enable_ptrace_readexec;
55425 +int grsec_enable_setxid;
55426 +int grsec_enable_brute;
55427 +int grsec_enable_link;
55428 +int grsec_enable_dmesg;
55429 +int grsec_enable_harden_ptrace;
55430 +int grsec_enable_fifo;
55431 +int grsec_enable_execlog;
55432 +int grsec_enable_signal;
55433 +int grsec_enable_forkfail;
55434 +int grsec_enable_audit_ptrace;
55435 +int grsec_enable_time;
55436 +int grsec_enable_audit_textrel;
55437 +int grsec_enable_group;
55438 +int grsec_audit_gid;
55439 +int grsec_enable_chdir;
55440 +int grsec_enable_mount;
55441 +int grsec_enable_rofs;
55442 +int grsec_enable_chroot_findtask;
55443 +int grsec_enable_chroot_mount;
55444 +int grsec_enable_chroot_shmat;
55445 +int grsec_enable_chroot_fchdir;
55446 +int grsec_enable_chroot_double;
55447 +int grsec_enable_chroot_pivot;
55448 +int grsec_enable_chroot_chdir;
55449 +int grsec_enable_chroot_chmod;
55450 +int grsec_enable_chroot_mknod;
55451 +int grsec_enable_chroot_nice;
55452 +int grsec_enable_chroot_execlog;
55453 +int grsec_enable_chroot_caps;
55454 +int grsec_enable_chroot_sysctl;
55455 +int grsec_enable_chroot_unix;
55456 +int grsec_enable_tpe;
55457 +int grsec_tpe_gid;
55458 +int grsec_enable_blackhole;
55459 +#ifdef CONFIG_IPV6_MODULE
55460 +EXPORT_SYMBOL(grsec_enable_blackhole);
55462 +int grsec_lastack_retries;
55463 +int grsec_enable_tpe_all;
55464 +int grsec_enable_tpe_invert;
55465 +int grsec_enable_socket_all;
55466 +int grsec_socket_all_gid;
55467 +int grsec_enable_socket_client;
55468 +int grsec_socket_client_gid;
55469 +int grsec_enable_socket_server;
55470 +int grsec_socket_server_gid;
55471 +int grsec_resource_logging;
55472 +int grsec_disable_privio;
55473 +int grsec_enable_log_rwxmaps;
55476 +DEFINE_SPINLOCK(grsec_alert_lock);
55477 +unsigned long grsec_alert_wtime = 0;
55478 +unsigned long grsec_alert_fyet = 0;
55480 +DEFINE_SPINLOCK(grsec_audit_lock);
55482 +DEFINE_RWLOCK(grsec_exec_file_lock);
55484 +char *gr_shared_page[4];
55486 +char *gr_alert_log_fmt;
55487 +char *gr_audit_log_fmt;
55488 +char *gr_alert_log_buf;
55489 +char *gr_audit_log_buf;
55491 +extern struct gr_arg *gr_usermode;
55492 +extern unsigned char *gr_system_salt;
55493 +extern unsigned char *gr_system_sum;
55496 +grsecurity_init(void)
55499 + /* create the per-cpu shared pages */
55502 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
55505 + for (j = 0; j < 4; j++) {
55506 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
55507 + if (gr_shared_page[j] == NULL) {
55508 + panic("Unable to allocate grsecurity shared page");
55513 + /* allocate log buffers */
55514 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
55515 + if (!gr_alert_log_fmt) {
55516 + panic("Unable to allocate grsecurity alert log format buffer");
55519 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
55520 + if (!gr_audit_log_fmt) {
55521 + panic("Unable to allocate grsecurity audit log format buffer");
55524 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55525 + if (!gr_alert_log_buf) {
55526 + panic("Unable to allocate grsecurity alert log buffer");
55529 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55530 + if (!gr_audit_log_buf) {
55531 + panic("Unable to allocate grsecurity audit log buffer");
55535 + /* allocate memory for authentication structure */
55536 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
55537 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
55538 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
55540 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
55541 + panic("Unable to allocate grsecurity authentication structure");
55546 +#ifdef CONFIG_GRKERNSEC_IO
55547 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
55548 + grsec_disable_privio = 1;
55549 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55550 + grsec_disable_privio = 1;
55552 + grsec_disable_privio = 0;
55556 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55557 + /* for backward compatibility, tpe_invert always defaults to on if
55558 + enabled in the kernel
55560 + grsec_enable_tpe_invert = 1;
55563 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55564 +#ifndef CONFIG_GRKERNSEC_SYSCTL
55568 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55569 + grsec_enable_audit_textrel = 1;
55571 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55572 + grsec_enable_log_rwxmaps = 1;
55574 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
55575 + grsec_enable_group = 1;
55576 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
55578 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
55579 + grsec_enable_ptrace_readexec = 1;
55581 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55582 + grsec_enable_chdir = 1;
55584 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55585 + grsec_enable_harden_ptrace = 1;
55587 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55588 + grsec_enable_mount = 1;
55590 +#ifdef CONFIG_GRKERNSEC_LINK
55591 + grsec_enable_link = 1;
55593 +#ifdef CONFIG_GRKERNSEC_BRUTE
55594 + grsec_enable_brute = 1;
55596 +#ifdef CONFIG_GRKERNSEC_DMESG
55597 + grsec_enable_dmesg = 1;
55599 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55600 + grsec_enable_blackhole = 1;
55601 + grsec_lastack_retries = 4;
55603 +#ifdef CONFIG_GRKERNSEC_FIFO
55604 + grsec_enable_fifo = 1;
55606 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55607 + grsec_enable_execlog = 1;
55609 +#ifdef CONFIG_GRKERNSEC_SETXID
55610 + grsec_enable_setxid = 1;
55612 +#ifdef CONFIG_GRKERNSEC_SIGNAL
55613 + grsec_enable_signal = 1;
55615 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55616 + grsec_enable_forkfail = 1;
55618 +#ifdef CONFIG_GRKERNSEC_TIME
55619 + grsec_enable_time = 1;
55621 +#ifdef CONFIG_GRKERNSEC_RESLOG
55622 + grsec_resource_logging = 1;
55624 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55625 + grsec_enable_chroot_findtask = 1;
55627 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55628 + grsec_enable_chroot_unix = 1;
55630 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55631 + grsec_enable_chroot_mount = 1;
55633 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55634 + grsec_enable_chroot_fchdir = 1;
55636 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55637 + grsec_enable_chroot_shmat = 1;
55639 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55640 + grsec_enable_audit_ptrace = 1;
55642 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55643 + grsec_enable_chroot_double = 1;
55645 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55646 + grsec_enable_chroot_pivot = 1;
55648 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55649 + grsec_enable_chroot_chdir = 1;
55651 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55652 + grsec_enable_chroot_chmod = 1;
55654 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55655 + grsec_enable_chroot_mknod = 1;
55657 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55658 + grsec_enable_chroot_nice = 1;
55660 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55661 + grsec_enable_chroot_execlog = 1;
55663 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55664 + grsec_enable_chroot_caps = 1;
55666 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55667 + grsec_enable_chroot_sysctl = 1;
55669 +#ifdef CONFIG_GRKERNSEC_TPE
55670 + grsec_enable_tpe = 1;
55671 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
55672 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
55673 + grsec_enable_tpe_all = 1;
55676 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55677 + grsec_enable_socket_all = 1;
55678 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
55680 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55681 + grsec_enable_socket_client = 1;
55682 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
55684 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55685 + grsec_enable_socket_server = 1;
55686 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
55692 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
55693 new file mode 100644
55694 index 0000000..3efe141
55696 +++ b/grsecurity/grsec_link.c
55698 +#include <linux/kernel.h>
55699 +#include <linux/sched.h>
55700 +#include <linux/fs.h>
55701 +#include <linux/file.h>
55702 +#include <linux/grinternal.h>
55705 +gr_handle_follow_link(const struct inode *parent,
55706 + const struct inode *inode,
55707 + const struct dentry *dentry, const struct vfsmount *mnt)
55709 +#ifdef CONFIG_GRKERNSEC_LINK
55710 + const struct cred *cred = current_cred();
55712 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
55713 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
55714 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
55715 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
55723 +gr_handle_hardlink(const struct dentry *dentry,
55724 + const struct vfsmount *mnt,
55725 + struct inode *inode, const int mode, const char *to)
55727 +#ifdef CONFIG_GRKERNSEC_LINK
55728 + const struct cred *cred = current_cred();
55730 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
55731 + (!S_ISREG(mode) || (mode & S_ISUID) ||
55732 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
55733 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
55734 + !capable(CAP_FOWNER) && cred->uid) {
55735 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
55741 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
55742 new file mode 100644
55743 index 0000000..a45d2e9
55745 +++ b/grsecurity/grsec_log.c
55747 +#include <linux/kernel.h>
55748 +#include <linux/sched.h>
55749 +#include <linux/file.h>
55750 +#include <linux/tty.h>
55751 +#include <linux/fs.h>
55752 +#include <linux/grinternal.h>
55754 +#ifdef CONFIG_TREE_PREEMPT_RCU
55755 +#define DISABLE_PREEMPT() preempt_disable()
55756 +#define ENABLE_PREEMPT() preempt_enable()
55758 +#define DISABLE_PREEMPT()
55759 +#define ENABLE_PREEMPT()
55762 +#define BEGIN_LOCKS(x) \
55763 + DISABLE_PREEMPT(); \
55764 + rcu_read_lock(); \
55765 + read_lock(&tasklist_lock); \
55766 + read_lock(&grsec_exec_file_lock); \
55767 + if (x != GR_DO_AUDIT) \
55768 + spin_lock(&grsec_alert_lock); \
55770 + spin_lock(&grsec_audit_lock)
55772 +#define END_LOCKS(x) \
55773 + if (x != GR_DO_AUDIT) \
55774 + spin_unlock(&grsec_alert_lock); \
55776 + spin_unlock(&grsec_audit_lock); \
55777 + read_unlock(&grsec_exec_file_lock); \
55778 + read_unlock(&tasklist_lock); \
55779 + rcu_read_unlock(); \
55780 + ENABLE_PREEMPT(); \
55781 + if (x == GR_DONT_AUDIT) \
55782 + gr_handle_alertkill(current)
55789 +extern char *gr_alert_log_fmt;
55790 +extern char *gr_audit_log_fmt;
55791 +extern char *gr_alert_log_buf;
55792 +extern char *gr_audit_log_buf;
55794 +static int gr_log_start(int audit)
55796 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
55797 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
55798 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55799 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
55800 + unsigned long curr_secs = get_seconds();
55802 + if (audit == GR_DO_AUDIT)
55805 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
55806 + grsec_alert_wtime = curr_secs;
55807 + grsec_alert_fyet = 0;
55808 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
55809 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
55810 + grsec_alert_fyet++;
55811 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
55812 + grsec_alert_wtime = curr_secs;
55813 + grsec_alert_fyet++;
55814 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
55817 + else return FLOODING;
55821 + memset(buf, 0, PAGE_SIZE);
55822 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
55823 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
55824 + snprintf(buf, PAGE_SIZE - 1, fmt, ¤t->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55825 + } else if (current->signal->curr_ip) {
55826 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
55827 + snprintf(buf, PAGE_SIZE - 1, fmt, ¤t->signal->curr_ip);
55828 + } else if (gr_acl_is_enabled()) {
55829 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
55830 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55832 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
55833 + strcpy(buf, fmt);
55836 + return NO_FLOODING;
55839 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55840 + __attribute__ ((format (printf, 2, 0)));
55842 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55844 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55845 + unsigned int len = strlen(buf);
55847 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55852 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55853 + __attribute__ ((format (printf, 2, 3)));
55855 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55857 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55858 + unsigned int len = strlen(buf);
55861 + va_start(ap, msg);
55862 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55868 +static void gr_log_end(int audit, int append_default)
55870 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55872 + if (append_default) {
55873 + unsigned int len = strlen(buf);
55874 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
55877 + printk("%s\n", buf);
55882 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
55885 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
55886 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
55887 + void *voidptr = NULL;
55888 + int num1 = 0, num2 = 0;
55889 + unsigned long ulong1 = 0, ulong2 = 0;
55890 + struct dentry *dentry = NULL;
55891 + struct vfsmount *mnt = NULL;
55892 + struct file *file = NULL;
55893 + struct task_struct *task = NULL;
55894 + const struct cred *cred, *pcred;
55897 + BEGIN_LOCKS(audit);
55898 + logtype = gr_log_start(audit);
55899 + if (logtype == FLOODING) {
55900 + END_LOCKS(audit);
55903 + va_start(ap, argtypes);
55904 + switch (argtypes) {
55905 + case GR_TTYSNIFF:
55906 + task = va_arg(ap, struct task_struct *);
55907 + 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);
55909 + case GR_SYSCTL_HIDDEN:
55910 + str1 = va_arg(ap, char *);
55911 + gr_log_middle_varargs(audit, msg, result, str1);
55914 + dentry = va_arg(ap, struct dentry *);
55915 + mnt = va_arg(ap, struct vfsmount *);
55916 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
55918 + case GR_RBAC_STR:
55919 + dentry = va_arg(ap, struct dentry *);
55920 + mnt = va_arg(ap, struct vfsmount *);
55921 + str1 = va_arg(ap, char *);
55922 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
55924 + case GR_STR_RBAC:
55925 + str1 = va_arg(ap, char *);
55926 + dentry = va_arg(ap, struct dentry *);
55927 + mnt = va_arg(ap, struct vfsmount *);
55928 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
55930 + case GR_RBAC_MODE2:
55931 + dentry = va_arg(ap, struct dentry *);
55932 + mnt = va_arg(ap, struct vfsmount *);
55933 + str1 = va_arg(ap, char *);
55934 + str2 = va_arg(ap, char *);
55935 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
55937 + case GR_RBAC_MODE3:
55938 + dentry = va_arg(ap, struct dentry *);
55939 + mnt = va_arg(ap, struct vfsmount *);
55940 + str1 = va_arg(ap, char *);
55941 + str2 = va_arg(ap, char *);
55942 + str3 = va_arg(ap, char *);
55943 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
55945 + case GR_FILENAME:
55946 + dentry = va_arg(ap, struct dentry *);
55947 + mnt = va_arg(ap, struct vfsmount *);
55948 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
55950 + case GR_STR_FILENAME:
55951 + str1 = va_arg(ap, char *);
55952 + dentry = va_arg(ap, struct dentry *);
55953 + mnt = va_arg(ap, struct vfsmount *);
55954 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
55956 + case GR_FILENAME_STR:
55957 + dentry = va_arg(ap, struct dentry *);
55958 + mnt = va_arg(ap, struct vfsmount *);
55959 + str1 = va_arg(ap, char *);
55960 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
55962 + case GR_FILENAME_TWO_INT:
55963 + dentry = va_arg(ap, struct dentry *);
55964 + mnt = va_arg(ap, struct vfsmount *);
55965 + num1 = va_arg(ap, int);
55966 + num2 = va_arg(ap, int);
55967 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
55969 + case GR_FILENAME_TWO_INT_STR:
55970 + dentry = va_arg(ap, struct dentry *);
55971 + mnt = va_arg(ap, struct vfsmount *);
55972 + num1 = va_arg(ap, int);
55973 + num2 = va_arg(ap, int);
55974 + str1 = va_arg(ap, char *);
55975 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
55978 + file = va_arg(ap, struct file *);
55979 + ulong1 = va_arg(ap, unsigned long);
55980 + ulong2 = va_arg(ap, unsigned long);
55981 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
55984 + task = va_arg(ap, struct task_struct *);
55985 + 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);
55987 + case GR_RESOURCE:
55988 + task = va_arg(ap, struct task_struct *);
55989 + cred = __task_cred(task);
55990 + pcred = __task_cred(task->real_parent);
55991 + ulong1 = va_arg(ap, unsigned long);
55992 + str1 = va_arg(ap, char *);
55993 + ulong2 = va_arg(ap, unsigned long);
55994 + 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);
55997 + task = va_arg(ap, struct task_struct *);
55998 + cred = __task_cred(task);
55999 + pcred = __task_cred(task->real_parent);
56000 + str1 = va_arg(ap, char *);
56001 + 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);
56004 + str1 = va_arg(ap, char *);
56005 + voidptr = va_arg(ap, void *);
56006 + gr_log_middle_varargs(audit, msg, str1, voidptr);
56009 + task = va_arg(ap, struct task_struct *);
56010 + cred = __task_cred(task);
56011 + pcred = __task_cred(task->real_parent);
56012 + num1 = va_arg(ap, int);
56013 + 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);
56016 + task = va_arg(ap, struct task_struct *);
56017 + cred = __task_cred(task);
56018 + pcred = __task_cred(task->real_parent);
56019 + ulong1 = va_arg(ap, unsigned long);
56020 + 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);
56023 + task = va_arg(ap, struct task_struct *);
56024 + cred = __task_cred(task);
56025 + pcred = __task_cred(task->real_parent);
56026 + ulong1 = va_arg(ap, unsigned long);
56027 + 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);
56030 + file = va_arg(ap, struct file *);
56031 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
56035 + unsigned int wday, cday;
56039 + char cur_tty[64] = { 0 };
56040 + char parent_tty[64] = { 0 };
56042 + task = va_arg(ap, struct task_struct *);
56043 + wday = va_arg(ap, unsigned int);
56044 + cday = va_arg(ap, unsigned int);
56045 + whr = va_arg(ap, int);
56046 + chr = va_arg(ap, int);
56047 + wmin = va_arg(ap, int);
56048 + cmin = va_arg(ap, int);
56049 + wsec = va_arg(ap, int);
56050 + csec = va_arg(ap, int);
56051 + ulong1 = va_arg(ap, unsigned long);
56052 + cred = __task_cred(task);
56053 + pcred = __task_cred(task->real_parent);
56055 + 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);
56059 + gr_log_middle(audit, msg, ap);
56062 + // these don't need DEFAULTSECARGS printed on the end
56063 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
56064 + gr_log_end(audit, 0);
56066 + gr_log_end(audit, 1);
56067 + END_LOCKS(audit);
56069 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
56070 new file mode 100644
56071 index 0000000..f536303
56073 +++ b/grsecurity/grsec_mem.c
56075 +#include <linux/kernel.h>
56076 +#include <linux/sched.h>
56077 +#include <linux/mm.h>
56078 +#include <linux/mman.h>
56079 +#include <linux/grinternal.h>
56082 +gr_handle_ioperm(void)
56084 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
56089 +gr_handle_iopl(void)
56091 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
56096 +gr_handle_mem_readwrite(u64 from, u64 to)
56098 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
56103 +gr_handle_vm86(void)
56105 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
56110 +gr_log_badprocpid(const char *entry)
56112 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
56115 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
56116 new file mode 100644
56117 index 0000000..2131422
56119 +++ b/grsecurity/grsec_mount.c
56121 +#include <linux/kernel.h>
56122 +#include <linux/sched.h>
56123 +#include <linux/mount.h>
56124 +#include <linux/grsecurity.h>
56125 +#include <linux/grinternal.h>
56128 +gr_log_remount(const char *devname, const int retval)
56130 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56131 + if (grsec_enable_mount && (retval >= 0))
56132 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
56138 +gr_log_unmount(const char *devname, const int retval)
56140 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56141 + if (grsec_enable_mount && (retval >= 0))
56142 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
56148 +gr_log_mount(const char *from, const char *to, const int retval)
56150 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56151 + if (grsec_enable_mount && (retval >= 0))
56152 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
56158 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
56160 +#ifdef CONFIG_GRKERNSEC_ROFS
56161 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
56162 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
56171 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
56173 +#ifdef CONFIG_GRKERNSEC_ROFS
56174 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
56175 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
56176 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
56183 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
56184 new file mode 100644
56185 index 0000000..a3b12a0
56187 +++ b/grsecurity/grsec_pax.c
56189 +#include <linux/kernel.h>
56190 +#include <linux/sched.h>
56191 +#include <linux/mm.h>
56192 +#include <linux/file.h>
56193 +#include <linux/grinternal.h>
56194 +#include <linux/grsecurity.h>
56197 +gr_log_textrel(struct vm_area_struct * vma)
56199 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56200 + if (grsec_enable_audit_textrel)
56201 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
56207 +gr_log_rwxmmap(struct file *file)
56209 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56210 + if (grsec_enable_log_rwxmaps)
56211 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
56217 +gr_log_rwxmprotect(struct file *file)
56219 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56220 + if (grsec_enable_log_rwxmaps)
56221 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
56225 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
56226 new file mode 100644
56227 index 0000000..f7f29aa
56229 +++ b/grsecurity/grsec_ptrace.c
56231 +#include <linux/kernel.h>
56232 +#include <linux/sched.h>
56233 +#include <linux/grinternal.h>
56234 +#include <linux/security.h>
56237 +gr_audit_ptrace(struct task_struct *task)
56239 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56240 + if (grsec_enable_audit_ptrace)
56241 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
56247 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
56249 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56250 + const struct dentry *dentry = file->f_path.dentry;
56251 + const struct vfsmount *mnt = file->f_path.mnt;
56253 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
56254 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
56255 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
56261 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
56262 new file mode 100644
56263 index 0000000..7a5b2de
56265 +++ b/grsecurity/grsec_sig.c
56267 +#include <linux/kernel.h>
56268 +#include <linux/sched.h>
56269 +#include <linux/delay.h>
56270 +#include <linux/grsecurity.h>
56271 +#include <linux/grinternal.h>
56272 +#include <linux/hardirq.h>
56274 +char *signames[] = {
56275 + [SIGSEGV] = "Segmentation fault",
56276 + [SIGILL] = "Illegal instruction",
56277 + [SIGABRT] = "Abort",
56278 + [SIGBUS] = "Invalid alignment/Bus error"
56282 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
56284 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56285 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
56286 + (sig == SIGABRT) || (sig == SIGBUS))) {
56287 + if (t->pid == current->pid) {
56288 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
56290 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
56298 +gr_handle_signal(const struct task_struct *p, const int sig)
56300 +#ifdef CONFIG_GRKERNSEC
56301 + /* ignore the 0 signal for protected task checks */
56302 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
56303 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
56305 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
56312 +#ifdef CONFIG_GRKERNSEC
56313 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
56315 +int gr_fake_force_sig(int sig, struct task_struct *t)
56317 + unsigned long int flags;
56318 + int ret, blocked, ignored;
56319 + struct k_sigaction *action;
56321 + spin_lock_irqsave(&t->sighand->siglock, flags);
56322 + action = &t->sighand->action[sig-1];
56323 + ignored = action->sa.sa_handler == SIG_IGN;
56324 + blocked = sigismember(&t->blocked, sig);
56325 + if (blocked || ignored) {
56326 + action->sa.sa_handler = SIG_DFL;
56328 + sigdelset(&t->blocked, sig);
56329 + recalc_sigpending_and_wake(t);
56332 + if (action->sa.sa_handler == SIG_DFL)
56333 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
56334 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
56336 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
56342 +#ifdef CONFIG_GRKERNSEC_BRUTE
56343 +#define GR_USER_BAN_TIME (15 * 60)
56345 +static int __get_dumpable(unsigned long mm_flags)
56349 + ret = mm_flags & MMF_DUMPABLE_MASK;
56350 + return (ret >= 2) ? 2 : ret;
56354 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
56356 +#ifdef CONFIG_GRKERNSEC_BRUTE
56359 + if (!grsec_enable_brute)
56363 + read_lock(&tasklist_lock);
56364 + read_lock(&grsec_exec_file_lock);
56365 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
56366 + p->real_parent->brute = 1;
56368 + const struct cred *cred = __task_cred(p), *cred2;
56369 + struct task_struct *tsk, *tsk2;
56371 + if (!__get_dumpable(mm_flags) && cred->uid) {
56372 + struct user_struct *user;
56376 + /* this is put upon execution past expiration */
56377 + user = find_user(uid);
56378 + if (user == NULL)
56380 + user->banned = 1;
56381 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
56382 + if (user->ban_expires == ~0UL)
56383 + user->ban_expires--;
56385 + do_each_thread(tsk2, tsk) {
56386 + cred2 = __task_cred(tsk);
56387 + if (tsk != p && cred2->uid == uid)
56388 + gr_fake_force_sig(SIGKILL, tsk);
56389 + } while_each_thread(tsk2, tsk);
56393 + read_unlock(&grsec_exec_file_lock);
56394 + read_unlock(&tasklist_lock);
56395 + rcu_read_unlock();
56398 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
56404 +void gr_handle_brute_check(void)
56406 +#ifdef CONFIG_GRKERNSEC_BRUTE
56407 + if (current->brute)
56408 + msleep(30 * 1000);
56413 +void gr_handle_kernel_exploit(void)
56415 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
56416 + const struct cred *cred;
56417 + struct task_struct *tsk, *tsk2;
56418 + struct user_struct *user;
56421 + if (in_irq() || in_serving_softirq() || in_nmi())
56422 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
56424 + uid = current_uid();
56427 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
56429 + /* kill all the processes of this user, hold a reference
56430 + to their creds struct, and prevent them from creating
56431 + another process until system reset
56433 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
56434 + /* we intentionally leak this ref */
56435 + user = get_uid(current->cred->user);
56437 + user->banned = 1;
56438 + user->ban_expires = ~0UL;
56441 + read_lock(&tasklist_lock);
56442 + do_each_thread(tsk2, tsk) {
56443 + cred = __task_cred(tsk);
56444 + if (cred->uid == uid)
56445 + gr_fake_force_sig(SIGKILL, tsk);
56446 + } while_each_thread(tsk2, tsk);
56447 + read_unlock(&tasklist_lock);
56452 +int __gr_process_user_ban(struct user_struct *user)
56454 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56455 + if (unlikely(user->banned)) {
56456 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
56457 + user->banned = 0;
56458 + user->ban_expires = 0;
56467 +int gr_process_user_ban(void)
56469 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56470 + return __gr_process_user_ban(current->cred->user);
56474 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
56475 new file mode 100644
56476 index 0000000..4030d57
56478 +++ b/grsecurity/grsec_sock.c
56480 +#include <linux/kernel.h>
56481 +#include <linux/module.h>
56482 +#include <linux/sched.h>
56483 +#include <linux/file.h>
56484 +#include <linux/net.h>
56485 +#include <linux/in.h>
56486 +#include <linux/ip.h>
56487 +#include <net/sock.h>
56488 +#include <net/inet_sock.h>
56489 +#include <linux/grsecurity.h>
56490 +#include <linux/grinternal.h>
56491 +#include <linux/gracl.h>
56493 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
56494 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
56496 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
56497 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
56499 +#ifdef CONFIG_UNIX_MODULE
56500 +EXPORT_SYMBOL(gr_acl_handle_unix);
56501 +EXPORT_SYMBOL(gr_acl_handle_mknod);
56502 +EXPORT_SYMBOL(gr_handle_chroot_unix);
56503 +EXPORT_SYMBOL(gr_handle_create);
56506 +#ifdef CONFIG_GRKERNSEC
56507 +#define gr_conn_table_size 32749
56508 +struct conn_table_entry {
56509 + struct conn_table_entry *next;
56510 + struct signal_struct *sig;
56513 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
56514 +DEFINE_SPINLOCK(gr_conn_table_lock);
56516 +extern const char * gr_socktype_to_name(unsigned char type);
56517 +extern const char * gr_proto_to_name(unsigned char proto);
56518 +extern const char * gr_sockfamily_to_name(unsigned char family);
56520 +static __inline__ int
56521 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
56523 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
56526 +static __inline__ int
56527 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
56528 + __u16 sport, __u16 dport)
56530 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
56531 + sig->gr_sport == sport && sig->gr_dport == dport))
56537 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
56539 + struct conn_table_entry **match;
56540 + unsigned int index;
56542 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56543 + sig->gr_sport, sig->gr_dport,
56544 + gr_conn_table_size);
56546 + newent->sig = sig;
56548 + match = &gr_conn_table[index];
56549 + newent->next = *match;
56555 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
56557 + struct conn_table_entry *match, *last = NULL;
56558 + unsigned int index;
56560 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56561 + sig->gr_sport, sig->gr_dport,
56562 + gr_conn_table_size);
56564 + match = gr_conn_table[index];
56565 + while (match && !conn_match(match->sig,
56566 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
56567 + sig->gr_dport)) {
56569 + match = match->next;
56574 + last->next = match->next;
56576 + gr_conn_table[index] = NULL;
56583 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
56584 + __u16 sport, __u16 dport)
56586 + struct conn_table_entry *match;
56587 + unsigned int index;
56589 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
56591 + match = gr_conn_table[index];
56592 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
56593 + match = match->next;
56596 + return match->sig;
56603 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
56605 +#ifdef CONFIG_GRKERNSEC
56606 + struct signal_struct *sig = task->signal;
56607 + struct conn_table_entry *newent;
56609 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
56610 + if (newent == NULL)
56612 + /* no bh lock needed since we are called with bh disabled */
56613 + spin_lock(&gr_conn_table_lock);
56614 + gr_del_task_from_ip_table_nolock(sig);
56615 + sig->gr_saddr = inet->inet_rcv_saddr;
56616 + sig->gr_daddr = inet->inet_daddr;
56617 + sig->gr_sport = inet->inet_sport;
56618 + sig->gr_dport = inet->inet_dport;
56619 + gr_add_to_task_ip_table_nolock(sig, newent);
56620 + spin_unlock(&gr_conn_table_lock);
56625 +void gr_del_task_from_ip_table(struct task_struct *task)
56627 +#ifdef CONFIG_GRKERNSEC
56628 + spin_lock_bh(&gr_conn_table_lock);
56629 + gr_del_task_from_ip_table_nolock(task->signal);
56630 + spin_unlock_bh(&gr_conn_table_lock);
56636 +gr_attach_curr_ip(const struct sock *sk)
56638 +#ifdef CONFIG_GRKERNSEC
56639 + struct signal_struct *p, *set;
56640 + const struct inet_sock *inet = inet_sk(sk);
56642 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
56645 + set = current->signal;
56647 + spin_lock_bh(&gr_conn_table_lock);
56648 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
56649 + inet->inet_dport, inet->inet_sport);
56650 + if (unlikely(p != NULL)) {
56651 + set->curr_ip = p->curr_ip;
56652 + set->used_accept = 1;
56653 + gr_del_task_from_ip_table_nolock(p);
56654 + spin_unlock_bh(&gr_conn_table_lock);
56657 + spin_unlock_bh(&gr_conn_table_lock);
56659 + set->curr_ip = inet->inet_daddr;
56660 + set->used_accept = 1;
56666 +gr_handle_sock_all(const int family, const int type, const int protocol)
56668 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56669 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
56670 + (family != AF_UNIX)) {
56671 + if (family == AF_INET)
56672 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
56674 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
56682 +gr_handle_sock_server(const struct sockaddr *sck)
56684 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56685 + if (grsec_enable_socket_server &&
56686 + in_group_p(grsec_socket_server_gid) &&
56687 + sck && (sck->sa_family != AF_UNIX) &&
56688 + (sck->sa_family != AF_LOCAL)) {
56689 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56697 +gr_handle_sock_server_other(const struct sock *sck)
56699 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56700 + if (grsec_enable_socket_server &&
56701 + in_group_p(grsec_socket_server_gid) &&
56702 + sck && (sck->sk_family != AF_UNIX) &&
56703 + (sck->sk_family != AF_LOCAL)) {
56704 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56712 +gr_handle_sock_client(const struct sockaddr *sck)
56714 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56715 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
56716 + sck && (sck->sa_family != AF_UNIX) &&
56717 + (sck->sa_family != AF_LOCAL)) {
56718 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
56724 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
56725 new file mode 100644
56726 index 0000000..a1aedd7
56728 +++ b/grsecurity/grsec_sysctl.c
56730 +#include <linux/kernel.h>
56731 +#include <linux/sched.h>
56732 +#include <linux/sysctl.h>
56733 +#include <linux/grsecurity.h>
56734 +#include <linux/grinternal.h>
56737 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
56739 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56740 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
56741 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
56748 +#ifdef CONFIG_GRKERNSEC_ROFS
56749 +static int __maybe_unused one = 1;
56752 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
56753 +struct ctl_table grsecurity_table[] = {
56754 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56755 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
56756 +#ifdef CONFIG_GRKERNSEC_IO
56758 + .procname = "disable_priv_io",
56759 + .data = &grsec_disable_privio,
56760 + .maxlen = sizeof(int),
56762 + .proc_handler = &proc_dointvec,
56766 +#ifdef CONFIG_GRKERNSEC_LINK
56768 + .procname = "linking_restrictions",
56769 + .data = &grsec_enable_link,
56770 + .maxlen = sizeof(int),
56772 + .proc_handler = &proc_dointvec,
56775 +#ifdef CONFIG_GRKERNSEC_BRUTE
56777 + .procname = "deter_bruteforce",
56778 + .data = &grsec_enable_brute,
56779 + .maxlen = sizeof(int),
56781 + .proc_handler = &proc_dointvec,
56784 +#ifdef CONFIG_GRKERNSEC_FIFO
56786 + .procname = "fifo_restrictions",
56787 + .data = &grsec_enable_fifo,
56788 + .maxlen = sizeof(int),
56790 + .proc_handler = &proc_dointvec,
56793 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56795 + .procname = "ptrace_readexec",
56796 + .data = &grsec_enable_ptrace_readexec,
56797 + .maxlen = sizeof(int),
56799 + .proc_handler = &proc_dointvec,
56802 +#ifdef CONFIG_GRKERNSEC_SETXID
56804 + .procname = "consistent_setxid",
56805 + .data = &grsec_enable_setxid,
56806 + .maxlen = sizeof(int),
56808 + .proc_handler = &proc_dointvec,
56811 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56813 + .procname = "ip_blackhole",
56814 + .data = &grsec_enable_blackhole,
56815 + .maxlen = sizeof(int),
56817 + .proc_handler = &proc_dointvec,
56820 + .procname = "lastack_retries",
56821 + .data = &grsec_lastack_retries,
56822 + .maxlen = sizeof(int),
56824 + .proc_handler = &proc_dointvec,
56827 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56829 + .procname = "exec_logging",
56830 + .data = &grsec_enable_execlog,
56831 + .maxlen = sizeof(int),
56833 + .proc_handler = &proc_dointvec,
56836 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56838 + .procname = "rwxmap_logging",
56839 + .data = &grsec_enable_log_rwxmaps,
56840 + .maxlen = sizeof(int),
56842 + .proc_handler = &proc_dointvec,
56845 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56847 + .procname = "signal_logging",
56848 + .data = &grsec_enable_signal,
56849 + .maxlen = sizeof(int),
56851 + .proc_handler = &proc_dointvec,
56854 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56856 + .procname = "forkfail_logging",
56857 + .data = &grsec_enable_forkfail,
56858 + .maxlen = sizeof(int),
56860 + .proc_handler = &proc_dointvec,
56863 +#ifdef CONFIG_GRKERNSEC_TIME
56865 + .procname = "timechange_logging",
56866 + .data = &grsec_enable_time,
56867 + .maxlen = sizeof(int),
56869 + .proc_handler = &proc_dointvec,
56872 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56874 + .procname = "chroot_deny_shmat",
56875 + .data = &grsec_enable_chroot_shmat,
56876 + .maxlen = sizeof(int),
56878 + .proc_handler = &proc_dointvec,
56881 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56883 + .procname = "chroot_deny_unix",
56884 + .data = &grsec_enable_chroot_unix,
56885 + .maxlen = sizeof(int),
56887 + .proc_handler = &proc_dointvec,
56890 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56892 + .procname = "chroot_deny_mount",
56893 + .data = &grsec_enable_chroot_mount,
56894 + .maxlen = sizeof(int),
56896 + .proc_handler = &proc_dointvec,
56899 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56901 + .procname = "chroot_deny_fchdir",
56902 + .data = &grsec_enable_chroot_fchdir,
56903 + .maxlen = sizeof(int),
56905 + .proc_handler = &proc_dointvec,
56908 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56910 + .procname = "chroot_deny_chroot",
56911 + .data = &grsec_enable_chroot_double,
56912 + .maxlen = sizeof(int),
56914 + .proc_handler = &proc_dointvec,
56917 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56919 + .procname = "chroot_deny_pivot",
56920 + .data = &grsec_enable_chroot_pivot,
56921 + .maxlen = sizeof(int),
56923 + .proc_handler = &proc_dointvec,
56926 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56928 + .procname = "chroot_enforce_chdir",
56929 + .data = &grsec_enable_chroot_chdir,
56930 + .maxlen = sizeof(int),
56932 + .proc_handler = &proc_dointvec,
56935 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56937 + .procname = "chroot_deny_chmod",
56938 + .data = &grsec_enable_chroot_chmod,
56939 + .maxlen = sizeof(int),
56941 + .proc_handler = &proc_dointvec,
56944 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56946 + .procname = "chroot_deny_mknod",
56947 + .data = &grsec_enable_chroot_mknod,
56948 + .maxlen = sizeof(int),
56950 + .proc_handler = &proc_dointvec,
56953 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56955 + .procname = "chroot_restrict_nice",
56956 + .data = &grsec_enable_chroot_nice,
56957 + .maxlen = sizeof(int),
56959 + .proc_handler = &proc_dointvec,
56962 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56964 + .procname = "chroot_execlog",
56965 + .data = &grsec_enable_chroot_execlog,
56966 + .maxlen = sizeof(int),
56968 + .proc_handler = &proc_dointvec,
56971 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56973 + .procname = "chroot_caps",
56974 + .data = &grsec_enable_chroot_caps,
56975 + .maxlen = sizeof(int),
56977 + .proc_handler = &proc_dointvec,
56980 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56982 + .procname = "chroot_deny_sysctl",
56983 + .data = &grsec_enable_chroot_sysctl,
56984 + .maxlen = sizeof(int),
56986 + .proc_handler = &proc_dointvec,
56989 +#ifdef CONFIG_GRKERNSEC_TPE
56991 + .procname = "tpe",
56992 + .data = &grsec_enable_tpe,
56993 + .maxlen = sizeof(int),
56995 + .proc_handler = &proc_dointvec,
56998 + .procname = "tpe_gid",
56999 + .data = &grsec_tpe_gid,
57000 + .maxlen = sizeof(int),
57002 + .proc_handler = &proc_dointvec,
57005 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57007 + .procname = "tpe_invert",
57008 + .data = &grsec_enable_tpe_invert,
57009 + .maxlen = sizeof(int),
57011 + .proc_handler = &proc_dointvec,
57014 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57016 + .procname = "tpe_restrict_all",
57017 + .data = &grsec_enable_tpe_all,
57018 + .maxlen = sizeof(int),
57020 + .proc_handler = &proc_dointvec,
57023 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57025 + .procname = "socket_all",
57026 + .data = &grsec_enable_socket_all,
57027 + .maxlen = sizeof(int),
57029 + .proc_handler = &proc_dointvec,
57032 + .procname = "socket_all_gid",
57033 + .data = &grsec_socket_all_gid,
57034 + .maxlen = sizeof(int),
57036 + .proc_handler = &proc_dointvec,
57039 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57041 + .procname = "socket_client",
57042 + .data = &grsec_enable_socket_client,
57043 + .maxlen = sizeof(int),
57045 + .proc_handler = &proc_dointvec,
57048 + .procname = "socket_client_gid",
57049 + .data = &grsec_socket_client_gid,
57050 + .maxlen = sizeof(int),
57052 + .proc_handler = &proc_dointvec,
57055 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57057 + .procname = "socket_server",
57058 + .data = &grsec_enable_socket_server,
57059 + .maxlen = sizeof(int),
57061 + .proc_handler = &proc_dointvec,
57064 + .procname = "socket_server_gid",
57065 + .data = &grsec_socket_server_gid,
57066 + .maxlen = sizeof(int),
57068 + .proc_handler = &proc_dointvec,
57071 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57073 + .procname = "audit_group",
57074 + .data = &grsec_enable_group,
57075 + .maxlen = sizeof(int),
57077 + .proc_handler = &proc_dointvec,
57080 + .procname = "audit_gid",
57081 + .data = &grsec_audit_gid,
57082 + .maxlen = sizeof(int),
57084 + .proc_handler = &proc_dointvec,
57087 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57089 + .procname = "audit_chdir",
57090 + .data = &grsec_enable_chdir,
57091 + .maxlen = sizeof(int),
57093 + .proc_handler = &proc_dointvec,
57096 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57098 + .procname = "audit_mount",
57099 + .data = &grsec_enable_mount,
57100 + .maxlen = sizeof(int),
57102 + .proc_handler = &proc_dointvec,
57105 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57107 + .procname = "audit_textrel",
57108 + .data = &grsec_enable_audit_textrel,
57109 + .maxlen = sizeof(int),
57111 + .proc_handler = &proc_dointvec,
57114 +#ifdef CONFIG_GRKERNSEC_DMESG
57116 + .procname = "dmesg",
57117 + .data = &grsec_enable_dmesg,
57118 + .maxlen = sizeof(int),
57120 + .proc_handler = &proc_dointvec,
57123 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57125 + .procname = "chroot_findtask",
57126 + .data = &grsec_enable_chroot_findtask,
57127 + .maxlen = sizeof(int),
57129 + .proc_handler = &proc_dointvec,
57132 +#ifdef CONFIG_GRKERNSEC_RESLOG
57134 + .procname = "resource_logging",
57135 + .data = &grsec_resource_logging,
57136 + .maxlen = sizeof(int),
57138 + .proc_handler = &proc_dointvec,
57141 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57143 + .procname = "audit_ptrace",
57144 + .data = &grsec_enable_audit_ptrace,
57145 + .maxlen = sizeof(int),
57147 + .proc_handler = &proc_dointvec,
57150 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57152 + .procname = "harden_ptrace",
57153 + .data = &grsec_enable_harden_ptrace,
57154 + .maxlen = sizeof(int),
57156 + .proc_handler = &proc_dointvec,
57160 + .procname = "grsec_lock",
57161 + .data = &grsec_lock,
57162 + .maxlen = sizeof(int),
57164 + .proc_handler = &proc_dointvec,
57167 +#ifdef CONFIG_GRKERNSEC_ROFS
57169 + .procname = "romount_protect",
57170 + .data = &grsec_enable_rofs,
57171 + .maxlen = sizeof(int),
57173 + .proc_handler = &proc_dointvec_minmax,
57181 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
57182 new file mode 100644
57183 index 0000000..0dc13c3
57185 +++ b/grsecurity/grsec_time.c
57187 +#include <linux/kernel.h>
57188 +#include <linux/sched.h>
57189 +#include <linux/grinternal.h>
57190 +#include <linux/module.h>
57193 +gr_log_timechange(void)
57195 +#ifdef CONFIG_GRKERNSEC_TIME
57196 + if (grsec_enable_time)
57197 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
57202 +EXPORT_SYMBOL(gr_log_timechange);
57203 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
57204 new file mode 100644
57205 index 0000000..07e0dc0
57207 +++ b/grsecurity/grsec_tpe.c
57209 +#include <linux/kernel.h>
57210 +#include <linux/sched.h>
57211 +#include <linux/file.h>
57212 +#include <linux/fs.h>
57213 +#include <linux/grinternal.h>
57215 +extern int gr_acl_tpe_check(void);
57218 +gr_tpe_allow(const struct file *file)
57220 +#ifdef CONFIG_GRKERNSEC
57221 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
57222 + const struct cred *cred = current_cred();
57223 + char *msg = NULL;
57224 + char *msg2 = NULL;
57226 + // never restrict root
57230 + if (grsec_enable_tpe) {
57231 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57232 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
57233 + msg = "not being in trusted group";
57234 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
57235 + msg = "being in untrusted group";
57237 + if (in_group_p(grsec_tpe_gid))
57238 + msg = "being in untrusted group";
57241 + if (!msg && gr_acl_tpe_check())
57242 + msg = "being in untrusted role";
57244 + // not in any affected group/role
57248 + if (inode->i_uid)
57249 + msg2 = "file in non-root-owned directory";
57250 + else if (inode->i_mode & S_IWOTH)
57251 + msg2 = "file in world-writable directory";
57252 + else if (inode->i_mode & S_IWGRP)
57253 + msg2 = "file in group-writable directory";
57255 + if (msg && msg2) {
57256 + char fullmsg[70] = {0};
57257 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
57258 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
57263 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57264 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
57267 + if (inode->i_uid && (inode->i_uid != cred->uid))
57268 + msg = "directory not owned by user";
57269 + else if (inode->i_mode & S_IWOTH)
57270 + msg = "file in world-writable directory";
57271 + else if (inode->i_mode & S_IWGRP)
57272 + msg = "file in group-writable directory";
57275 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
57282 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
57283 new file mode 100644
57284 index 0000000..9f7b1ac
57286 +++ b/grsecurity/grsum.c
57288 +#include <linux/err.h>
57289 +#include <linux/kernel.h>
57290 +#include <linux/sched.h>
57291 +#include <linux/mm.h>
57292 +#include <linux/scatterlist.h>
57293 +#include <linux/crypto.h>
57294 +#include <linux/gracl.h>
57297 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
57298 +#error "crypto and sha256 must be built into the kernel"
57302 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
57305 + struct crypto_hash *tfm;
57306 + struct hash_desc desc;
57307 + struct scatterlist sg;
57308 + unsigned char temp_sum[GR_SHA_LEN];
57309 + volatile int retval = 0;
57310 + volatile int dummy = 0;
57313 + sg_init_table(&sg, 1);
57315 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
57316 + if (IS_ERR(tfm)) {
57317 + /* should never happen, since sha256 should be built in */
57324 + crypto_hash_init(&desc);
57327 + sg_set_buf(&sg, p, GR_SALT_LEN);
57328 + crypto_hash_update(&desc, &sg, sg.length);
57331 + sg_set_buf(&sg, p, strlen(p));
57333 + crypto_hash_update(&desc, &sg, sg.length);
57335 + crypto_hash_final(&desc, temp_sum);
57337 + memset(entry->pw, 0, GR_PW_LEN);
57339 + for (i = 0; i < GR_SHA_LEN; i++)
57340 + if (sum[i] != temp_sum[i])
57343 + dummy = 1; // waste a cycle
57345 + crypto_free_hash(tfm);
57349 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
57350 index 6cd5b64..f620d2d 100644
57351 --- a/include/acpi/acpi_bus.h
57352 +++ b/include/acpi/acpi_bus.h
57353 @@ -107,7 +107,7 @@ struct acpi_device_ops {
57355 acpi_op_unbind unbind;
57356 acpi_op_notify notify;
57360 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
57362 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
57363 index b7babf0..71e4e74 100644
57364 --- a/include/asm-generic/atomic-long.h
57365 +++ b/include/asm-generic/atomic-long.h
57368 typedef atomic64_t atomic_long_t;
57370 +#ifdef CONFIG_PAX_REFCOUNT
57371 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
57373 +typedef atomic64_t atomic_long_unchecked_t;
57376 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
57378 static inline long atomic_long_read(atomic_long_t *l)
57379 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57380 return (long)atomic64_read(v);
57383 +#ifdef CONFIG_PAX_REFCOUNT
57384 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57386 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57388 + return (long)atomic64_read_unchecked(v);
57392 static inline void atomic_long_set(atomic_long_t *l, long i)
57394 atomic64_t *v = (atomic64_t *)l;
57395 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57396 atomic64_set(v, i);
57399 +#ifdef CONFIG_PAX_REFCOUNT
57400 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57402 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57404 + atomic64_set_unchecked(v, i);
57408 static inline void atomic_long_inc(atomic_long_t *l)
57410 atomic64_t *v = (atomic64_t *)l;
57411 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57415 +#ifdef CONFIG_PAX_REFCOUNT
57416 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57418 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57420 + atomic64_inc_unchecked(v);
57424 static inline void atomic_long_dec(atomic_long_t *l)
57426 atomic64_t *v = (atomic64_t *)l;
57427 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57431 +#ifdef CONFIG_PAX_REFCOUNT
57432 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57434 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57436 + atomic64_dec_unchecked(v);
57440 static inline void atomic_long_add(long i, atomic_long_t *l)
57442 atomic64_t *v = (atomic64_t *)l;
57443 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57444 atomic64_add(i, v);
57447 +#ifdef CONFIG_PAX_REFCOUNT
57448 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57450 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57452 + atomic64_add_unchecked(i, v);
57456 static inline void atomic_long_sub(long i, atomic_long_t *l)
57458 atomic64_t *v = (atomic64_t *)l;
57459 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57460 atomic64_sub(i, v);
57463 +#ifdef CONFIG_PAX_REFCOUNT
57464 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57466 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57468 + atomic64_sub_unchecked(i, v);
57472 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57474 atomic64_t *v = (atomic64_t *)l;
57475 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57476 return (long)atomic64_inc_return(v);
57479 +#ifdef CONFIG_PAX_REFCOUNT
57480 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57482 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57484 + return (long)atomic64_inc_return_unchecked(v);
57488 static inline long atomic_long_dec_return(atomic_long_t *l)
57490 atomic64_t *v = (atomic64_t *)l;
57491 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57493 typedef atomic_t atomic_long_t;
57495 +#ifdef CONFIG_PAX_REFCOUNT
57496 +typedef atomic_unchecked_t atomic_long_unchecked_t;
57498 +typedef atomic_t atomic_long_unchecked_t;
57501 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
57502 static inline long atomic_long_read(atomic_long_t *l)
57504 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57505 return (long)atomic_read(v);
57508 +#ifdef CONFIG_PAX_REFCOUNT
57509 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57511 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57513 + return (long)atomic_read_unchecked(v);
57517 static inline void atomic_long_set(atomic_long_t *l, long i)
57519 atomic_t *v = (atomic_t *)l;
57520 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57524 +#ifdef CONFIG_PAX_REFCOUNT
57525 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57527 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57529 + atomic_set_unchecked(v, i);
57533 static inline void atomic_long_inc(atomic_long_t *l)
57535 atomic_t *v = (atomic_t *)l;
57536 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57540 +#ifdef CONFIG_PAX_REFCOUNT
57541 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57543 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57545 + atomic_inc_unchecked(v);
57549 static inline void atomic_long_dec(atomic_long_t *l)
57551 atomic_t *v = (atomic_t *)l;
57552 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57556 +#ifdef CONFIG_PAX_REFCOUNT
57557 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57559 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57561 + atomic_dec_unchecked(v);
57565 static inline void atomic_long_add(long i, atomic_long_t *l)
57567 atomic_t *v = (atomic_t *)l;
57568 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57572 +#ifdef CONFIG_PAX_REFCOUNT
57573 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57575 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57577 + atomic_add_unchecked(i, v);
57581 static inline void atomic_long_sub(long i, atomic_long_t *l)
57583 atomic_t *v = (atomic_t *)l;
57584 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57588 +#ifdef CONFIG_PAX_REFCOUNT
57589 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57591 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57593 + atomic_sub_unchecked(i, v);
57597 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57599 atomic_t *v = (atomic_t *)l;
57600 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57601 return (long)atomic_inc_return(v);
57604 +#ifdef CONFIG_PAX_REFCOUNT
57605 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57607 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57609 + return (long)atomic_inc_return_unchecked(v);
57613 static inline long atomic_long_dec_return(atomic_long_t *l)
57615 atomic_t *v = (atomic_t *)l;
57616 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57618 #endif /* BITS_PER_LONG == 64 */
57620 +#ifdef CONFIG_PAX_REFCOUNT
57621 +static inline void pax_refcount_needs_these_functions(void)
57623 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
57624 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
57625 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
57626 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
57627 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
57628 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
57629 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
57630 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
57631 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
57632 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
57633 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
57635 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
57636 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
57637 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
57638 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
57639 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
57640 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
57641 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
57644 +#define atomic_read_unchecked(v) atomic_read(v)
57645 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
57646 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
57647 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
57648 +#define atomic_inc_unchecked(v) atomic_inc(v)
57649 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
57650 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
57651 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
57652 +#define atomic_dec_unchecked(v) atomic_dec(v)
57653 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
57654 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
57656 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
57657 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
57658 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
57659 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
57660 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
57661 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
57662 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
57665 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
57666 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
57667 index b18ce4f..2ee2843 100644
57668 --- a/include/asm-generic/atomic64.h
57669 +++ b/include/asm-generic/atomic64.h
57670 @@ -16,6 +16,8 @@ typedef struct {
57674 +typedef atomic64_t atomic64_unchecked_t;
57676 #define ATOMIC64_INIT(i) { (i) }
57678 extern long long atomic64_read(const atomic64_t *v);
57679 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
57680 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
57681 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
57683 +#define atomic64_read_unchecked(v) atomic64_read(v)
57684 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
57685 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
57686 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
57687 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
57688 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
57689 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
57690 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
57691 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
57693 #endif /* _ASM_GENERIC_ATOMIC64_H */
57694 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
57695 index 1bfcfe5..e04c5c9 100644
57696 --- a/include/asm-generic/cache.h
57697 +++ b/include/asm-generic/cache.h
57699 * cache lines need to provide their own cache.h.
57702 -#define L1_CACHE_SHIFT 5
57703 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
57704 +#define L1_CACHE_SHIFT 5UL
57705 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
57707 #endif /* __ASM_GENERIC_CACHE_H */
57708 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
57709 index 1ca3efc..e3dc852 100644
57710 --- a/include/asm-generic/int-l64.h
57711 +++ b/include/asm-generic/int-l64.h
57712 @@ -46,6 +46,8 @@ typedef unsigned int u32;
57713 typedef signed long s64;
57714 typedef unsigned long u64;
57716 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
57719 #define U8_C(x) x ## U
57721 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
57722 index f394147..b6152b9 100644
57723 --- a/include/asm-generic/int-ll64.h
57724 +++ b/include/asm-generic/int-ll64.h
57725 @@ -51,6 +51,8 @@ typedef unsigned int u32;
57726 typedef signed long long s64;
57727 typedef unsigned long long u64;
57729 +typedef unsigned long long intoverflow_t;
57732 #define U8_C(x) x ## U
57734 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
57735 index 0232ccb..13d9165 100644
57736 --- a/include/asm-generic/kmap_types.h
57737 +++ b/include/asm-generic/kmap_types.h
57738 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
57740 KMAP_D(18) KM_NMI_PTE,
57742 +KMAP_D(20) KM_CLEARPAGE,
57744 * Remember to update debug_kmap_atomic() when adding new kmap types!
57746 -KMAP_D(20) KM_TYPE_NR
57747 +KMAP_D(21) KM_TYPE_NR
57751 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
57752 index 725612b..9cc513a 100644
57753 --- a/include/asm-generic/pgtable-nopmd.h
57754 +++ b/include/asm-generic/pgtable-nopmd.h
57756 #ifndef _PGTABLE_NOPMD_H
57757 #define _PGTABLE_NOPMD_H
57759 -#ifndef __ASSEMBLY__
57761 #include <asm-generic/pgtable-nopud.h>
57765 #define __PAGETABLE_PMD_FOLDED
57767 +#define PMD_SHIFT PUD_SHIFT
57768 +#define PTRS_PER_PMD 1
57769 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
57770 +#define PMD_MASK (~(PMD_SIZE-1))
57772 +#ifndef __ASSEMBLY__
57777 * Having the pmd type consist of a pud gets the size right, and allows
57778 * us to conceptually access the pud entry that this pmd is folded into
57779 @@ -16,11 +21,6 @@ struct mm_struct;
57781 typedef struct { pud_t pud; } pmd_t;
57783 -#define PMD_SHIFT PUD_SHIFT
57784 -#define PTRS_PER_PMD 1
57785 -#define PMD_SIZE (1UL << PMD_SHIFT)
57786 -#define PMD_MASK (~(PMD_SIZE-1))
57789 * The "pud_xxx()" functions here are trivial for a folded two-level
57790 * setup: the pmd is never bad, and a pmd always exists (as it's folded
57791 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
57792 index 810431d..ccc3638 100644
57793 --- a/include/asm-generic/pgtable-nopud.h
57794 +++ b/include/asm-generic/pgtable-nopud.h
57796 #ifndef _PGTABLE_NOPUD_H
57797 #define _PGTABLE_NOPUD_H
57799 -#ifndef __ASSEMBLY__
57801 #define __PAGETABLE_PUD_FOLDED
57803 +#define PUD_SHIFT PGDIR_SHIFT
57804 +#define PTRS_PER_PUD 1
57805 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
57806 +#define PUD_MASK (~(PUD_SIZE-1))
57808 +#ifndef __ASSEMBLY__
57811 * Having the pud type consist of a pgd gets the size right, and allows
57812 * us to conceptually access the pgd entry that this pud is folded into
57815 typedef struct { pgd_t pgd; } pud_t;
57817 -#define PUD_SHIFT PGDIR_SHIFT
57818 -#define PTRS_PER_PUD 1
57819 -#define PUD_SIZE (1UL << PUD_SHIFT)
57820 -#define PUD_MASK (~(PUD_SIZE-1))
57823 * The "pgd_xxx()" functions here are trivial for a folded two-level
57824 * setup: the pud is never bad, and a pud always exists (as it's folded
57825 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
57826 index 76bff2b..c7a14e2 100644
57827 --- a/include/asm-generic/pgtable.h
57828 +++ b/include/asm-generic/pgtable.h
57829 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
57830 #endif /* __HAVE_ARCH_PMD_WRITE */
57833 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
57834 +static inline unsigned long pax_open_kernel(void) { return 0; }
57837 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
57838 +static inline unsigned long pax_close_kernel(void) { return 0; }
57841 #endif /* !__ASSEMBLY__ */
57843 #endif /* _ASM_GENERIC_PGTABLE_H */
57844 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
57845 index b5e2e4c..6a5373e 100644
57846 --- a/include/asm-generic/vmlinux.lds.h
57847 +++ b/include/asm-generic/vmlinux.lds.h
57848 @@ -217,6 +217,7 @@
57849 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
57850 VMLINUX_SYMBOL(__start_rodata) = .; \
57851 *(.rodata) *(.rodata.*) \
57852 + *(.data..read_only) \
57853 *(__vermagic) /* Kernel version magic */ \
57855 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
57856 @@ -722,17 +723,18 @@
57857 * section in the linker script will go there too. @phdr should have
57860 - * Note that this macros defines __per_cpu_load as an absolute symbol.
57861 + * Note that this macros defines per_cpu_load as an absolute symbol.
57862 * If there is no need to put the percpu section at a predetermined
57863 * address, use PERCPU_SECTION.
57865 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
57866 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
57867 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
57868 + per_cpu_load = .; \
57869 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
57871 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
57872 PERCPU_INPUT(cacheline) \
57874 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
57875 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
57878 * PERCPU_SECTION - define output section for percpu area, simple version
57879 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
57880 index bf4b2dc..2d0762f 100644
57881 --- a/include/drm/drmP.h
57882 +++ b/include/drm/drmP.h
57884 #include <linux/workqueue.h>
57885 #include <linux/poll.h>
57886 #include <asm/pgalloc.h>
57887 +#include <asm/local.h>
57890 #include <linux/idr.h>
57891 @@ -1038,7 +1039,7 @@ struct drm_device {
57893 /** \name Usage Counters */
57895 - int open_count; /**< Outstanding files open */
57896 + local_t open_count; /**< Outstanding files open */
57897 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
57898 atomic_t vma_count; /**< Outstanding vma areas open */
57899 int buf_use; /**< Buffers in use -- cannot alloc */
57900 @@ -1049,7 +1050,7 @@ struct drm_device {
57902 unsigned long counters;
57903 enum drm_stat_type types[15];
57904 - atomic_t counts[15];
57905 + atomic_unchecked_t counts[15];
57908 struct list_head filelist;
57909 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
57910 index 73b0712..0b7ef2f 100644
57911 --- a/include/drm/drm_crtc_helper.h
57912 +++ b/include/drm/drm_crtc_helper.h
57913 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
57915 /* disable crtc when not in use - more explicit than dpms off */
57916 void (*disable)(struct drm_crtc *crtc);
57920 struct drm_encoder_helper_funcs {
57921 void (*dpms)(struct drm_encoder *encoder, int mode);
57922 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
57923 struct drm_connector *connector);
57924 /* disable encoder when not in use - more explicit than dpms off */
57925 void (*disable)(struct drm_encoder *encoder);
57929 struct drm_connector_helper_funcs {
57930 int (*get_modes)(struct drm_connector *connector);
57931 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
57932 index 26c1f78..6722682 100644
57933 --- a/include/drm/ttm/ttm_memory.h
57934 +++ b/include/drm/ttm/ttm_memory.h
57937 struct ttm_mem_shrink {
57938 int (*do_shrink) (struct ttm_mem_shrink *);
57943 * struct ttm_mem_global - Global memory accounting structure.
57944 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
57945 index e86dfca..40cc55f 100644
57946 --- a/include/linux/a.out.h
57947 +++ b/include/linux/a.out.h
57948 @@ -39,6 +39,14 @@ enum machine_type {
57949 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
57952 +/* Constants for the N_FLAGS field */
57953 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57954 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
57955 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
57956 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
57957 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57958 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57960 #if !defined (N_MAGIC)
57961 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
57963 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
57964 index 49a83ca..df96b54 100644
57965 --- a/include/linux/atmdev.h
57966 +++ b/include/linux/atmdev.h
57967 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
57970 struct k_atm_aal_stats {
57971 -#define __HANDLE_ITEM(i) atomic_t i
57972 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
57974 #undef __HANDLE_ITEM
57976 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
57977 index fd88a39..8a801b4 100644
57978 --- a/include/linux/binfmts.h
57979 +++ b/include/linux/binfmts.h
57980 @@ -18,7 +18,7 @@ struct pt_regs;
57981 #define BINPRM_BUF_SIZE 128
57984 -#include <linux/list.h>
57985 +#include <linux/sched.h>
57987 #define CORENAME_MAX_SIZE 128
57989 @@ -58,6 +58,7 @@ struct linux_binprm {
57990 unsigned interp_flags;
57991 unsigned interp_data;
57992 unsigned long loader, exec;
57993 + char tcomm[TASK_COMM_LEN];
57996 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
57997 @@ -88,6 +89,7 @@ struct linux_binfmt {
57998 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
57999 int (*load_shlib)(struct file *);
58000 int (*core_dump)(struct coredump_params *cprm);
58001 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
58002 unsigned long min_coredump; /* minimal dump size */
58005 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
58006 index 0ed1eb0..3ab569b 100644
58007 --- a/include/linux/blkdev.h
58008 +++ b/include/linux/blkdev.h
58009 @@ -1315,7 +1315,7 @@ struct block_device_operations {
58010 /* this callback is with swap_lock and sometimes page table lock held */
58011 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
58012 struct module *owner;
58016 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
58018 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
58019 index 4d1a074..88f929a 100644
58020 --- a/include/linux/blktrace_api.h
58021 +++ b/include/linux/blktrace_api.h
58022 @@ -162,7 +162,7 @@ struct blk_trace {
58023 struct dentry *dir;
58024 struct dentry *dropped_file;
58025 struct dentry *msg_file;
58026 - atomic_t dropped;
58027 + atomic_unchecked_t dropped;
58030 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
58031 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
58032 index 83195fb..0b0f77d 100644
58033 --- a/include/linux/byteorder/little_endian.h
58034 +++ b/include/linux/byteorder/little_endian.h
58035 @@ -42,51 +42,51 @@
58037 static inline __le64 __cpu_to_le64p(const __u64 *p)
58039 - return (__force __le64)*p;
58040 + return (__force const __le64)*p;
58042 static inline __u64 __le64_to_cpup(const __le64 *p)
58044 - return (__force __u64)*p;
58045 + return (__force const __u64)*p;
58047 static inline __le32 __cpu_to_le32p(const __u32 *p)
58049 - return (__force __le32)*p;
58050 + return (__force const __le32)*p;
58052 static inline __u32 __le32_to_cpup(const __le32 *p)
58054 - return (__force __u32)*p;
58055 + return (__force const __u32)*p;
58057 static inline __le16 __cpu_to_le16p(const __u16 *p)
58059 - return (__force __le16)*p;
58060 + return (__force const __le16)*p;
58062 static inline __u16 __le16_to_cpup(const __le16 *p)
58064 - return (__force __u16)*p;
58065 + return (__force const __u16)*p;
58067 static inline __be64 __cpu_to_be64p(const __u64 *p)
58069 - return (__force __be64)__swab64p(p);
58070 + return (__force const __be64)__swab64p(p);
58072 static inline __u64 __be64_to_cpup(const __be64 *p)
58074 - return __swab64p((__u64 *)p);
58075 + return __swab64p((const __u64 *)p);
58077 static inline __be32 __cpu_to_be32p(const __u32 *p)
58079 - return (__force __be32)__swab32p(p);
58080 + return (__force const __be32)__swab32p(p);
58082 static inline __u32 __be32_to_cpup(const __be32 *p)
58084 - return __swab32p((__u32 *)p);
58085 + return __swab32p((const __u32 *)p);
58087 static inline __be16 __cpu_to_be16p(const __u16 *p)
58089 - return (__force __be16)__swab16p(p);
58090 + return (__force const __be16)__swab16p(p);
58092 static inline __u16 __be16_to_cpup(const __be16 *p)
58094 - return __swab16p((__u16 *)p);
58095 + return __swab16p((const __u16 *)p);
58097 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
58098 #define __le64_to_cpus(x) do { (void)(x); } while (0)
58099 diff --git a/include/linux/cache.h b/include/linux/cache.h
58100 index 4c57065..4307975 100644
58101 --- a/include/linux/cache.h
58102 +++ b/include/linux/cache.h
58104 #define __read_mostly
58107 +#ifndef __read_only
58108 +#define __read_only __read_mostly
58111 #ifndef ____cacheline_aligned
58112 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
58114 diff --git a/include/linux/capability.h b/include/linux/capability.h
58115 index a63d13d..069bfd5 100644
58116 --- a/include/linux/capability.h
58117 +++ b/include/linux/capability.h
58118 @@ -548,6 +548,9 @@ extern bool capable(int cap);
58119 extern bool ns_capable(struct user_namespace *ns, int cap);
58120 extern bool task_ns_capable(struct task_struct *t, int cap);
58121 extern bool nsown_capable(int cap);
58122 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
58123 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
58124 +extern bool capable_nolog(int cap);
58126 /* audit system wants to get cap info from files as well */
58127 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
58128 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
58129 index 04ffb2e..6799180 100644
58130 --- a/include/linux/cleancache.h
58131 +++ b/include/linux/cleancache.h
58132 @@ -31,7 +31,7 @@ struct cleancache_ops {
58133 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
58134 void (*flush_inode)(int, struct cleancache_filekey);
58135 void (*flush_fs)(int);
58139 extern struct cleancache_ops
58140 cleancache_register_ops(struct cleancache_ops *ops);
58141 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
58142 index dfadc96..c0e70c1 100644
58143 --- a/include/linux/compiler-gcc4.h
58144 +++ b/include/linux/compiler-gcc4.h
58148 #if __GNUC_MINOR__ >= 5
58150 +#ifdef CONSTIFY_PLUGIN
58151 +#define __no_const __attribute__((no_const))
58152 +#define __do_const __attribute__((do_const))
58156 * Mark a position in code as unreachable. This can be used to
58157 * suppress control flow warnings after asm blocks that transfer
58159 #define __noclone __attribute__((__noclone__))
58163 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
58164 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
58165 +#define __bos0(ptr) __bos((ptr), 0)
58166 +#define __bos1(ptr) __bos((ptr), 1)
58169 #if __GNUC_MINOR__ > 0
58170 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
58171 index 320d6c9..8573a1c 100644
58172 --- a/include/linux/compiler.h
58173 +++ b/include/linux/compiler.h
58177 # define __user __attribute__((noderef, address_space(1)))
58178 +# define __force_user __force __user
58179 # define __kernel __attribute__((address_space(0)))
58180 +# define __force_kernel __force __kernel
58181 # define __safe __attribute__((safe))
58182 # define __force __attribute__((force))
58183 # define __nocast __attribute__((nocast))
58184 # define __iomem __attribute__((noderef, address_space(2)))
58185 +# define __force_iomem __force __iomem
58186 # define __acquires(x) __attribute__((context(x,0,1)))
58187 # define __releases(x) __attribute__((context(x,1,0)))
58188 # define __acquire(x) __context__(x,1)
58189 # define __release(x) __context__(x,-1)
58190 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
58191 # define __percpu __attribute__((noderef, address_space(3)))
58192 +# define __force_percpu __force __percpu
58193 #ifdef CONFIG_SPARSE_RCU_POINTER
58194 # define __rcu __attribute__((noderef, address_space(4)))
58195 +# define __force_rcu __force __rcu
58198 +# define __force_rcu
58200 extern void __chk_user_ptr(const volatile void __user *);
58201 extern void __chk_io_ptr(const volatile void __iomem *);
58202 +#elif defined(CHECKER_PLUGIN)
58204 +//# define __force_user
58205 +//# define __kernel
58206 +//# define __force_kernel
58211 +# define __force_iomem
58212 +# define __chk_user_ptr(x) (void)0
58213 +# define __chk_io_ptr(x) (void)0
58214 +# define __builtin_warning(x, y...) (1)
58215 +# define __acquires(x)
58216 +# define __releases(x)
58217 +# define __acquire(x) (void)0
58218 +# define __release(x) (void)0
58219 +# define __cond_lock(x,c) (c)
58221 +# define __force_percpu
58223 +# define __force_rcu
58226 +# define __force_user
58228 +# define __force_kernel
58233 +# define __force_iomem
58234 # define __chk_user_ptr(x) (void)0
58235 # define __chk_io_ptr(x) (void)0
58236 # define __builtin_warning(x, y...) (1)
58237 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
58238 # define __release(x) (void)0
58239 # define __cond_lock(x,c) (c)
58241 +# define __force_percpu
58243 +# define __force_rcu
58247 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58248 # define __attribute_const__ /* unimplemented */
58251 +#ifndef __no_const
58252 +# define __no_const
58255 +#ifndef __do_const
58256 +# define __do_const
58260 * Tell gcc if a function is cold. The compiler will assume any path
58261 * directly leading to the call is unlikely.
58262 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58266 +#ifndef __alloc_size
58267 +#define __alloc_size(...)
58271 +#define __bos(ptr, arg)
58275 +#define __bos0(ptr)
58279 +#define __bos1(ptr)
58282 /* Simple shorthand for a section definition */
58284 # define __section(S) __attribute__ ((__section__(#S)))
58285 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58286 * use is to mediate communication between process-level code and irq/NMI
58287 * handlers, all running on the same CPU.
58289 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
58290 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
58291 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
58293 #endif /* __LINUX_COMPILER_H */
58294 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
58295 index e9eaec5..bfeb9bb 100644
58296 --- a/include/linux/cpuset.h
58297 +++ b/include/linux/cpuset.h
58298 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
58302 - --ACCESS_ONCE(current->mems_allowed_change_disable);
58303 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
58306 static inline void set_mems_allowed(nodemask_t nodemask)
58307 diff --git a/include/linux/cred.h b/include/linux/cred.h
58308 index 4030896..8d6f342 100644
58309 --- a/include/linux/cred.h
58310 +++ b/include/linux/cred.h
58311 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
58312 static inline void validate_process_creds(void)
58315 +static inline void validate_task_creds(struct task_struct *task)
58321 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
58322 index 8a94217..15d49e3 100644
58323 --- a/include/linux/crypto.h
58324 +++ b/include/linux/crypto.h
58325 @@ -365,7 +365,7 @@ struct cipher_tfm {
58326 const u8 *key, unsigned int keylen);
58327 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58328 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58333 int (*init)(struct hash_desc *desc);
58334 @@ -386,13 +386,13 @@ struct compress_tfm {
58335 int (*cot_decompress)(struct crypto_tfm *tfm,
58336 const u8 *src, unsigned int slen,
58337 u8 *dst, unsigned int *dlen);
58342 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
58343 unsigned int dlen);
58344 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
58348 #define crt_ablkcipher crt_u.ablkcipher
58349 #define crt_aead crt_u.aead
58350 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
58351 index 7925bf0..d5143d2 100644
58352 --- a/include/linux/decompress/mm.h
58353 +++ b/include/linux/decompress/mm.h
58354 @@ -77,7 +77,7 @@ static void free(void *where)
58355 * warnings when not needed (indeed large_malloc / large_free are not
58356 * needed by inflate */
58358 -#define malloc(a) kmalloc(a, GFP_KERNEL)
58359 +#define malloc(a) kmalloc((a), GFP_KERNEL)
58360 #define free(a) kfree(a)
58362 #define large_malloc(a) vmalloc(a)
58363 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
58364 index e13117c..e9fc938 100644
58365 --- a/include/linux/dma-mapping.h
58366 +++ b/include/linux/dma-mapping.h
58367 @@ -46,7 +46,7 @@ struct dma_map_ops {
58368 u64 (*get_required_mask)(struct device *dev);
58374 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
58376 diff --git a/include/linux/efi.h b/include/linux/efi.h
58377 index 2362a0b..cfaf8fcc 100644
58378 --- a/include/linux/efi.h
58379 +++ b/include/linux/efi.h
58380 @@ -446,7 +446,7 @@ struct efivar_operations {
58381 efi_get_variable_t *get_variable;
58382 efi_get_next_variable_t *get_next_variable;
58383 efi_set_variable_t *set_variable;
58389 diff --git a/include/linux/elf.h b/include/linux/elf.h
58390 index 31f0508..5421c01 100644
58391 --- a/include/linux/elf.h
58392 +++ b/include/linux/elf.h
58393 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
58394 #define PT_GNU_EH_FRAME 0x6474e550
58396 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
58397 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
58399 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
58401 +/* Constants for the e_flags field */
58402 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
58403 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
58404 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
58405 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
58406 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
58407 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
58410 * Extended Numbering
58411 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
58412 #define DT_DEBUG 21
58413 #define DT_TEXTREL 22
58414 #define DT_JMPREL 23
58415 +#define DT_FLAGS 30
58416 + #define DF_TEXTREL 0x00000004
58417 #define DT_ENCODING 32
58418 #define OLD_DT_LOOS 0x60000000
58419 #define DT_LOOS 0x6000000d
58420 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
58424 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
58425 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
58426 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
58427 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
58428 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
58429 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
58430 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
58431 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
58432 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
58433 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
58434 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
58435 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
58437 typedef struct elf32_phdr{
58439 Elf32_Off p_offset;
58440 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
58446 #define ELFMAG0 0x7f /* EI_MAG */
58447 #define ELFMAG1 'E'
58448 #define ELFMAG2 'L'
58449 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
58450 #define elf_note elf32_note
58451 #define elf_addr_t Elf32_Off
58452 #define Elf_Half Elf32_Half
58453 +#define elf_dyn Elf32_Dyn
58457 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
58458 #define elf_note elf64_note
58459 #define elf_addr_t Elf64_Off
58460 #define Elf_Half Elf64_Half
58461 +#define elf_dyn Elf64_Dyn
58465 diff --git a/include/linux/filter.h b/include/linux/filter.h
58466 index 8eeb205..d59bfa2 100644
58467 --- a/include/linux/filter.h
58468 +++ b/include/linux/filter.h
58469 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
58473 +struct bpf_jit_work;
58477 @@ -141,6 +142,9 @@ struct sk_filter
58478 unsigned int len; /* Number of filter blocks */
58479 unsigned int (*bpf_func)(const struct sk_buff *skb,
58480 const struct sock_filter *filter);
58481 +#ifdef CONFIG_BPF_JIT
58482 + struct bpf_jit_work *work;
58484 struct rcu_head rcu;
58485 struct sock_filter insns[0];
58487 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
58488 index 84ccf8e..2e9b14c 100644
58489 --- a/include/linux/firewire.h
58490 +++ b/include/linux/firewire.h
58491 @@ -428,7 +428,7 @@ struct fw_iso_context {
58493 fw_iso_callback_t sc;
58494 fw_iso_mc_callback_t mc;
58496 + } __no_const callback;
58497 void *callback_data;
58500 diff --git a/include/linux/fs.h b/include/linux/fs.h
58501 index 10b2288..09180e4 100644
58502 --- a/include/linux/fs.h
58503 +++ b/include/linux/fs.h
58504 @@ -1609,7 +1609,8 @@ struct file_operations {
58505 int (*setlease)(struct file *, long, struct file_lock **);
58506 long (*fallocate)(struct file *file, int mode, loff_t offset,
58510 +typedef struct file_operations __no_const file_operations_no_const;
58512 struct inode_operations {
58513 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
58514 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
58515 index 003dc0f..3c4ea97 100644
58516 --- a/include/linux/fs_struct.h
58517 +++ b/include/linux/fs_struct.h
58519 #include <linux/seqlock.h>
58527 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
58528 index ce31408..b1ad003 100644
58529 --- a/include/linux/fscache-cache.h
58530 +++ b/include/linux/fscache-cache.h
58531 @@ -102,7 +102,7 @@ struct fscache_operation {
58532 fscache_operation_release_t release;
58535 -extern atomic_t fscache_op_debug_id;
58536 +extern atomic_unchecked_t fscache_op_debug_id;
58537 extern void fscache_op_work_func(struct work_struct *work);
58539 extern void fscache_enqueue_operation(struct fscache_operation *);
58540 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
58542 INIT_WORK(&op->work, fscache_op_work_func);
58543 atomic_set(&op->usage, 1);
58544 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58545 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58546 op->processor = processor;
58547 op->release = release;
58548 INIT_LIST_HEAD(&op->pend_link);
58549 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
58550 index 2a53f10..0187fdf 100644
58551 --- a/include/linux/fsnotify.h
58552 +++ b/include/linux/fsnotify.h
58553 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
58555 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
58557 - return kstrdup(name, GFP_KERNEL);
58558 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
58562 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
58563 index 91d0e0a3..035666b 100644
58564 --- a/include/linux/fsnotify_backend.h
58565 +++ b/include/linux/fsnotify_backend.h
58566 @@ -105,6 +105,7 @@ struct fsnotify_ops {
58567 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
58568 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
58570 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
58573 * A group is a "thing" that wants to receive notification about filesystem
58574 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
58575 index c3da42d..c70e0df 100644
58576 --- a/include/linux/ftrace_event.h
58577 +++ b/include/linux/ftrace_event.h
58578 @@ -97,7 +97,7 @@ struct trace_event_functions {
58579 trace_print_func raw;
58580 trace_print_func hex;
58581 trace_print_func binary;
58585 struct trace_event {
58586 struct hlist_node node;
58587 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
58588 extern int trace_add_event_call(struct ftrace_event_call *call);
58589 extern void trace_remove_event_call(struct ftrace_event_call *call);
58591 -#define is_signed_type(type) (((type)(-1)) < 0)
58592 +#define is_signed_type(type) (((type)(-1)) < (type)1)
58594 int trace_set_clr_event(const char *system, const char *event, int set);
58596 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
58597 index 6d18f35..ab71e2c 100644
58598 --- a/include/linux/genhd.h
58599 +++ b/include/linux/genhd.h
58600 @@ -185,7 +185,7 @@ struct gendisk {
58601 struct kobject *slave_dir;
58603 struct timer_rand_state *random;
58604 - atomic_t sync_io; /* RAID */
58605 + atomic_unchecked_t sync_io; /* RAID */
58606 struct disk_events *ev;
58607 #ifdef CONFIG_BLK_DEV_INTEGRITY
58608 struct blk_integrity *integrity;
58609 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
58610 new file mode 100644
58611 index 0000000..8a130b6
58613 +++ b/include/linux/gracl.h
58618 +#include <linux/grdefs.h>
58619 +#include <linux/resource.h>
58620 +#include <linux/capability.h>
58621 +#include <linux/dcache.h>
58622 +#include <asm/resource.h>
58624 +/* Major status information */
58626 +#define GR_VERSION "grsecurity 2.9"
58627 +#define GRSECURITY_VERSION 0x2900
58638 + GR_SPROLEPAM = 8,
58641 +/* Password setup definitions
58642 + * kernel/grhash.c */
58645 + GR_SALT_LEN = 16,
58650 + GR_SPROLE_LEN = 64,
58659 +#define GR_NLIMITS 32
58661 +/* Begin Data Structures */
58663 +struct sprole_pw {
58664 + unsigned char *rolename;
58665 + unsigned char salt[GR_SALT_LEN];
58666 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
58669 +struct name_entry {
58676 + struct name_entry *prev;
58677 + struct name_entry *next;
58680 +struct inodev_entry {
58681 + struct name_entry *nentry;
58682 + struct inodev_entry *prev;
58683 + struct inodev_entry *next;
58686 +struct acl_role_db {
58687 + struct acl_role_label **r_hash;
58691 +struct inodev_db {
58692 + struct inodev_entry **i_hash;
58697 + struct name_entry **n_hash;
58701 +struct crash_uid {
58703 + unsigned long expires;
58706 +struct gr_hash_struct {
58708 + void **nametable;
58710 + __u32 table_size;
58715 +/* Userspace Grsecurity ACL data structures */
58717 +struct acl_subject_label {
58722 + kernel_cap_t cap_mask;
58723 + kernel_cap_t cap_lower;
58724 + kernel_cap_t cap_invert_audit;
58726 + struct rlimit res[GR_NLIMITS];
58729 + __u8 user_trans_type;
58730 + __u8 group_trans_type;
58731 + uid_t *user_transitions;
58732 + gid_t *group_transitions;
58733 + __u16 user_trans_num;
58734 + __u16 group_trans_num;
58736 + __u32 sock_families[2];
58737 + __u32 ip_proto[8];
58739 + struct acl_ip_label **ips;
58741 + __u32 inaddr_any_override;
58744 + unsigned long expires;
58746 + struct acl_subject_label *parent_subject;
58747 + struct gr_hash_struct *hash;
58748 + struct acl_subject_label *prev;
58749 + struct acl_subject_label *next;
58751 + struct acl_object_label **obj_hash;
58752 + __u32 obj_hash_size;
58756 +struct role_allowed_ip {
58760 + struct role_allowed_ip *prev;
58761 + struct role_allowed_ip *next;
58764 +struct role_transition {
58767 + struct role_transition *prev;
58768 + struct role_transition *next;
58771 +struct acl_role_label {
58776 + __u16 auth_attempts;
58777 + unsigned long expires;
58779 + struct acl_subject_label *root_label;
58780 + struct gr_hash_struct *hash;
58782 + struct acl_role_label *prev;
58783 + struct acl_role_label *next;
58785 + struct role_transition *transitions;
58786 + struct role_allowed_ip *allowed_ips;
58787 + uid_t *domain_children;
58788 + __u16 domain_child_num;
58792 + struct acl_subject_label **subj_hash;
58793 + __u32 subj_hash_size;
58796 +struct user_acl_role_db {
58797 + struct acl_role_label **r_table;
58798 + __u32 num_pointers; /* Number of allocations to track */
58799 + __u32 num_roles; /* Number of roles */
58800 + __u32 num_domain_children; /* Number of domain children */
58801 + __u32 num_subjects; /* Number of subjects */
58802 + __u32 num_objects; /* Number of objects */
58805 +struct acl_object_label {
58811 + struct acl_subject_label *nested;
58812 + struct acl_object_label *globbed;
58814 + /* next two structures not used */
58816 + struct acl_object_label *prev;
58817 + struct acl_object_label *next;
58820 +struct acl_ip_label {
58829 + /* next two structures not used */
58831 + struct acl_ip_label *prev;
58832 + struct acl_ip_label *next;
58836 + struct user_acl_role_db role_db;
58837 + unsigned char pw[GR_PW_LEN];
58838 + unsigned char salt[GR_SALT_LEN];
58839 + unsigned char sum[GR_SHA_LEN];
58840 + unsigned char sp_role[GR_SPROLE_LEN];
58841 + struct sprole_pw *sprole_pws;
58842 + dev_t segv_device;
58843 + ino_t segv_inode;
58845 + __u16 num_sprole_pws;
58849 +struct gr_arg_wrapper {
58850 + struct gr_arg *arg;
58855 +struct subject_map {
58856 + struct acl_subject_label *user;
58857 + struct acl_subject_label *kernel;
58858 + struct subject_map *prev;
58859 + struct subject_map *next;
58862 +struct acl_subj_map_db {
58863 + struct subject_map **s_hash;
58867 +/* End Data Structures Section */
58869 +/* Hash functions generated by empirical testing by Brad Spengler
58870 + Makes good use of the low bits of the inode. Generally 0-1 times
58871 + in loop for successful match. 0-3 for unsuccessful match.
58872 + Shift/add algorithm with modulus of table size and an XOR*/
58874 +static __inline__ unsigned int
58875 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
58877 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
58880 + static __inline__ unsigned int
58881 +shash(const struct acl_subject_label *userp, const unsigned int sz)
58883 + return ((const unsigned long)userp % sz);
58886 +static __inline__ unsigned int
58887 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
58889 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
58892 +static __inline__ unsigned int
58893 +nhash(const char *name, const __u16 len, const unsigned int sz)
58895 + return full_name_hash((const unsigned char *)name, len) % sz;
58898 +#define FOR_EACH_ROLE_START(role) \
58899 + role = role_list; \
58902 +#define FOR_EACH_ROLE_END(role) \
58903 + role = role->prev; \
58906 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
58909 + while (iter < role->subj_hash_size) { \
58910 + if (subj == NULL) \
58911 + subj = role->subj_hash[iter]; \
58912 + if (subj == NULL) { \
58917 +#define FOR_EACH_SUBJECT_END(subj,iter) \
58918 + subj = subj->next; \
58919 + if (subj == NULL) \
58924 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
58925 + subj = role->hash->first; \
58926 + while (subj != NULL) {
58928 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
58929 + subj = subj->next; \
58934 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
58935 new file mode 100644
58936 index 0000000..323ecf2
58938 +++ b/include/linux/gralloc.h
58940 +#ifndef __GRALLOC_H
58941 +#define __GRALLOC_H
58943 +void acl_free_all(void);
58944 +int acl_alloc_stack_init(unsigned long size);
58945 +void *acl_alloc(unsigned long len);
58946 +void *acl_alloc_num(unsigned long num, unsigned long len);
58949 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
58950 new file mode 100644
58951 index 0000000..b30e9bc
58953 +++ b/include/linux/grdefs.h
58958 +/* Begin grsecurity status declarations */
58962 + GR_STATUS_INIT = 0x00 // disabled state
58965 +/* Begin ACL declarations */
58970 + GR_ROLE_USER = 0x0001,
58971 + GR_ROLE_GROUP = 0x0002,
58972 + GR_ROLE_DEFAULT = 0x0004,
58973 + GR_ROLE_SPECIAL = 0x0008,
58974 + GR_ROLE_AUTH = 0x0010,
58975 + GR_ROLE_NOPW = 0x0020,
58976 + GR_ROLE_GOD = 0x0040,
58977 + GR_ROLE_LEARN = 0x0080,
58978 + GR_ROLE_TPE = 0x0100,
58979 + GR_ROLE_DOMAIN = 0x0200,
58980 + GR_ROLE_PAM = 0x0400,
58981 + GR_ROLE_PERSIST = 0x0800
58984 +/* ACL Subject and Object mode flags */
58986 + GR_DELETED = 0x80000000
58989 +/* ACL Object-only mode flags */
58991 + GR_READ = 0x00000001,
58992 + GR_APPEND = 0x00000002,
58993 + GR_WRITE = 0x00000004,
58994 + GR_EXEC = 0x00000008,
58995 + GR_FIND = 0x00000010,
58996 + GR_INHERIT = 0x00000020,
58997 + GR_SETID = 0x00000040,
58998 + GR_CREATE = 0x00000080,
58999 + GR_DELETE = 0x00000100,
59000 + GR_LINK = 0x00000200,
59001 + GR_AUDIT_READ = 0x00000400,
59002 + GR_AUDIT_APPEND = 0x00000800,
59003 + GR_AUDIT_WRITE = 0x00001000,
59004 + GR_AUDIT_EXEC = 0x00002000,
59005 + GR_AUDIT_FIND = 0x00004000,
59006 + GR_AUDIT_INHERIT= 0x00008000,
59007 + GR_AUDIT_SETID = 0x00010000,
59008 + GR_AUDIT_CREATE = 0x00020000,
59009 + GR_AUDIT_DELETE = 0x00040000,
59010 + GR_AUDIT_LINK = 0x00080000,
59011 + GR_PTRACERD = 0x00100000,
59012 + GR_NOPTRACE = 0x00200000,
59013 + GR_SUPPRESS = 0x00400000,
59014 + GR_NOLEARN = 0x00800000,
59015 + GR_INIT_TRANSFER= 0x01000000
59018 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
59019 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
59020 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
59022 +/* ACL subject-only mode flags */
59024 + GR_KILL = 0x00000001,
59025 + GR_VIEW = 0x00000002,
59026 + GR_PROTECTED = 0x00000004,
59027 + GR_LEARN = 0x00000008,
59028 + GR_OVERRIDE = 0x00000010,
59029 + /* just a placeholder, this mode is only used in userspace */
59030 + GR_DUMMY = 0x00000020,
59031 + GR_PROTSHM = 0x00000040,
59032 + GR_KILLPROC = 0x00000080,
59033 + GR_KILLIPPROC = 0x00000100,
59034 + /* just a placeholder, this mode is only used in userspace */
59035 + GR_NOTROJAN = 0x00000200,
59036 + GR_PROTPROCFD = 0x00000400,
59037 + GR_PROCACCT = 0x00000800,
59038 + GR_RELAXPTRACE = 0x00001000,
59039 + GR_NESTED = 0x00002000,
59040 + GR_INHERITLEARN = 0x00004000,
59041 + GR_PROCFIND = 0x00008000,
59042 + GR_POVERRIDE = 0x00010000,
59043 + GR_KERNELAUTH = 0x00020000,
59044 + GR_ATSECURE = 0x00040000,
59045 + GR_SHMEXEC = 0x00080000
59049 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
59050 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
59051 + GR_PAX_ENABLE_MPROTECT = 0x0004,
59052 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
59053 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
59054 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
59055 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
59056 + GR_PAX_DISABLE_MPROTECT = 0x0400,
59057 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
59058 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
59062 + GR_ID_USER = 0x01,
59063 + GR_ID_GROUP = 0x02,
59067 + GR_ID_ALLOW = 0x01,
59068 + GR_ID_DENY = 0x02,
59071 +#define GR_CRASH_RES 31
59072 +#define GR_UIDTABLE_MAX 500
59074 +/* begin resource learning section */
59076 + GR_RLIM_CPU_BUMP = 60,
59077 + GR_RLIM_FSIZE_BUMP = 50000,
59078 + GR_RLIM_DATA_BUMP = 10000,
59079 + GR_RLIM_STACK_BUMP = 1000,
59080 + GR_RLIM_CORE_BUMP = 10000,
59081 + GR_RLIM_RSS_BUMP = 500000,
59082 + GR_RLIM_NPROC_BUMP = 1,
59083 + GR_RLIM_NOFILE_BUMP = 5,
59084 + GR_RLIM_MEMLOCK_BUMP = 50000,
59085 + GR_RLIM_AS_BUMP = 500000,
59086 + GR_RLIM_LOCKS_BUMP = 2,
59087 + GR_RLIM_SIGPENDING_BUMP = 5,
59088 + GR_RLIM_MSGQUEUE_BUMP = 10000,
59089 + GR_RLIM_NICE_BUMP = 1,
59090 + GR_RLIM_RTPRIO_BUMP = 1,
59091 + GR_RLIM_RTTIME_BUMP = 1000000
59095 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
59096 new file mode 100644
59097 index 0000000..da390f1
59099 +++ b/include/linux/grinternal.h
59101 +#ifndef __GRINTERNAL_H
59102 +#define __GRINTERNAL_H
59104 +#ifdef CONFIG_GRKERNSEC
59106 +#include <linux/fs.h>
59107 +#include <linux/mnt_namespace.h>
59108 +#include <linux/nsproxy.h>
59109 +#include <linux/gracl.h>
59110 +#include <linux/grdefs.h>
59111 +#include <linux/grmsg.h>
59113 +void gr_add_learn_entry(const char *fmt, ...)
59114 + __attribute__ ((format (printf, 1, 2)));
59115 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
59116 + const struct vfsmount *mnt);
59117 +__u32 gr_check_create(const struct dentry *new_dentry,
59118 + const struct dentry *parent,
59119 + const struct vfsmount *mnt, const __u32 mode);
59120 +int gr_check_protected_task(const struct task_struct *task);
59121 +__u32 to_gr_audit(const __u32 reqmode);
59122 +int gr_set_acls(const int type);
59123 +int gr_apply_subject_to_task(struct task_struct *task);
59124 +int gr_acl_is_enabled(void);
59125 +char gr_roletype_to_char(void);
59127 +void gr_handle_alertkill(struct task_struct *task);
59128 +char *gr_to_filename(const struct dentry *dentry,
59129 + const struct vfsmount *mnt);
59130 +char *gr_to_filename1(const struct dentry *dentry,
59131 + const struct vfsmount *mnt);
59132 +char *gr_to_filename2(const struct dentry *dentry,
59133 + const struct vfsmount *mnt);
59134 +char *gr_to_filename3(const struct dentry *dentry,
59135 + const struct vfsmount *mnt);
59137 +extern int grsec_enable_ptrace_readexec;
59138 +extern int grsec_enable_harden_ptrace;
59139 +extern int grsec_enable_link;
59140 +extern int grsec_enable_fifo;
59141 +extern int grsec_enable_execve;
59142 +extern int grsec_enable_shm;
59143 +extern int grsec_enable_execlog;
59144 +extern int grsec_enable_signal;
59145 +extern int grsec_enable_audit_ptrace;
59146 +extern int grsec_enable_forkfail;
59147 +extern int grsec_enable_time;
59148 +extern int grsec_enable_rofs;
59149 +extern int grsec_enable_chroot_shmat;
59150 +extern int grsec_enable_chroot_mount;
59151 +extern int grsec_enable_chroot_double;
59152 +extern int grsec_enable_chroot_pivot;
59153 +extern int grsec_enable_chroot_chdir;
59154 +extern int grsec_enable_chroot_chmod;
59155 +extern int grsec_enable_chroot_mknod;
59156 +extern int grsec_enable_chroot_fchdir;
59157 +extern int grsec_enable_chroot_nice;
59158 +extern int grsec_enable_chroot_execlog;
59159 +extern int grsec_enable_chroot_caps;
59160 +extern int grsec_enable_chroot_sysctl;
59161 +extern int grsec_enable_chroot_unix;
59162 +extern int grsec_enable_tpe;
59163 +extern int grsec_tpe_gid;
59164 +extern int grsec_enable_tpe_all;
59165 +extern int grsec_enable_tpe_invert;
59166 +extern int grsec_enable_socket_all;
59167 +extern int grsec_socket_all_gid;
59168 +extern int grsec_enable_socket_client;
59169 +extern int grsec_socket_client_gid;
59170 +extern int grsec_enable_socket_server;
59171 +extern int grsec_socket_server_gid;
59172 +extern int grsec_audit_gid;
59173 +extern int grsec_enable_group;
59174 +extern int grsec_enable_audit_textrel;
59175 +extern int grsec_enable_log_rwxmaps;
59176 +extern int grsec_enable_mount;
59177 +extern int grsec_enable_chdir;
59178 +extern int grsec_resource_logging;
59179 +extern int grsec_enable_blackhole;
59180 +extern int grsec_lastack_retries;
59181 +extern int grsec_enable_brute;
59182 +extern int grsec_lock;
59184 +extern spinlock_t grsec_alert_lock;
59185 +extern unsigned long grsec_alert_wtime;
59186 +extern unsigned long grsec_alert_fyet;
59188 +extern spinlock_t grsec_audit_lock;
59190 +extern rwlock_t grsec_exec_file_lock;
59192 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
59193 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
59194 + (tsk)->exec_file->f_vfsmnt) : "/")
59196 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
59197 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
59198 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
59200 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
59201 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
59202 + (tsk)->exec_file->f_vfsmnt) : "/")
59204 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
59205 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
59206 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
59208 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
59210 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
59212 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
59213 + (task)->pid, (cred)->uid, \
59214 + (cred)->euid, (cred)->gid, (cred)->egid, \
59215 + gr_parent_task_fullpath(task), \
59216 + (task)->real_parent->comm, (task)->real_parent->pid, \
59217 + (pcred)->uid, (pcred)->euid, \
59218 + (pcred)->gid, (pcred)->egid
59220 +#define GR_CHROOT_CAPS {{ \
59221 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
59222 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
59223 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
59224 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
59225 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
59226 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
59227 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
59229 +#define security_learn(normal_msg,args...) \
59231 + read_lock(&grsec_exec_file_lock); \
59232 + gr_add_learn_entry(normal_msg "\n", ## args); \
59233 + read_unlock(&grsec_exec_file_lock); \
59239 + /* used for non-audit messages that we shouldn't kill the task on */
59240 + GR_DONT_AUDIT_GOOD
59251 + GR_SYSCTL_HIDDEN,
59254 + GR_ONE_INT_TWO_STR,
59261 + GR_FIVE_INT_TWO_STR,
59267 + GR_FILENAME_TWO_INT,
59268 + GR_FILENAME_TWO_INT_STR,
59281 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
59282 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
59283 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
59284 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
59285 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
59286 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
59287 +#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)
59288 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
59289 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
59290 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
59291 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
59292 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
59293 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
59294 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
59295 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
59296 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
59297 +#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)
59298 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
59299 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
59300 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
59301 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
59302 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
59303 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
59304 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
59305 +#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)
59306 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
59307 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
59308 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
59309 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
59310 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
59311 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
59312 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
59313 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
59314 +#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)
59315 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
59317 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
59322 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
59323 new file mode 100644
59324 index 0000000..ae576a1
59326 +++ b/include/linux/grmsg.h
59328 +#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"
59329 +#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"
59330 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
59331 +#define GR_STOPMOD_MSG "denied modification of module state by "
59332 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
59333 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
59334 +#define GR_IOPERM_MSG "denied use of ioperm() by "
59335 +#define GR_IOPL_MSG "denied use of iopl() by "
59336 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
59337 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
59338 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
59339 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
59340 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
59341 +#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"
59342 +#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"
59343 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
59344 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
59345 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
59346 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
59347 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
59348 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
59349 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
59350 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
59351 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
59352 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
59353 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
59354 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
59355 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
59356 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
59357 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
59358 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
59359 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
59360 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
59361 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
59362 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
59363 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
59364 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
59365 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
59366 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
59367 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
59368 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
59369 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
59370 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
59371 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
59372 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
59373 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
59374 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
59375 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
59376 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
59377 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
59378 +#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"
59379 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
59380 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
59381 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
59382 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
59383 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
59384 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
59385 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
59386 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
59387 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
59388 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
59389 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
59390 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
59391 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
59392 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
59393 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
59394 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
59395 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
59396 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
59397 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
59398 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
59399 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
59400 +#define GR_NICE_CHROOT_MSG "denied priority change by "
59401 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
59402 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
59403 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
59404 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
59405 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
59406 +#define GR_TIME_MSG "time set by "
59407 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
59408 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
59409 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
59410 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
59411 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
59412 +#define GR_BIND_MSG "denied bind() by "
59413 +#define GR_CONNECT_MSG "denied connect() by "
59414 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
59415 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
59416 +#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"
59417 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
59418 +#define GR_CAP_ACL_MSG "use of %s denied for "
59419 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
59420 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
59421 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
59422 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
59423 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
59424 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
59425 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
59426 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
59427 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
59428 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
59429 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
59430 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
59431 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
59432 +#define GR_VM86_MSG "denied use of vm86 by "
59433 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
59434 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
59435 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
59436 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
59437 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
59438 new file mode 100644
59439 index 0000000..2ccf677
59441 +++ b/include/linux/grsecurity.h
59443 +#ifndef GR_SECURITY_H
59444 +#define GR_SECURITY_H
59445 +#include <linux/fs.h>
59446 +#include <linux/fs_struct.h>
59447 +#include <linux/binfmts.h>
59448 +#include <linux/gracl.h>
59450 +/* notify of brain-dead configs */
59451 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59452 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
59454 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
59455 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
59457 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
59458 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
59460 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
59461 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
59464 +#include <linux/compat.h>
59466 +struct user_arg_ptr {
59467 +#ifdef CONFIG_COMPAT
59471 + const char __user *const __user *native;
59472 +#ifdef CONFIG_COMPAT
59473 + compat_uptr_t __user *compat;
59478 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
59479 +void gr_handle_brute_check(void);
59480 +void gr_handle_kernel_exploit(void);
59481 +int gr_process_user_ban(void);
59483 +char gr_roletype_to_char(void);
59485 +int gr_acl_enable_at_secure(void);
59487 +int gr_check_user_change(int real, int effective, int fs);
59488 +int gr_check_group_change(int real, int effective, int fs);
59490 +void gr_del_task_from_ip_table(struct task_struct *p);
59492 +int gr_pid_is_chrooted(struct task_struct *p);
59493 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
59494 +int gr_handle_chroot_nice(void);
59495 +int gr_handle_chroot_sysctl(const int op);
59496 +int gr_handle_chroot_setpriority(struct task_struct *p,
59497 + const int niceval);
59498 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
59499 +int gr_handle_chroot_chroot(const struct dentry *dentry,
59500 + const struct vfsmount *mnt);
59501 +void gr_handle_chroot_chdir(struct path *path);
59502 +int gr_handle_chroot_chmod(const struct dentry *dentry,
59503 + const struct vfsmount *mnt, const int mode);
59504 +int gr_handle_chroot_mknod(const struct dentry *dentry,
59505 + const struct vfsmount *mnt, const int mode);
59506 +int gr_handle_chroot_mount(const struct dentry *dentry,
59507 + const struct vfsmount *mnt,
59508 + const char *dev_name);
59509 +int gr_handle_chroot_pivot(void);
59510 +int gr_handle_chroot_unix(const pid_t pid);
59512 +int gr_handle_rawio(const struct inode *inode);
59514 +void gr_handle_ioperm(void);
59515 +void gr_handle_iopl(void);
59517 +umode_t gr_acl_umask(void);
59519 +int gr_tpe_allow(const struct file *file);
59521 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
59522 +void gr_clear_chroot_entries(struct task_struct *task);
59524 +void gr_log_forkfail(const int retval);
59525 +void gr_log_timechange(void);
59526 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
59527 +void gr_log_chdir(const struct dentry *dentry,
59528 + const struct vfsmount *mnt);
59529 +void gr_log_chroot_exec(const struct dentry *dentry,
59530 + const struct vfsmount *mnt);
59531 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
59532 +void gr_log_remount(const char *devname, const int retval);
59533 +void gr_log_unmount(const char *devname, const int retval);
59534 +void gr_log_mount(const char *from, const char *to, const int retval);
59535 +void gr_log_textrel(struct vm_area_struct *vma);
59536 +void gr_log_rwxmmap(struct file *file);
59537 +void gr_log_rwxmprotect(struct file *file);
59539 +int gr_handle_follow_link(const struct inode *parent,
59540 + const struct inode *inode,
59541 + const struct dentry *dentry,
59542 + const struct vfsmount *mnt);
59543 +int gr_handle_fifo(const struct dentry *dentry,
59544 + const struct vfsmount *mnt,
59545 + const struct dentry *dir, const int flag,
59546 + const int acc_mode);
59547 +int gr_handle_hardlink(const struct dentry *dentry,
59548 + const struct vfsmount *mnt,
59549 + struct inode *inode,
59550 + const int mode, const char *to);
59552 +int gr_is_capable(const int cap);
59553 +int gr_is_capable_nolog(const int cap);
59554 +void gr_learn_resource(const struct task_struct *task, const int limit,
59555 + const unsigned long wanted, const int gt);
59556 +void gr_copy_label(struct task_struct *tsk);
59557 +void gr_handle_crash(struct task_struct *task, const int sig);
59558 +int gr_handle_signal(const struct task_struct *p, const int sig);
59559 +int gr_check_crash_uid(const uid_t uid);
59560 +int gr_check_protected_task(const struct task_struct *task);
59561 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
59562 +int gr_acl_handle_mmap(const struct file *file,
59563 + const unsigned long prot);
59564 +int gr_acl_handle_mprotect(const struct file *file,
59565 + const unsigned long prot);
59566 +int gr_check_hidden_task(const struct task_struct *tsk);
59567 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
59568 + const struct vfsmount *mnt);
59569 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
59570 + const struct vfsmount *mnt);
59571 +__u32 gr_acl_handle_access(const struct dentry *dentry,
59572 + const struct vfsmount *mnt, const int fmode);
59573 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
59574 + const struct vfsmount *mnt, umode_t *mode);
59575 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
59576 + const struct vfsmount *mnt);
59577 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
59578 + const struct vfsmount *mnt);
59579 +int gr_handle_ptrace(struct task_struct *task, const long request);
59580 +int gr_handle_proc_ptrace(struct task_struct *task);
59581 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
59582 + const struct vfsmount *mnt);
59583 +int gr_check_crash_exec(const struct file *filp);
59584 +int gr_acl_is_enabled(void);
59585 +void gr_set_kernel_label(struct task_struct *task);
59586 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
59587 + const gid_t gid);
59588 +int gr_set_proc_label(const struct dentry *dentry,
59589 + const struct vfsmount *mnt,
59590 + const int unsafe_flags);
59591 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
59592 + const struct vfsmount *mnt);
59593 +__u32 gr_acl_handle_open(const struct dentry *dentry,
59594 + const struct vfsmount *mnt, int acc_mode);
59595 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
59596 + const struct dentry *p_dentry,
59597 + const struct vfsmount *p_mnt,
59598 + int open_flags, int acc_mode, const int imode);
59599 +void gr_handle_create(const struct dentry *dentry,
59600 + const struct vfsmount *mnt);
59601 +void gr_handle_proc_create(const struct dentry *dentry,
59602 + const struct inode *inode);
59603 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
59604 + const struct dentry *parent_dentry,
59605 + const struct vfsmount *parent_mnt,
59607 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
59608 + const struct dentry *parent_dentry,
59609 + const struct vfsmount *parent_mnt);
59610 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
59611 + const struct vfsmount *mnt);
59612 +void gr_handle_delete(const ino_t ino, const dev_t dev);
59613 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
59614 + const struct vfsmount *mnt);
59615 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
59616 + const struct dentry *parent_dentry,
59617 + const struct vfsmount *parent_mnt,
59618 + const char *from);
59619 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
59620 + const struct dentry *parent_dentry,
59621 + const struct vfsmount *parent_mnt,
59622 + const struct dentry *old_dentry,
59623 + const struct vfsmount *old_mnt, const char *to);
59624 +int gr_acl_handle_rename(struct dentry *new_dentry,
59625 + struct dentry *parent_dentry,
59626 + const struct vfsmount *parent_mnt,
59627 + struct dentry *old_dentry,
59628 + struct inode *old_parent_inode,
59629 + struct vfsmount *old_mnt, const char *newname);
59630 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59631 + struct dentry *old_dentry,
59632 + struct dentry *new_dentry,
59633 + struct vfsmount *mnt, const __u8 replace);
59634 +__u32 gr_check_link(const struct dentry *new_dentry,
59635 + const struct dentry *parent_dentry,
59636 + const struct vfsmount *parent_mnt,
59637 + const struct dentry *old_dentry,
59638 + const struct vfsmount *old_mnt);
59639 +int gr_acl_handle_filldir(const struct file *file, const char *name,
59640 + const unsigned int namelen, const ino_t ino);
59642 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
59643 + const struct vfsmount *mnt);
59644 +void gr_acl_handle_exit(void);
59645 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
59646 +int gr_acl_handle_procpidmem(const struct task_struct *task);
59647 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
59648 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
59649 +void gr_audit_ptrace(struct task_struct *task);
59650 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
59652 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
59654 +#ifdef CONFIG_GRKERNSEC
59655 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
59656 +void gr_handle_vm86(void);
59657 +void gr_handle_mem_readwrite(u64 from, u64 to);
59659 +void gr_log_badprocpid(const char *entry);
59661 +extern int grsec_enable_dmesg;
59662 +extern int grsec_disable_privio;
59663 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59664 +extern int grsec_enable_chroot_findtask;
59666 +#ifdef CONFIG_GRKERNSEC_SETXID
59667 +extern int grsec_enable_setxid;
59672 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
59673 new file mode 100644
59674 index 0000000..e7ffaaf
59676 +++ b/include/linux/grsock.h
59678 +#ifndef __GRSOCK_H
59679 +#define __GRSOCK_H
59681 +extern void gr_attach_curr_ip(const struct sock *sk);
59682 +extern int gr_handle_sock_all(const int family, const int type,
59683 + const int protocol);
59684 +extern int gr_handle_sock_server(const struct sockaddr *sck);
59685 +extern int gr_handle_sock_server_other(const struct sock *sck);
59686 +extern int gr_handle_sock_client(const struct sockaddr *sck);
59687 +extern int gr_search_connect(struct socket * sock,
59688 + struct sockaddr_in * addr);
59689 +extern int gr_search_bind(struct socket * sock,
59690 + struct sockaddr_in * addr);
59691 +extern int gr_search_listen(struct socket * sock);
59692 +extern int gr_search_accept(struct socket * sock);
59693 +extern int gr_search_socket(const int domain, const int type,
59694 + const int protocol);
59697 diff --git a/include/linux/hid.h b/include/linux/hid.h
59698 index c235e4e..f0cf7a0 100644
59699 --- a/include/linux/hid.h
59700 +++ b/include/linux/hid.h
59701 @@ -679,7 +679,7 @@ struct hid_ll_driver {
59702 unsigned int code, int value);
59704 int (*parse)(struct hid_device *hdev);
59708 #define PM_HINT_FULLON 1<<5
59709 #define PM_HINT_NORMAL 1<<1
59710 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
59711 index 3a93f73..b19d0b3 100644
59712 --- a/include/linux/highmem.h
59713 +++ b/include/linux/highmem.h
59714 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
59715 kunmap_atomic(kaddr, KM_USER0);
59718 +static inline void sanitize_highpage(struct page *page)
59721 + unsigned long flags;
59723 + local_irq_save(flags);
59724 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
59725 + clear_page(kaddr);
59726 + kunmap_atomic(kaddr, KM_CLEARPAGE);
59727 + local_irq_restore(flags);
59730 static inline void zero_user_segments(struct page *page,
59731 unsigned start1, unsigned end1,
59732 unsigned start2, unsigned end2)
59733 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
59734 index 07d103a..04ec65b 100644
59735 --- a/include/linux/i2c.h
59736 +++ b/include/linux/i2c.h
59737 @@ -364,6 +364,7 @@ struct i2c_algorithm {
59738 /* To determine what the adapter supports */
59739 u32 (*functionality) (struct i2c_adapter *);
59741 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
59744 * i2c_adapter is the structure used to identify a physical i2c bus along
59745 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
59746 index a6deef4..c56a7f2 100644
59747 --- a/include/linux/i2o.h
59748 +++ b/include/linux/i2o.h
59749 @@ -564,7 +564,7 @@ struct i2o_controller {
59750 struct i2o_device *exec; /* Executive */
59751 #if BITS_PER_LONG == 64
59752 spinlock_t context_list_lock; /* lock for context_list */
59753 - atomic_t context_list_counter; /* needed for unique contexts */
59754 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
59755 struct list_head context_list; /* list of context id's
59758 diff --git a/include/linux/init.h b/include/linux/init.h
59759 index 9146f39..885354d 100644
59760 --- a/include/linux/init.h
59761 +++ b/include/linux/init.h
59762 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
59764 /* Each module must use one module_init(). */
59765 #define module_init(initfn) \
59766 - static inline initcall_t __inittest(void) \
59767 + static inline __used initcall_t __inittest(void) \
59768 { return initfn; } \
59769 int init_module(void) __attribute__((alias(#initfn)));
59771 /* This is only required if you want to be unloadable. */
59772 #define module_exit(exitfn) \
59773 - static inline exitcall_t __exittest(void) \
59774 + static inline __used exitcall_t __exittest(void) \
59775 { return exitfn; } \
59776 void cleanup_module(void) __attribute__((alias(#exitfn)));
59778 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
59779 index 32574ee..00d4ef1 100644
59780 --- a/include/linux/init_task.h
59781 +++ b/include/linux/init_task.h
59782 @@ -128,6 +128,12 @@ extern struct cred init_cred;
59784 #define INIT_TASK_COMM "swapper"
59787 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
59789 +#define INIT_TASK_THREAD_INFO
59793 * INIT_TASK is used to set up the first task table, touch at
59794 * your own risk!. Base=0, limit=0x1fffff (=2MB)
59795 @@ -166,6 +172,7 @@ extern struct cred init_cred;
59796 RCU_INIT_POINTER(.cred, &init_cred), \
59797 .comm = INIT_TASK_COMM, \
59798 .thread = INIT_THREAD, \
59799 + INIT_TASK_THREAD_INFO \
59801 .files = &init_files, \
59802 .signal = &init_signals, \
59803 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
59804 index e6ca56d..8583707 100644
59805 --- a/include/linux/intel-iommu.h
59806 +++ b/include/linux/intel-iommu.h
59807 @@ -296,7 +296,7 @@ struct iommu_flush {
59809 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
59810 unsigned int size_order, u64 type);
59816 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
59817 index a64b00e..464d8bc 100644
59818 --- a/include/linux/interrupt.h
59819 +++ b/include/linux/interrupt.h
59820 @@ -441,7 +441,7 @@ enum
59821 /* map softirq index to softirq name. update 'softirq_to_name' in
59822 * kernel/softirq.c when adding a new softirq.
59824 -extern char *softirq_to_name[NR_SOFTIRQS];
59825 +extern const char * const softirq_to_name[NR_SOFTIRQS];
59827 /* softirq mask and active fields moved to irq_cpustat_t in
59828 * asm/hardirq.h to get better cache usage. KAO
59829 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
59831 struct softirq_action
59833 - void (*action)(struct softirq_action *);
59834 + void (*action)(void);
59837 asmlinkage void do_softirq(void);
59838 asmlinkage void __do_softirq(void);
59839 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
59840 +extern void open_softirq(int nr, void (*action)(void));
59841 extern void softirq_init(void);
59842 static inline void __raise_softirq_irqoff(unsigned int nr)
59844 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
59845 index 3875719..4cd454c 100644
59846 --- a/include/linux/kallsyms.h
59847 +++ b/include/linux/kallsyms.h
59852 -#ifdef CONFIG_KALLSYMS
59853 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
59854 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59855 /* Lookup the address for a symbol. Returns 0 if not found. */
59856 unsigned long kallsyms_lookup_name(const char *name);
59858 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
59859 /* Stupid that this does nothing, but I didn't create this mess. */
59860 #define __print_symbol(fmt, addr)
59861 #endif /*CONFIG_KALLSYMS*/
59862 +#else /* when included by kallsyms.c, vsnprintf.c, or
59863 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
59864 +extern void __print_symbol(const char *fmt, unsigned long address);
59865 +extern int sprint_backtrace(char *buffer, unsigned long address);
59866 +extern int sprint_symbol(char *buffer, unsigned long address);
59867 +const char *kallsyms_lookup(unsigned long addr,
59868 + unsigned long *symbolsize,
59869 + unsigned long *offset,
59870 + char **modname, char *namebuf);
59873 /* This macro allows us to keep printk typechecking */
59874 static __printf(1, 2)
59875 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
59876 index fa39183..40160be 100644
59877 --- a/include/linux/kgdb.h
59878 +++ b/include/linux/kgdb.h
59879 @@ -53,7 +53,7 @@ extern int kgdb_connected;
59880 extern int kgdb_io_module_registered;
59882 extern atomic_t kgdb_setting_breakpoint;
59883 -extern atomic_t kgdb_cpu_doing_single_step;
59884 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
59886 extern struct task_struct *kgdb_usethread;
59887 extern struct task_struct *kgdb_contthread;
59888 @@ -251,7 +251,7 @@ struct kgdb_arch {
59889 void (*disable_hw_break)(struct pt_regs *regs);
59890 void (*remove_all_hw_break)(void);
59891 void (*correct_hw_break)(void);
59896 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
59897 @@ -276,7 +276,7 @@ struct kgdb_io {
59898 void (*pre_exception) (void);
59899 void (*post_exception) (void);
59904 extern struct kgdb_arch arch_kgdb_ops;
59906 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
59907 index b16f653..eb908f4 100644
59908 --- a/include/linux/kmod.h
59909 +++ b/include/linux/kmod.h
59910 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
59911 * usually useless though. */
59912 extern __printf(2, 3)
59913 int __request_module(bool wait, const char *name, ...);
59914 +extern __printf(3, 4)
59915 +int ___request_module(bool wait, char *param_name, const char *name, ...);
59916 #define request_module(mod...) __request_module(true, mod)
59917 #define request_module_nowait(mod...) __request_module(false, mod)
59918 #define try_then_request_module(x, mod...) \
59919 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
59920 index d526231..086e89b 100644
59921 --- a/include/linux/kvm_host.h
59922 +++ b/include/linux/kvm_host.h
59923 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
59924 void vcpu_load(struct kvm_vcpu *vcpu);
59925 void vcpu_put(struct kvm_vcpu *vcpu);
59927 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59928 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59929 struct module *module);
59930 void kvm_exit(void);
59932 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
59933 struct kvm_guest_debug *dbg);
59934 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
59936 -int kvm_arch_init(void *opaque);
59937 +int kvm_arch_init(const void *opaque);
59938 void kvm_arch_exit(void);
59940 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
59941 diff --git a/include/linux/libata.h b/include/linux/libata.h
59942 index cafc09a..d7e7829 100644
59943 --- a/include/linux/libata.h
59944 +++ b/include/linux/libata.h
59945 @@ -909,7 +909,7 @@ struct ata_port_operations {
59946 * fields must be pointers.
59948 const struct ata_port_operations *inherits;
59952 struct ata_port_info {
59953 unsigned long flags;
59954 diff --git a/include/linux/mca.h b/include/linux/mca.h
59955 index 3797270..7765ede 100644
59956 --- a/include/linux/mca.h
59957 +++ b/include/linux/mca.h
59958 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
59960 void * (*mca_transform_memory)(struct mca_device *,
59966 u64 default_dma_mask;
59967 diff --git a/include/linux/memory.h b/include/linux/memory.h
59968 index 935699b..11042cc 100644
59969 --- a/include/linux/memory.h
59970 +++ b/include/linux/memory.h
59971 @@ -144,7 +144,7 @@ struct memory_accessor {
59973 ssize_t (*write)(struct memory_accessor *, const char *buf,
59974 off_t offset, size_t count);
59979 * Kernel text modification mutex, used for code patching. Users of this lock
59980 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
59981 index 9970337..9444122 100644
59982 --- a/include/linux/mfd/abx500.h
59983 +++ b/include/linux/mfd/abx500.h
59984 @@ -188,6 +188,7 @@ struct abx500_ops {
59985 int (*event_registers_startup_state_get) (struct device *, u8 *);
59986 int (*startup_irq_enabled) (struct device *, unsigned int);
59988 +typedef struct abx500_ops __no_const abx500_ops_no_const;
59990 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
59991 void abx500_remove_ops(struct device *dev);
59992 diff --git a/include/linux/mm.h b/include/linux/mm.h
59993 index 4baadd1..2e0b45e 100644
59994 --- a/include/linux/mm.h
59995 +++ b/include/linux/mm.h
59996 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
59998 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
59999 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
60001 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
60002 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
60003 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
60005 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
60008 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
60009 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
60011 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
60012 int set_page_dirty_lock(struct page *page);
60013 int clear_page_dirty_for_io(struct page *page);
60015 -/* Is the vma a continuation of the stack vma above it? */
60016 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
60018 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
60021 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
60022 - unsigned long addr)
60024 - return (vma->vm_flags & VM_GROWSDOWN) &&
60025 - (vma->vm_start == addr) &&
60026 - !vma_growsdown(vma->vm_prev, addr);
60029 -/* Is the vma a continuation of the stack vma below it? */
60030 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
60032 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
60035 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
60036 - unsigned long addr)
60038 - return (vma->vm_flags & VM_GROWSUP) &&
60039 - (vma->vm_end == addr) &&
60040 - !vma_growsup(vma->vm_next, addr);
60043 extern unsigned long move_page_tables(struct vm_area_struct *vma,
60044 unsigned long old_addr, struct vm_area_struct *new_vma,
60045 unsigned long new_addr, unsigned long len);
60046 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
60051 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
60053 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
60055 + return __pgprot(0);
60059 int vma_wants_writenotify(struct vm_area_struct *vma);
60061 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
60062 @@ -1419,6 +1407,7 @@ out:
60065 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
60066 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
60068 extern unsigned long do_brk(unsigned long, unsigned long);
60070 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
60071 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
60072 struct vm_area_struct **pprev);
60074 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
60075 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
60076 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
60078 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
60079 NULL if none. Assume start_addr < end_addr. */
60080 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
60081 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
60082 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
60086 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
60088 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
60090 - return __pgprot(0);
60094 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
60095 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
60096 unsigned long pfn, unsigned long size, pgprot_t);
60097 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
60098 extern int sysctl_memory_failure_early_kill;
60099 extern int sysctl_memory_failure_recovery;
60100 extern void shake_page(struct page *p, int access);
60101 -extern atomic_long_t mce_bad_pages;
60102 +extern atomic_long_unchecked_t mce_bad_pages;
60103 extern int soft_offline_page(struct page *page, int flags);
60105 extern void dump_page(struct page *page);
60106 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
60107 unsigned int pages_per_huge_page);
60108 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
60110 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60111 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
60113 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
60116 #endif /* __KERNEL__ */
60117 #endif /* _LINUX_MM_H */
60118 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
60119 index 5b42f1b..759e4b4 100644
60120 --- a/include/linux/mm_types.h
60121 +++ b/include/linux/mm_types.h
60122 @@ -253,6 +253,8 @@ struct vm_area_struct {
60124 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
60127 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
60130 struct core_thread {
60131 @@ -389,6 +391,24 @@ struct mm_struct {
60132 #ifdef CONFIG_CPUMASK_OFFSTACK
60133 struct cpumask cpumask_allocation;
60136 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60137 + unsigned long pax_flags;
60140 +#ifdef CONFIG_PAX_DLRESOLVE
60141 + unsigned long call_dl_resolve;
60144 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60145 + unsigned long call_syscall;
60148 +#ifdef CONFIG_PAX_ASLR
60149 + unsigned long delta_mmap; /* randomized offset */
60150 + unsigned long delta_stack; /* randomized offset */
60155 static inline void mm_init_cpumask(struct mm_struct *mm)
60156 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
60157 index 1d1b1e1..2a13c78 100644
60158 --- a/include/linux/mmu_notifier.h
60159 +++ b/include/linux/mmu_notifier.h
60160 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
60162 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
60166 struct vm_area_struct *___vma = __vma; \
60167 unsigned long ___address = __address; \
60168 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
60169 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
60170 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
60175 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
60176 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
60177 index 188cb2f..d78409b 100644
60178 --- a/include/linux/mmzone.h
60179 +++ b/include/linux/mmzone.h
60180 @@ -369,7 +369,7 @@ struct zone {
60181 unsigned long flags; /* zone flags, see below */
60183 /* Zone statistics */
60184 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
60185 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
60188 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
60189 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
60190 index 468819c..17b9db3 100644
60191 --- a/include/linux/mod_devicetable.h
60192 +++ b/include/linux/mod_devicetable.h
60194 typedef unsigned long kernel_ulong_t;
60197 -#define PCI_ANY_ID (~0)
60198 +#define PCI_ANY_ID ((__u16)~0)
60200 struct pci_device_id {
60201 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
60202 @@ -131,7 +131,7 @@ struct usb_device_id {
60203 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
60204 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
60206 -#define HID_ANY_ID (~0)
60207 +#define HID_ANY_ID (~0U)
60209 struct hid_device_id {
60211 diff --git a/include/linux/module.h b/include/linux/module.h
60212 index 3cb7839..511cb87 100644
60213 --- a/include/linux/module.h
60214 +++ b/include/linux/module.h
60216 #include <linux/moduleparam.h>
60217 #include <linux/tracepoint.h>
60218 #include <linux/export.h>
60219 +#include <linux/fs.h>
60221 #include <linux/percpu.h>
60222 #include <asm/module.h>
60223 @@ -261,19 +262,16 @@ struct module
60226 /* If this is non-NULL, vfree after init() returns */
60227 - void *module_init;
60228 + void *module_init_rx, *module_init_rw;
60230 /* Here is the actual code + data, vfree'd on unload. */
60231 - void *module_core;
60232 + void *module_core_rx, *module_core_rw;
60234 /* Here are the sizes of the init and core sections */
60235 - unsigned int init_size, core_size;
60236 + unsigned int init_size_rw, core_size_rw;
60238 /* The size of the executable code in each section. */
60239 - unsigned int init_text_size, core_text_size;
60241 - /* Size of RO sections of the module (text+rodata) */
60242 - unsigned int init_ro_size, core_ro_size;
60243 + unsigned int init_size_rx, core_size_rx;
60245 /* Arch-specific module values */
60246 struct mod_arch_specific arch;
60247 @@ -329,6 +327,10 @@ struct module
60248 #ifdef CONFIG_EVENT_TRACING
60249 struct ftrace_event_call **trace_events;
60250 unsigned int num_trace_events;
60251 + struct file_operations trace_id;
60252 + struct file_operations trace_enable;
60253 + struct file_operations trace_format;
60254 + struct file_operations trace_filter;
60256 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
60257 unsigned int num_ftrace_callsites;
60258 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
60259 bool is_module_percpu_address(unsigned long addr);
60260 bool is_module_text_address(unsigned long addr);
60262 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
60265 +#ifdef CONFIG_PAX_KERNEXEC
60266 + if (ktla_ktva(addr) >= (unsigned long)start &&
60267 + ktla_ktva(addr) < (unsigned long)start + size)
60271 + return ((void *)addr >= start && (void *)addr < start + size);
60274 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
60276 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
60279 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
60281 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
60284 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
60286 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
60289 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
60291 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
60294 static inline int within_module_core(unsigned long addr, struct module *mod)
60296 - return (unsigned long)mod->module_core <= addr &&
60297 - addr < (unsigned long)mod->module_core + mod->core_size;
60298 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
60301 static inline int within_module_init(unsigned long addr, struct module *mod)
60303 - return (unsigned long)mod->module_init <= addr &&
60304 - addr < (unsigned long)mod->module_init + mod->init_size;
60305 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
60308 /* Search for module by name: must hold module_mutex. */
60309 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
60310 index b2be02e..6a9fdb1 100644
60311 --- a/include/linux/moduleloader.h
60312 +++ b/include/linux/moduleloader.h
60313 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
60314 sections. Returns NULL on failure. */
60315 void *module_alloc(unsigned long size);
60317 +#ifdef CONFIG_PAX_KERNEXEC
60318 +void *module_alloc_exec(unsigned long size);
60320 +#define module_alloc_exec(x) module_alloc(x)
60323 /* Free memory returned from module_alloc. */
60324 void module_free(struct module *mod, void *module_region);
60326 +#ifdef CONFIG_PAX_KERNEXEC
60327 +void module_free_exec(struct module *mod, void *module_region);
60329 +#define module_free_exec(x, y) module_free((x), (y))
60332 /* Apply the given relocation to the (simplified) ELF. Return -error
60334 int apply_relocate(Elf_Shdr *sechdrs,
60335 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
60336 index 7939f63..ec6df57 100644
60337 --- a/include/linux/moduleparam.h
60338 +++ b/include/linux/moduleparam.h
60339 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
60340 * @len is usually just sizeof(string).
60342 #define module_param_string(name, string, len, perm) \
60343 - static const struct kparam_string __param_string_##name \
60344 + static const struct kparam_string __param_string_##name __used \
60345 = { len, string }; \
60346 __module_param_call(MODULE_PARAM_PREFIX, name, \
60347 ¶m_ops_string, \
60348 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
60349 * module_param_named() for why this might be necessary.
60351 #define module_param_array_named(name, array, type, nump, perm) \
60352 - static const struct kparam_array __param_arr_##name \
60353 + static const struct kparam_array __param_arr_##name __used \
60354 = { .max = ARRAY_SIZE(array), .num = nump, \
60355 .ops = ¶m_ops_##type, \
60356 .elemsize = sizeof(array[0]), .elem = array }; \
60357 diff --git a/include/linux/namei.h b/include/linux/namei.h
60358 index ffc0213..2c1f2cb 100644
60359 --- a/include/linux/namei.h
60360 +++ b/include/linux/namei.h
60361 @@ -24,7 +24,7 @@ struct nameidata {
60365 - char *saved_names[MAX_NESTED_LINKS + 1];
60366 + const char *saved_names[MAX_NESTED_LINKS + 1];
60370 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
60371 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
60372 extern void unlock_rename(struct dentry *, struct dentry *);
60374 -static inline void nd_set_link(struct nameidata *nd, char *path)
60375 +static inline void nd_set_link(struct nameidata *nd, const char *path)
60377 nd->saved_names[nd->depth] = path;
60380 -static inline char *nd_get_link(struct nameidata *nd)
60381 +static inline const char *nd_get_link(const struct nameidata *nd)
60383 return nd->saved_names[nd->depth];
60385 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
60386 index a82ad4d..90d15b7 100644
60387 --- a/include/linux/netdevice.h
60388 +++ b/include/linux/netdevice.h
60389 @@ -949,6 +949,7 @@ struct net_device_ops {
60390 int (*ndo_set_features)(struct net_device *dev,
60393 +typedef struct net_device_ops __no_const net_device_ops_no_const;
60396 * The DEVICE structure.
60397 @@ -1088,7 +1089,7 @@ struct net_device {
60400 struct net_device_stats stats;
60401 - atomic_long_t rx_dropped; /* dropped packets by core network
60402 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
60403 * Do not use this in drivers.
60406 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
60407 new file mode 100644
60408 index 0000000..33f4af8
60410 +++ b/include/linux/netfilter/xt_gradm.h
60412 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
60413 +#define _LINUX_NETFILTER_XT_GRADM_H 1
60415 +struct xt_gradm_mtinfo {
60421 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
60422 index c65a18a..0c05f3a 100644
60423 --- a/include/linux/of_pdt.h
60424 +++ b/include/linux/of_pdt.h
60425 @@ -32,7 +32,7 @@ struct of_pdt_ops {
60427 /* return 0 on success; fill in 'len' with number of bytes in path */
60428 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
60432 extern void *prom_early_alloc(unsigned long size);
60434 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
60435 index a4c5624..79d6d88 100644
60436 --- a/include/linux/oprofile.h
60437 +++ b/include/linux/oprofile.h
60438 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
60439 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
60440 char const * name, ulong * val);
60442 -/** Create a file for read-only access to an atomic_t. */
60443 +/** Create a file for read-only access to an atomic_unchecked_t. */
60444 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
60445 - char const * name, atomic_t * val);
60446 + char const * name, atomic_unchecked_t * val);
60448 /** create a directory */
60449 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
60450 diff --git a/include/linux/padata.h b/include/linux/padata.h
60451 index 4633b2f..988bc08 100644
60452 --- a/include/linux/padata.h
60453 +++ b/include/linux/padata.h
60454 @@ -129,7 +129,7 @@ struct parallel_data {
60455 struct padata_instance *pinst;
60456 struct padata_parallel_queue __percpu *pqueue;
60457 struct padata_serial_queue __percpu *squeue;
60459 + atomic_unchecked_t seq_nr;
60460 atomic_t reorder_objects;
60462 unsigned int max_seq_nr;
60463 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
60464 index b1f8912..c955bff 100644
60465 --- a/include/linux/perf_event.h
60466 +++ b/include/linux/perf_event.h
60467 @@ -748,8 +748,8 @@ struct perf_event {
60469 enum perf_event_active_state state;
60470 unsigned int attach_state;
60472 - atomic64_t child_count;
60473 + local64_t count; /* PaX: fix it one day */
60474 + atomic64_unchecked_t child_count;
60477 * These are the total time in nanoseconds that the event
60478 @@ -800,8 +800,8 @@ struct perf_event {
60479 * These accumulate total time (in nanoseconds) that children
60480 * events have been enabled and running, respectively.
60482 - atomic64_t child_total_time_enabled;
60483 - atomic64_t child_total_time_running;
60484 + atomic64_unchecked_t child_total_time_enabled;
60485 + atomic64_unchecked_t child_total_time_running;
60488 * Protect attach/detach and child_list:
60489 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
60490 index 77257c9..51d473a 100644
60491 --- a/include/linux/pipe_fs_i.h
60492 +++ b/include/linux/pipe_fs_i.h
60493 @@ -46,9 +46,9 @@ struct pipe_buffer {
60494 struct pipe_inode_info {
60495 wait_queue_head_t wait;
60496 unsigned int nrbufs, curbuf, buffers;
60497 - unsigned int readers;
60498 - unsigned int writers;
60499 - unsigned int waiting_writers;
60500 + atomic_t readers;
60501 + atomic_t writers;
60502 + atomic_t waiting_writers;
60503 unsigned int r_counter;
60504 unsigned int w_counter;
60505 struct page *tmp_page;
60506 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
60507 index d3085e7..fd01052 100644
60508 --- a/include/linux/pm_runtime.h
60509 +++ b/include/linux/pm_runtime.h
60510 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
60512 static inline void pm_runtime_mark_last_busy(struct device *dev)
60514 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
60515 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
60518 #else /* !CONFIG_PM_RUNTIME */
60519 diff --git a/include/linux/poison.h b/include/linux/poison.h
60520 index 79159de..f1233a9 100644
60521 --- a/include/linux/poison.h
60522 +++ b/include/linux/poison.h
60524 * under normal circumstances, used to verify that nobody uses
60525 * non-initialized list entries.
60527 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
60528 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
60529 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
60530 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
60532 /********** include/linux/timer.h **********/
60534 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
60535 index 58969b2..ead129b 100644
60536 --- a/include/linux/preempt.h
60537 +++ b/include/linux/preempt.h
60538 @@ -123,7 +123,7 @@ struct preempt_ops {
60539 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
60540 void (*sched_out)(struct preempt_notifier *notifier,
60541 struct task_struct *next);
60546 * preempt_notifier - key for installing preemption notifiers
60547 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
60548 index 643b96c..ef55a9c 100644
60549 --- a/include/linux/proc_fs.h
60550 +++ b/include/linux/proc_fs.h
60551 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
60552 return proc_create_data(name, mode, parent, proc_fops, NULL);
60555 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
60556 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
60558 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60559 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
60560 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60561 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
60563 + return proc_create_data(name, mode, parent, proc_fops, NULL);
60568 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
60569 mode_t mode, struct proc_dir_entry *base,
60570 read_proc_t *read_proc, void * data)
60571 @@ -258,7 +271,7 @@ union proc_op {
60572 int (*proc_show)(struct seq_file *m,
60573 struct pid_namespace *ns, struct pid *pid,
60574 struct task_struct *task);
60578 struct ctl_table_header;
60580 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
60581 index 800f113..e9ee2e3 100644
60582 --- a/include/linux/ptrace.h
60583 +++ b/include/linux/ptrace.h
60584 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
60585 extern void exit_ptrace(struct task_struct *tracer);
60586 #define PTRACE_MODE_READ 1
60587 #define PTRACE_MODE_ATTACH 2
60588 -/* Returns 0 on success, -errno on denial. */
60589 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
60590 /* Returns true on success, false on denial. */
60591 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
60592 +/* Returns true on success, false on denial. */
60593 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
60594 +/* Returns true on success, false on denial. */
60595 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
60597 static inline int ptrace_reparented(struct task_struct *child)
60599 diff --git a/include/linux/random.h b/include/linux/random.h
60600 index 8f74538..02a1012 100644
60601 --- a/include/linux/random.h
60602 +++ b/include/linux/random.h
60603 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
60605 u32 prandom32(struct rnd_state *);
60607 +static inline unsigned long pax_get_random_long(void)
60609 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
60613 * Handle minimum values for seeds
60615 static inline u32 __seed(u32 x, u32 m)
60617 - return (x < m) ? x + m : x;
60618 + return (x <= m) ? x + m + 1 : x;
60622 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
60623 index e0879a7..a12f962 100644
60624 --- a/include/linux/reboot.h
60625 +++ b/include/linux/reboot.h
60626 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
60627 * Architecture-specific implementations of sys_reboot commands.
60630 -extern void machine_restart(char *cmd);
60631 -extern void machine_halt(void);
60632 -extern void machine_power_off(void);
60633 +extern void machine_restart(char *cmd) __noreturn;
60634 +extern void machine_halt(void) __noreturn;
60635 +extern void machine_power_off(void) __noreturn;
60637 extern void machine_shutdown(void);
60639 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
60642 extern void kernel_restart_prepare(char *cmd);
60643 -extern void kernel_restart(char *cmd);
60644 -extern void kernel_halt(void);
60645 -extern void kernel_power_off(void);
60646 +extern void kernel_restart(char *cmd) __noreturn;
60647 +extern void kernel_halt(void) __noreturn;
60648 +extern void kernel_power_off(void) __noreturn;
60650 extern int C_A_D; /* for sysctl */
60651 void ctrl_alt_del(void);
60652 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
60653 * Emergency restart, callable from an interrupt handler.
60656 -extern void emergency_restart(void);
60657 +extern void emergency_restart(void) __noreturn;
60658 #include <asm/emergency-restart.h>
60661 diff --git a/include/linux/regset.h b/include/linux/regset.h
60662 index 8abee65..5150fd1 100644
60663 --- a/include/linux/regset.h
60664 +++ b/include/linux/regset.h
60665 @@ -335,6 +335,9 @@ static inline int copy_regset_to_user(struct task_struct *target,
60667 const struct user_regset *regset = &view->regsets[setno];
60669 + if (!regset->get)
60670 + return -EOPNOTSUPP;
60672 if (!access_ok(VERIFY_WRITE, data, size))
60675 @@ -358,6 +361,9 @@ static inline int copy_regset_from_user(struct task_struct *target,
60677 const struct user_regset *regset = &view->regsets[setno];
60679 + if (!regset->set)
60680 + return -EOPNOTSUPP;
60682 if (!access_ok(VERIFY_READ, data, size))
60685 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
60686 index 96d465f..b084e05 100644
60687 --- a/include/linux/reiserfs_fs.h
60688 +++ b/include/linux/reiserfs_fs.h
60689 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60690 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60692 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60693 -#define get_generation(s) atomic_read (&fs_generation(s))
60694 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60695 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60696 #define __fs_changed(gen,s) (gen != get_generation (s))
60697 #define fs_changed(gen,s) \
60698 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
60699 index 52c83b6..18ed7eb 100644
60700 --- a/include/linux/reiserfs_fs_sb.h
60701 +++ b/include/linux/reiserfs_fs_sb.h
60702 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
60703 /* Comment? -Hans */
60704 wait_queue_head_t s_wait;
60705 /* To be obsoleted soon by per buffer seals.. -Hans */
60706 - atomic_t s_generation_counter; // increased by one every time the
60707 + atomic_unchecked_t s_generation_counter; // increased by one every time the
60708 // tree gets re-balanced
60709 unsigned long s_properties; /* File system properties. Currently holds
60710 on-disk FS format */
60711 diff --git a/include/linux/relay.h b/include/linux/relay.h
60712 index 14a86bc..17d0700 100644
60713 --- a/include/linux/relay.h
60714 +++ b/include/linux/relay.h
60715 @@ -159,7 +159,7 @@ struct rchan_callbacks
60716 * The callback should return 0 if successful, negative if not.
60718 int (*remove_buf_file)(struct dentry *dentry);
60723 * CONFIG_RELAY kernel API, kernel/relay.c
60724 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
60725 index c6c6084..5bf1212 100644
60726 --- a/include/linux/rfkill.h
60727 +++ b/include/linux/rfkill.h
60728 @@ -147,6 +147,7 @@ struct rfkill_ops {
60729 void (*query)(struct rfkill *rfkill, void *data);
60730 int (*set_block)(void *data, bool blocked);
60732 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
60734 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
60736 diff --git a/include/linux/rio.h b/include/linux/rio.h
60737 index 4d50611..c6858a2 100644
60738 --- a/include/linux/rio.h
60739 +++ b/include/linux/rio.h
60740 @@ -315,7 +315,7 @@ struct rio_ops {
60741 int mbox, void *buffer, size_t len);
60742 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
60743 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
60747 #define RIO_RESOURCE_MEM 0x00000100
60748 #define RIO_RESOURCE_DOORBELL 0x00000200
60749 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
60750 index 2148b12..519b820 100644
60751 --- a/include/linux/rmap.h
60752 +++ b/include/linux/rmap.h
60753 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
60754 void anon_vma_init(void); /* create anon_vma_cachep */
60755 int anon_vma_prepare(struct vm_area_struct *);
60756 void unlink_anon_vmas(struct vm_area_struct *);
60757 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
60758 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
60759 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
60760 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
60761 void __anon_vma_link(struct vm_area_struct *);
60763 static inline void anon_vma_merge(struct vm_area_struct *vma,
60764 diff --git a/include/linux/sched.h b/include/linux/sched.h
60765 index 1c4f3e9..b4e4851 100644
60766 --- a/include/linux/sched.h
60767 +++ b/include/linux/sched.h
60768 @@ -101,6 +101,7 @@ struct bio_list;
60770 struct perf_event_context;
60772 +struct linux_binprm;
60775 * List of flags we want to share for kernel threads,
60776 @@ -380,10 +381,13 @@ struct user_namespace;
60777 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
60779 extern int sysctl_max_map_count;
60780 +extern unsigned long sysctl_heap_stack_gap;
60782 #include <linux/aio.h>
60785 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
60786 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
60787 extern void arch_pick_mmap_layout(struct mm_struct *mm);
60788 extern unsigned long
60789 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
60790 @@ -629,6 +633,17 @@ struct signal_struct {
60791 #ifdef CONFIG_TASKSTATS
60792 struct taskstats *stats;
60795 +#ifdef CONFIG_GRKERNSEC
60802 + u8 used_accept:1;
60805 #ifdef CONFIG_AUDIT
60806 unsigned audit_tty;
60807 struct tty_audit_buf *tty_audit_buf;
60808 @@ -710,6 +725,11 @@ struct user_struct {
60809 struct key *session_keyring; /* UID's default session keyring */
60812 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60813 + unsigned int banned;
60814 + unsigned long ban_expires;
60817 /* Hash table maintenance information */
60818 struct hlist_node uidhash_node;
60820 @@ -1337,8 +1357,8 @@ struct task_struct {
60821 struct list_head thread_group;
60823 struct completion *vfork_done; /* for vfork() */
60824 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
60825 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60826 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
60827 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60829 cputime_t utime, stime, utimescaled, stimescaled;
60831 @@ -1354,13 +1374,6 @@ struct task_struct {
60832 struct task_cputime cputime_expires;
60833 struct list_head cpu_timers[3];
60835 -/* process credentials */
60836 - const struct cred __rcu *real_cred; /* objective and real subjective task
60837 - * credentials (COW) */
60838 - const struct cred __rcu *cred; /* effective (overridable) subjective task
60839 - * credentials (COW) */
60840 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60842 char comm[TASK_COMM_LEN]; /* executable name excluding path
60843 - access with [gs]et_task_comm (which lock
60844 it with task_lock())
60845 @@ -1377,8 +1390,16 @@ struct task_struct {
60847 /* CPU-specific state of this task */
60848 struct thread_struct thread;
60849 +/* thread_info moved to task_struct */
60851 + struct thread_info tinfo;
60853 /* filesystem information */
60854 struct fs_struct *fs;
60856 + const struct cred __rcu *cred; /* effective (overridable) subjective task
60857 + * credentials (COW) */
60859 /* open file information */
60860 struct files_struct *files;
60862 @@ -1425,6 +1446,11 @@ struct task_struct {
60863 struct rt_mutex_waiter *pi_blocked_on;
60866 +/* process credentials */
60867 + const struct cred __rcu *real_cred; /* objective and real subjective task
60868 + * credentials (COW) */
60869 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60871 #ifdef CONFIG_DEBUG_MUTEXES
60872 /* mutex deadlock detection */
60873 struct mutex_waiter *blocked_on;
60874 @@ -1540,6 +1566,27 @@ struct task_struct {
60875 unsigned long default_timer_slack_ns;
60877 struct list_head *scm_work_list;
60879 +#ifdef CONFIG_GRKERNSEC
60881 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60884 +#ifdef CONFIG_GRKERNSEC_SETXID
60885 + const struct cred *delayed_cred;
60887 + struct dentry *gr_chroot_dentry;
60888 + struct acl_subject_label *acl;
60889 + struct acl_role_label *role;
60890 + struct file *exec_file;
60892 + /* is this the task that authenticated to the special role */
60896 + u8 gr_is_chrooted;
60899 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60900 /* Index of current stored address in ret_stack */
60901 int curr_ret_stack;
60902 @@ -1574,6 +1621,51 @@ struct task_struct {
60906 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
60907 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
60908 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
60909 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
60910 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
60911 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
60913 +#ifdef CONFIG_PAX_SOFTMODE
60914 +extern int pax_softmode;
60917 +extern int pax_check_flags(unsigned long *);
60919 +/* if tsk != current then task_lock must be held on it */
60920 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60921 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
60923 + if (likely(tsk->mm))
60924 + return tsk->mm->pax_flags;
60929 +/* if tsk != current then task_lock must be held on it */
60930 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
60932 + if (likely(tsk->mm)) {
60933 + tsk->mm->pax_flags = flags;
60940 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60941 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
60942 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60943 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60946 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
60947 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
60948 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
60949 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
60951 /* Future-safe accessor for struct task_struct's cpus_allowed. */
60952 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
60954 @@ -2081,7 +2173,9 @@ void yield(void);
60955 extern struct exec_domain default_exec_domain;
60957 union thread_union {
60958 +#ifndef CONFIG_X86
60959 struct thread_info thread_info;
60961 unsigned long stack[THREAD_SIZE/sizeof(long)];
60964 @@ -2114,6 +2208,7 @@ extern struct pid_namespace init_pid_ns;
60967 extern struct task_struct *find_task_by_vpid(pid_t nr);
60968 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
60969 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
60970 struct pid_namespace *ns);
60972 @@ -2235,6 +2330,12 @@ static inline void mmdrop(struct mm_struct * mm)
60973 extern void mmput(struct mm_struct *);
60974 /* Grab a reference to a task's mm, if it is not already going away */
60975 extern struct mm_struct *get_task_mm(struct task_struct *task);
60977 + * Grab a reference to a task's mm, if it is not already going away
60978 + * and ptrace_may_access with the mode parameter passed to it
60981 +extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
60982 /* Remove the current tasks stale references to the old mm_struct */
60983 extern void mm_release(struct task_struct *, struct mm_struct *);
60984 /* Allocate a new mm structure and copy contents from tsk->mm */
60985 @@ -2251,7 +2352,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
60986 extern void exit_itimers(struct signal_struct *);
60987 extern void flush_itimer_signals(void);
60989 -extern NORET_TYPE void do_group_exit(int);
60990 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
60992 extern void daemonize(const char *, ...);
60993 extern int allow_signal(int);
60994 @@ -2416,13 +2517,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
60998 -static inline int object_is_on_stack(void *obj)
60999 +static inline int object_starts_on_stack(void *obj)
61001 - void *stack = task_stack_page(current);
61002 + const void *stack = task_stack_page(current);
61004 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
61007 +#ifdef CONFIG_PAX_USERCOPY
61008 +extern int object_is_on_stack(const void *obj, unsigned long len);
61011 extern void thread_info_cache_init(void);
61013 #ifdef CONFIG_DEBUG_STACK_USAGE
61014 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
61015 index 899fbb4..1cb4138 100644
61016 --- a/include/linux/screen_info.h
61017 +++ b/include/linux/screen_info.h
61018 @@ -43,7 +43,8 @@ struct screen_info {
61019 __u16 pages; /* 0x32 */
61020 __u16 vesa_attributes; /* 0x34 */
61021 __u32 capabilities; /* 0x36 */
61022 - __u8 _reserved[6]; /* 0x3a */
61023 + __u16 vesapm_size; /* 0x3a */
61024 + __u8 _reserved[4]; /* 0x3c */
61025 } __attribute__((packed));
61027 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
61028 diff --git a/include/linux/security.h b/include/linux/security.h
61029 index e8c619d..e0cbd1c 100644
61030 --- a/include/linux/security.h
61031 +++ b/include/linux/security.h
61033 #include <linux/xfrm.h>
61034 #include <linux/slab.h>
61035 #include <linux/xattr.h>
61036 +#include <linux/grsecurity.h>
61037 #include <net/flow.h>
61039 /* Maximum number of letters for an LSM name string */
61040 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
61041 index 0b69a46..b2ffa4c 100644
61042 --- a/include/linux/seq_file.h
61043 +++ b/include/linux/seq_file.h
61044 @@ -24,6 +24,9 @@ struct seq_file {
61046 const struct seq_operations *op;
61048 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61054 @@ -33,6 +36,7 @@ struct seq_operations {
61055 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
61056 int (*show) (struct seq_file *m, void *v);
61058 +typedef struct seq_operations __no_const seq_operations_no_const;
61062 diff --git a/include/linux/shm.h b/include/linux/shm.h
61063 index 92808b8..c28cac4 100644
61064 --- a/include/linux/shm.h
61065 +++ b/include/linux/shm.h
61066 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
61068 /* The task created the shm object. NULL if the task is dead. */
61069 struct task_struct *shm_creator;
61070 +#ifdef CONFIG_GRKERNSEC
61071 + time_t shm_createtime;
61076 /* shm_mode upper byte flags */
61077 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
61078 index fe86488..1563c1c 100644
61079 --- a/include/linux/skbuff.h
61080 +++ b/include/linux/skbuff.h
61081 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
61083 static inline int skb_queue_empty(const struct sk_buff_head *list)
61085 - return list->next == (struct sk_buff *)list;
61086 + return list->next == (const struct sk_buff *)list;
61090 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
61091 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
61092 const struct sk_buff *skb)
61094 - return skb->next == (struct sk_buff *)list;
61095 + return skb->next == (const struct sk_buff *)list;
61099 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
61100 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
61101 const struct sk_buff *skb)
61103 - return skb->prev == (struct sk_buff *)list;
61104 + return skb->prev == (const struct sk_buff *)list;
61108 @@ -1523,7 +1523,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
61109 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
61111 #ifndef NET_SKB_PAD
61112 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
61113 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
61116 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
61117 diff --git a/include/linux/slab.h b/include/linux/slab.h
61118 index 573c809..e84c132 100644
61119 --- a/include/linux/slab.h
61120 +++ b/include/linux/slab.h
61121 @@ -11,12 +11,20 @@
61123 #include <linux/gfp.h>
61124 #include <linux/types.h>
61125 +#include <linux/err.h>
61128 * Flags to pass to kmem_cache_create().
61129 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
61131 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
61133 +#ifdef CONFIG_PAX_USERCOPY
61134 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
61136 +#define SLAB_USERCOPY 0x00000000UL
61139 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
61140 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
61141 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
61142 @@ -87,10 +95,13 @@
61143 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
61144 * Both make kfree a no-op.
61146 -#define ZERO_SIZE_PTR ((void *)16)
61147 +#define ZERO_SIZE_PTR \
61149 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
61150 + (void *)(-MAX_ERRNO-1L); \
61153 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
61154 - (unsigned long)ZERO_SIZE_PTR)
61155 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
61158 * struct kmem_cache related prototypes
61159 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
61160 void kfree(const void *);
61161 void kzfree(const void *);
61162 size_t ksize(const void *);
61163 +void check_object_size(const void *ptr, unsigned long n, bool to);
61166 * Allocator specific definitions. These are mainly used to establish optimized
61167 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
61169 void __init kmem_cache_init_late(void);
61171 +#define kmalloc(x, y) \
61173 + void *___retval; \
61174 + intoverflow_t ___x = (intoverflow_t)x; \
61175 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
61176 + ___retval = NULL; \
61178 + ___retval = kmalloc((size_t)___x, (y)); \
61182 +#define kmalloc_node(x, y, z) \
61184 + void *___retval; \
61185 + intoverflow_t ___x = (intoverflow_t)x; \
61186 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
61187 + ___retval = NULL; \
61189 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
61193 +#define kzalloc(x, y) \
61195 + void *___retval; \
61196 + intoverflow_t ___x = (intoverflow_t)x; \
61197 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
61198 + ___retval = NULL; \
61200 + ___retval = kzalloc((size_t)___x, (y)); \
61204 +#define __krealloc(x, y, z) \
61206 + void *___retval; \
61207 + intoverflow_t ___y = (intoverflow_t)y; \
61208 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
61209 + ___retval = NULL; \
61211 + ___retval = __krealloc((x), (size_t)___y, (z)); \
61215 +#define krealloc(x, y, z) \
61217 + void *___retval; \
61218 + intoverflow_t ___y = (intoverflow_t)y; \
61219 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
61220 + ___retval = NULL; \
61222 + ___retval = krealloc((x), (size_t)___y, (z)); \
61226 #endif /* _LINUX_SLAB_H */
61227 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
61228 index d00e0ba..1b3bf7b 100644
61229 --- a/include/linux/slab_def.h
61230 +++ b/include/linux/slab_def.h
61231 @@ -68,10 +68,10 @@ struct kmem_cache {
61232 unsigned long node_allocs;
61233 unsigned long node_frees;
61234 unsigned long node_overflow;
61235 - atomic_t allochit;
61236 - atomic_t allocmiss;
61237 - atomic_t freehit;
61238 - atomic_t freemiss;
61239 + atomic_unchecked_t allochit;
61240 + atomic_unchecked_t allocmiss;
61241 + atomic_unchecked_t freehit;
61242 + atomic_unchecked_t freemiss;
61245 * If debugging is enabled, then the allocator can add additional
61246 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
61247 index a32bcfd..53b71f4 100644
61248 --- a/include/linux/slub_def.h
61249 +++ b/include/linux/slub_def.h
61250 @@ -89,7 +89,7 @@ struct kmem_cache {
61251 struct kmem_cache_order_objects max;
61252 struct kmem_cache_order_objects min;
61253 gfp_t allocflags; /* gfp flags to use on each alloc */
61254 - int refcount; /* Refcount for slab cache destroy */
61255 + atomic_t refcount; /* Refcount for slab cache destroy */
61256 void (*ctor)(void *);
61257 int inuse; /* Offset to metadata */
61258 int align; /* Alignment */
61259 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
61262 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
61263 -void *__kmalloc(size_t size, gfp_t flags);
61264 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
61266 static __always_inline void *
61267 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
61268 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
61269 index de8832d..0147b46 100644
61270 --- a/include/linux/sonet.h
61271 +++ b/include/linux/sonet.h
61272 @@ -61,7 +61,7 @@ struct sonet_stats {
61273 #include <linux/atomic.h>
61275 struct k_sonet_stats {
61276 -#define __HANDLE_ITEM(i) atomic_t i
61277 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61279 #undef __HANDLE_ITEM
61281 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
61282 index 3d8f9c4..69f1c0a 100644
61283 --- a/include/linux/sunrpc/clnt.h
61284 +++ b/include/linux/sunrpc/clnt.h
61285 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
61287 switch (sap->sa_family) {
61289 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
61290 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
61292 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
61293 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
61297 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
61298 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
61299 const struct sockaddr *src)
61301 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
61302 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
61303 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
61305 dsin->sin_family = ssin->sin_family;
61306 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
61307 if (sa->sa_family != AF_INET6)
61310 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
61311 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
61314 #endif /* __KERNEL__ */
61315 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
61316 index e775689..9e206d9 100644
61317 --- a/include/linux/sunrpc/sched.h
61318 +++ b/include/linux/sunrpc/sched.h
61319 @@ -105,6 +105,7 @@ struct rpc_call_ops {
61320 void (*rpc_call_done)(struct rpc_task *, void *);
61321 void (*rpc_release)(void *);
61323 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
61325 struct rpc_task_setup {
61326 struct rpc_task *task;
61327 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
61328 index c14fe86..393245e 100644
61329 --- a/include/linux/sunrpc/svc_rdma.h
61330 +++ b/include/linux/sunrpc/svc_rdma.h
61331 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
61332 extern unsigned int svcrdma_max_requests;
61333 extern unsigned int svcrdma_max_req_size;
61335 -extern atomic_t rdma_stat_recv;
61336 -extern atomic_t rdma_stat_read;
61337 -extern atomic_t rdma_stat_write;
61338 -extern atomic_t rdma_stat_sq_starve;
61339 -extern atomic_t rdma_stat_rq_starve;
61340 -extern atomic_t rdma_stat_rq_poll;
61341 -extern atomic_t rdma_stat_rq_prod;
61342 -extern atomic_t rdma_stat_sq_poll;
61343 -extern atomic_t rdma_stat_sq_prod;
61344 +extern atomic_unchecked_t rdma_stat_recv;
61345 +extern atomic_unchecked_t rdma_stat_read;
61346 +extern atomic_unchecked_t rdma_stat_write;
61347 +extern atomic_unchecked_t rdma_stat_sq_starve;
61348 +extern atomic_unchecked_t rdma_stat_rq_starve;
61349 +extern atomic_unchecked_t rdma_stat_rq_poll;
61350 +extern atomic_unchecked_t rdma_stat_rq_prod;
61351 +extern atomic_unchecked_t rdma_stat_sq_poll;
61352 +extern atomic_unchecked_t rdma_stat_sq_prod;
61354 #define RPCRDMA_VERSION 1
61356 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
61357 index 703cfa33..0b8ca72ac 100644
61358 --- a/include/linux/sysctl.h
61359 +++ b/include/linux/sysctl.h
61360 @@ -155,7 +155,11 @@ enum
61361 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
61365 +#ifdef CONFIG_PAX_SOFTMODE
61367 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
61371 /* CTL_VM names: */
61373 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
61375 extern int proc_dostring(struct ctl_table *, int,
61376 void __user *, size_t *, loff_t *);
61377 +extern int proc_dostring_modpriv(struct ctl_table *, int,
61378 + void __user *, size_t *, loff_t *);
61379 extern int proc_dointvec(struct ctl_table *, int,
61380 void __user *, size_t *, loff_t *);
61381 extern int proc_dointvec_minmax(struct ctl_table *, int,
61382 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
61383 index a71a292..51bd91d 100644
61384 --- a/include/linux/tracehook.h
61385 +++ b/include/linux/tracehook.h
61386 @@ -54,12 +54,12 @@ struct linux_binprm;
61388 * ptrace report for syscall entry and exit looks identical.
61390 -static inline void ptrace_report_syscall(struct pt_regs *regs)
61391 +static inline int ptrace_report_syscall(struct pt_regs *regs)
61393 int ptrace = current->ptrace;
61395 if (!(ptrace & PT_PTRACED))
61399 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
61401 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
61402 send_sig(current->exit_code, current, 1);
61403 current->exit_code = 0;
61406 + return fatal_signal_pending(current);
61410 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
61411 static inline __must_check int tracehook_report_syscall_entry(
61412 struct pt_regs *regs)
61414 - ptrace_report_syscall(regs);
61416 + return ptrace_report_syscall(regs);
61420 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
61421 index ff7dc08..893e1bd 100644
61422 --- a/include/linux/tty_ldisc.h
61423 +++ b/include/linux/tty_ldisc.h
61424 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
61426 struct module *owner;
61429 + atomic_t refcount;
61433 diff --git a/include/linux/types.h b/include/linux/types.h
61434 index 57a9723..dbe234a 100644
61435 --- a/include/linux/types.h
61436 +++ b/include/linux/types.h
61437 @@ -213,10 +213,26 @@ typedef struct {
61441 +#ifdef CONFIG_PAX_REFCOUNT
61444 +} atomic_unchecked_t;
61446 +typedef atomic_t atomic_unchecked_t;
61449 #ifdef CONFIG_64BIT
61454 +#ifdef CONFIG_PAX_REFCOUNT
61457 +} atomic64_unchecked_t;
61459 +typedef atomic64_t atomic64_unchecked_t;
61464 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
61465 index 5ca0951..ab496a5 100644
61466 --- a/include/linux/uaccess.h
61467 +++ b/include/linux/uaccess.h
61468 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
61470 mm_segment_t old_fs = get_fs(); \
61472 - set_fs(KERNEL_DS); \
61473 pagefault_disable(); \
61474 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
61475 - pagefault_enable(); \
61476 + set_fs(KERNEL_DS); \
61477 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
61479 + pagefault_enable(); \
61483 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
61484 index 99c1b4d..bb94261 100644
61485 --- a/include/linux/unaligned/access_ok.h
61486 +++ b/include/linux/unaligned/access_ok.h
61489 static inline u16 get_unaligned_le16(const void *p)
61491 - return le16_to_cpup((__le16 *)p);
61492 + return le16_to_cpup((const __le16 *)p);
61495 static inline u32 get_unaligned_le32(const void *p)
61497 - return le32_to_cpup((__le32 *)p);
61498 + return le32_to_cpup((const __le32 *)p);
61501 static inline u64 get_unaligned_le64(const void *p)
61503 - return le64_to_cpup((__le64 *)p);
61504 + return le64_to_cpup((const __le64 *)p);
61507 static inline u16 get_unaligned_be16(const void *p)
61509 - return be16_to_cpup((__be16 *)p);
61510 + return be16_to_cpup((const __be16 *)p);
61513 static inline u32 get_unaligned_be32(const void *p)
61515 - return be32_to_cpup((__be32 *)p);
61516 + return be32_to_cpup((const __be32 *)p);
61519 static inline u64 get_unaligned_be64(const void *p)
61521 - return be64_to_cpup((__be64 *)p);
61522 + return be64_to_cpup((const __be64 *)p);
61525 static inline void put_unaligned_le16(u16 val, void *p)
61526 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
61527 index e5a40c3..20ab0f6 100644
61528 --- a/include/linux/usb/renesas_usbhs.h
61529 +++ b/include/linux/usb/renesas_usbhs.h
61530 @@ -39,7 +39,7 @@ enum {
61532 struct renesas_usbhs_driver_callback {
61533 int (*notify_hotplug)(struct platform_device *pdev);
61538 * callback functions for platform
61539 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
61540 * VBUS control is needed for Host
61542 int (*set_vbus)(struct platform_device *pdev, int enable);
61547 * parameters for renesas usbhs
61548 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
61549 index 6f8fbcf..8259001 100644
61550 --- a/include/linux/vermagic.h
61551 +++ b/include/linux/vermagic.h
61553 #define MODULE_ARCH_VERMAGIC ""
61556 +#ifdef CONFIG_PAX_REFCOUNT
61557 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
61559 +#define MODULE_PAX_REFCOUNT ""
61562 +#ifdef CONSTIFY_PLUGIN
61563 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
61565 +#define MODULE_CONSTIFY_PLUGIN ""
61568 +#ifdef STACKLEAK_PLUGIN
61569 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
61571 +#define MODULE_STACKLEAK_PLUGIN ""
61574 +#ifdef CONFIG_GRKERNSEC
61575 +#define MODULE_GRSEC "GRSEC "
61577 +#define MODULE_GRSEC ""
61580 #define VERMAGIC_STRING \
61582 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
61583 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
61584 - MODULE_ARCH_VERMAGIC
61585 + MODULE_ARCH_VERMAGIC \
61586 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
61589 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
61590 index 4bde182..aec92c1 100644
61591 --- a/include/linux/vmalloc.h
61592 +++ b/include/linux/vmalloc.h
61593 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
61594 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
61595 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
61596 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
61598 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
61599 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
61602 /* bits [20..32] reserved for arch specific ioremap internals */
61605 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
61609 +#define vmalloc(x) \
61611 + void *___retval; \
61612 + intoverflow_t ___x = (intoverflow_t)x; \
61613 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
61614 + ___retval = NULL; \
61616 + ___retval = vmalloc((unsigned long)___x); \
61620 +#define vzalloc(x) \
61622 + void *___retval; \
61623 + intoverflow_t ___x = (intoverflow_t)x; \
61624 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
61625 + ___retval = NULL; \
61627 + ___retval = vzalloc((unsigned long)___x); \
61631 +#define __vmalloc(x, y, z) \
61633 + void *___retval; \
61634 + intoverflow_t ___x = (intoverflow_t)x; \
61635 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
61636 + ___retval = NULL; \
61638 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
61642 +#define vmalloc_user(x) \
61644 + void *___retval; \
61645 + intoverflow_t ___x = (intoverflow_t)x; \
61646 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
61647 + ___retval = NULL; \
61649 + ___retval = vmalloc_user((unsigned long)___x); \
61653 +#define vmalloc_exec(x) \
61655 + void *___retval; \
61656 + intoverflow_t ___x = (intoverflow_t)x; \
61657 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
61658 + ___retval = NULL; \
61660 + ___retval = vmalloc_exec((unsigned long)___x); \
61664 +#define vmalloc_node(x, y) \
61666 + void *___retval; \
61667 + intoverflow_t ___x = (intoverflow_t)x; \
61668 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
61669 + ___retval = NULL; \
61671 + ___retval = vmalloc_node((unsigned long)___x, (y));\
61675 +#define vzalloc_node(x, y) \
61677 + void *___retval; \
61678 + intoverflow_t ___x = (intoverflow_t)x; \
61679 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
61680 + ___retval = NULL; \
61682 + ___retval = vzalloc_node((unsigned long)___x, (y));\
61686 +#define vmalloc_32(x) \
61688 + void *___retval; \
61689 + intoverflow_t ___x = (intoverflow_t)x; \
61690 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
61691 + ___retval = NULL; \
61693 + ___retval = vmalloc_32((unsigned long)___x); \
61697 +#define vmalloc_32_user(x) \
61699 +void *___retval; \
61700 + intoverflow_t ___x = (intoverflow_t)x; \
61701 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
61702 + ___retval = NULL; \
61704 + ___retval = vmalloc_32_user((unsigned long)___x);\
61708 #endif /* _LINUX_VMALLOC_H */
61709 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
61710 index 65efb92..137adbb 100644
61711 --- a/include/linux/vmstat.h
61712 +++ b/include/linux/vmstat.h
61713 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
61715 * Zone based page accounting with per cpu differentials.
61717 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61718 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61720 static inline void zone_page_state_add(long x, struct zone *zone,
61721 enum zone_stat_item item)
61723 - atomic_long_add(x, &zone->vm_stat[item]);
61724 - atomic_long_add(x, &vm_stat[item]);
61725 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
61726 + atomic_long_add_unchecked(x, &vm_stat[item]);
61729 static inline unsigned long global_page_state(enum zone_stat_item item)
61731 - long x = atomic_long_read(&vm_stat[item]);
61732 + long x = atomic_long_read_unchecked(&vm_stat[item]);
61736 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
61737 static inline unsigned long zone_page_state(struct zone *zone,
61738 enum zone_stat_item item)
61740 - long x = atomic_long_read(&zone->vm_stat[item]);
61741 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61745 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
61746 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
61747 enum zone_stat_item item)
61749 - long x = atomic_long_read(&zone->vm_stat[item]);
61750 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61754 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
61756 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
61758 - atomic_long_inc(&zone->vm_stat[item]);
61759 - atomic_long_inc(&vm_stat[item]);
61760 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
61761 + atomic_long_inc_unchecked(&vm_stat[item]);
61764 static inline void __inc_zone_page_state(struct page *page,
61765 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
61767 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
61769 - atomic_long_dec(&zone->vm_stat[item]);
61770 - atomic_long_dec(&vm_stat[item]);
61771 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
61772 + atomic_long_dec_unchecked(&vm_stat[item]);
61775 static inline void __dec_zone_page_state(struct page *page,
61776 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
61777 index e5d1220..ef6e406 100644
61778 --- a/include/linux/xattr.h
61779 +++ b/include/linux/xattr.h
61781 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
61782 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
61784 +/* User namespace */
61785 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
61786 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
61787 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
61791 #include <linux/types.h>
61792 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
61793 index 4aeff96..b378cdc 100644
61794 --- a/include/media/saa7146_vv.h
61795 +++ b/include/media/saa7146_vv.h
61796 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
61797 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
61799 /* the extension can override this */
61800 - struct v4l2_ioctl_ops ops;
61801 + v4l2_ioctl_ops_no_const ops;
61802 /* pointer to the saa7146 core ops */
61803 const struct v4l2_ioctl_ops *core_ops;
61805 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
61806 index c7c40f1..4f01585 100644
61807 --- a/include/media/v4l2-dev.h
61808 +++ b/include/media/v4l2-dev.h
61809 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
61812 struct v4l2_file_operations {
61813 - struct module *owner;
61814 + struct module * const owner;
61815 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61816 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
61817 unsigned int (*poll) (struct file *, struct poll_table_struct *);
61818 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
61819 int (*open) (struct file *);
61820 int (*release) (struct file *);
61822 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
61825 * Newer version of video_device, handled by videodev2.c
61826 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
61827 index 4d1c74a..65e1221 100644
61828 --- a/include/media/v4l2-ioctl.h
61829 +++ b/include/media/v4l2-ioctl.h
61830 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
61831 long (*vidioc_default) (struct file *file, void *fh,
61832 bool valid_prio, int cmd, void *arg);
61835 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
61837 /* v4l debugging and diagnostics */
61839 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
61840 index 8d55251..dfe5b0a 100644
61841 --- a/include/net/caif/caif_hsi.h
61842 +++ b/include/net/caif/caif_hsi.h
61843 @@ -98,7 +98,7 @@ struct cfhsi_drv {
61844 void (*rx_done_cb) (struct cfhsi_drv *drv);
61845 void (*wake_up_cb) (struct cfhsi_drv *drv);
61846 void (*wake_down_cb) (struct cfhsi_drv *drv);
61850 /* Structure implemented by HSI device. */
61852 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
61853 index 9e5425b..8136ffc 100644
61854 --- a/include/net/caif/cfctrl.h
61855 +++ b/include/net/caif/cfctrl.h
61856 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
61857 void (*radioset_rsp)(void);
61858 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
61859 struct cflayer *client_layer);
61863 /* Link Setup Parameters for CAIF-Links. */
61864 struct cfctrl_link_param {
61865 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
61867 struct cfsrvl serv;
61868 struct cfctrl_rsp res;
61869 - atomic_t req_seq_no;
61870 - atomic_t rsp_seq_no;
61871 + atomic_unchecked_t req_seq_no;
61872 + atomic_unchecked_t rsp_seq_no;
61873 struct list_head list;
61874 /* Protects from simultaneous access to first_req list */
61875 spinlock_t info_list_lock;
61876 diff --git a/include/net/flow.h b/include/net/flow.h
61877 index 2a7eefd..3250f3b 100644
61878 --- a/include/net/flow.h
61879 +++ b/include/net/flow.h
61880 @@ -218,6 +218,6 @@ extern struct flow_cache_object *flow_cache_lookup(
61882 extern void flow_cache_flush(void);
61883 extern void flow_cache_flush_deferred(void);
61884 -extern atomic_t flow_cache_genid;
61885 +extern atomic_unchecked_t flow_cache_genid;
61888 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
61889 index e9ff3fc..9d3e5c7 100644
61890 --- a/include/net/inetpeer.h
61891 +++ b/include/net/inetpeer.h
61892 @@ -48,8 +48,8 @@ struct inet_peer {
61896 - atomic_t rid; /* Frag reception counter */
61897 - atomic_t ip_id_count; /* IP ID for the next packet */
61898 + atomic_unchecked_t rid; /* Frag reception counter */
61899 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
61901 __u32 tcp_ts_stamp;
61903 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
61905 inet_peer_refcheck(p);
61907 - old = atomic_read(&p->ip_id_count);
61908 + old = atomic_read_unchecked(&p->ip_id_count);
61912 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
61913 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
61917 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
61918 index 10422ef..662570f 100644
61919 --- a/include/net/ip_fib.h
61920 +++ b/include/net/ip_fib.h
61921 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
61923 #define FIB_RES_SADDR(net, res) \
61924 ((FIB_RES_NH(res).nh_saddr_genid == \
61925 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
61926 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
61927 FIB_RES_NH(res).nh_saddr : \
61928 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
61929 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
61930 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
61931 index e5a7b9a..f4fc44b 100644
61932 --- a/include/net/ip_vs.h
61933 +++ b/include/net/ip_vs.h
61934 @@ -509,7 +509,7 @@ struct ip_vs_conn {
61935 struct ip_vs_conn *control; /* Master control connection */
61936 atomic_t n_control; /* Number of controlled ones */
61937 struct ip_vs_dest *dest; /* real server */
61938 - atomic_t in_pkts; /* incoming packet counter */
61939 + atomic_unchecked_t in_pkts; /* incoming packet counter */
61941 /* packet transmitter for different forwarding methods. If it
61942 mangles the packet, it must return NF_DROP or better NF_STOLEN,
61943 @@ -647,7 +647,7 @@ struct ip_vs_dest {
61944 __be16 port; /* port number of the server */
61945 union nf_inet_addr addr; /* IP address of the server */
61946 volatile unsigned flags; /* dest status flags */
61947 - atomic_t conn_flags; /* flags to copy to conn */
61948 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
61949 atomic_t weight; /* server weight */
61951 atomic_t refcnt; /* reference counter */
61952 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
61953 index 69b610a..fe3962c 100644
61954 --- a/include/net/irda/ircomm_core.h
61955 +++ b/include/net/irda/ircomm_core.h
61956 @@ -51,7 +51,7 @@ typedef struct {
61957 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
61958 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
61959 struct ircomm_info *);
61961 +} __no_const call_t;
61964 irda_queue_t queue;
61965 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
61966 index 59ba38bc..d515662 100644
61967 --- a/include/net/irda/ircomm_tty.h
61968 +++ b/include/net/irda/ircomm_tty.h
61970 #include <linux/termios.h>
61971 #include <linux/timer.h>
61972 #include <linux/tty.h> /* struct tty_struct */
61973 +#include <asm/local.h>
61975 #include <net/irda/irias_object.h>
61976 #include <net/irda/ircomm_core.h>
61977 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
61978 unsigned short close_delay;
61979 unsigned short closing_wait; /* time to wait before closing */
61982 - int blocked_open; /* # of blocked opens */
61983 + local_t open_count;
61984 + local_t blocked_open; /* # of blocked opens */
61986 /* Protect concurent access to :
61987 * o self->open_count
61988 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
61989 index f2419cf..473679f 100644
61990 --- a/include/net/iucv/af_iucv.h
61991 +++ b/include/net/iucv/af_iucv.h
61992 @@ -139,7 +139,7 @@ struct iucv_sock {
61993 struct iucv_sock_list {
61994 struct hlist_head head;
61996 - atomic_t autobind_name;
61997 + atomic_unchecked_t autobind_name;
62000 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
62001 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
62002 index 2720884..3aa5c25 100644
62003 --- a/include/net/neighbour.h
62004 +++ b/include/net/neighbour.h
62005 @@ -122,7 +122,7 @@ struct neigh_ops {
62006 void (*error_report)(struct neighbour *, struct sk_buff *);
62007 int (*output)(struct neighbour *, struct sk_buff *);
62008 int (*connected_output)(struct neighbour *, struct sk_buff *);
62012 struct pneigh_entry {
62013 struct pneigh_entry *next;
62014 diff --git a/include/net/netlink.h b/include/net/netlink.h
62015 index cb1f350..3279d2c 100644
62016 --- a/include/net/netlink.h
62017 +++ b/include/net/netlink.h
62018 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
62019 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
62022 - skb_trim(skb, (unsigned char *) mark - skb->data);
62023 + skb_trim(skb, (const unsigned char *) mark - skb->data);
62027 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
62028 index d786b4f..4c3dd41 100644
62029 --- a/include/net/netns/ipv4.h
62030 +++ b/include/net/netns/ipv4.h
62031 @@ -56,8 +56,8 @@ struct netns_ipv4 {
62033 unsigned int sysctl_ping_group_range[2];
62035 - atomic_t rt_genid;
62036 - atomic_t dev_addr_genid;
62037 + atomic_unchecked_t rt_genid;
62038 + atomic_unchecked_t dev_addr_genid;
62040 #ifdef CONFIG_IP_MROUTE
62041 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
62042 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
62043 index 6a72a58..e6a127d 100644
62044 --- a/include/net/sctp/sctp.h
62045 +++ b/include/net/sctp/sctp.h
62046 @@ -318,9 +318,9 @@ do { \
62048 #else /* SCTP_DEBUG */
62050 -#define SCTP_DEBUG_PRINTK(whatever...)
62051 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
62052 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
62053 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
62054 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
62055 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
62056 #define SCTP_ENABLE_DEBUG
62057 #define SCTP_DISABLE_DEBUG
62058 #define SCTP_ASSERT(expr, str, func)
62059 diff --git a/include/net/sock.h b/include/net/sock.h
62060 index 32e3937..87a1dbc 100644
62061 --- a/include/net/sock.h
62062 +++ b/include/net/sock.h
62063 @@ -277,7 +277,7 @@ struct sock {
62067 - atomic_t sk_drops;
62068 + atomic_unchecked_t sk_drops;
62071 struct sk_filter __rcu *sk_filter;
62072 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
62075 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
62076 - char __user *from, char *to,
62077 + char __user *from, unsigned char *to,
62078 int copy, int offset)
62080 if (skb->ip_summed == CHECKSUM_NONE) {
62081 diff --git a/include/net/tcp.h b/include/net/tcp.h
62082 index bb18c4d..bb87972 100644
62083 --- a/include/net/tcp.h
62084 +++ b/include/net/tcp.h
62085 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
62087 sa_family_t family;
62088 const struct file_operations *seq_fops;
62089 - struct seq_operations seq_ops;
62090 + seq_operations_no_const seq_ops;
62093 struct tcp_iter_state {
62094 diff --git a/include/net/udp.h b/include/net/udp.h
62095 index 3b285f4..0219639 100644
62096 --- a/include/net/udp.h
62097 +++ b/include/net/udp.h
62098 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
62099 sa_family_t family;
62100 struct udp_table *udp_table;
62101 const struct file_operations *seq_fops;
62102 - struct seq_operations seq_ops;
62103 + seq_operations_no_const seq_ops;
62106 struct udp_iter_state {
62107 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
62108 index b203e14..1df3991 100644
62109 --- a/include/net/xfrm.h
62110 +++ b/include/net/xfrm.h
62111 @@ -505,7 +505,7 @@ struct xfrm_policy {
62112 struct timer_list timer;
62114 struct flow_cache_object flo;
62116 + atomic_unchecked_t genid;
62119 struct xfrm_mark mark;
62120 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
62121 index 1a046b1..ee0bef0 100644
62122 --- a/include/rdma/iw_cm.h
62123 +++ b/include/rdma/iw_cm.h
62124 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
62127 int (*destroy_listen)(struct iw_cm_id *cm_id);
62132 * iw_create_cm_id - Create an IW CM identifier.
62133 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
62134 index 5d1a758..1dbf795 100644
62135 --- a/include/scsi/libfc.h
62136 +++ b/include/scsi/libfc.h
62137 @@ -748,6 +748,7 @@ struct libfc_function_template {
62139 void (*disc_stop_final) (struct fc_lport *);
62141 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
62144 * struct fc_disc - Discovery context
62145 @@ -851,7 +852,7 @@ struct fc_lport {
62146 struct fc_vport *vport;
62148 /* Operational Information */
62149 - struct libfc_function_template tt;
62150 + libfc_function_template_no_const tt;
62153 enum fc_lport_state state;
62154 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
62155 index 5591ed5..13eb457 100644
62156 --- a/include/scsi/scsi_device.h
62157 +++ b/include/scsi/scsi_device.h
62158 @@ -161,9 +161,9 @@ struct scsi_device {
62159 unsigned int max_device_blocked; /* what device_blocked counts down from */
62160 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
62162 - atomic_t iorequest_cnt;
62163 - atomic_t iodone_cnt;
62164 - atomic_t ioerr_cnt;
62165 + atomic_unchecked_t iorequest_cnt;
62166 + atomic_unchecked_t iodone_cnt;
62167 + atomic_unchecked_t ioerr_cnt;
62169 struct device sdev_gendev,
62171 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
62172 index 2a65167..91e01f8 100644
62173 --- a/include/scsi/scsi_transport_fc.h
62174 +++ b/include/scsi/scsi_transport_fc.h
62175 @@ -711,7 +711,7 @@ struct fc_function_template {
62176 unsigned long show_host_system_hostname:1;
62178 unsigned long disable_target_scan:1;
62184 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
62185 index 030b87c..98a6954 100644
62186 --- a/include/sound/ak4xxx-adda.h
62187 +++ b/include/sound/ak4xxx-adda.h
62188 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
62189 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
62190 unsigned char val);
62191 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
62195 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
62197 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
62198 index 8c05e47..2b5df97 100644
62199 --- a/include/sound/hwdep.h
62200 +++ b/include/sound/hwdep.h
62201 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
62202 struct snd_hwdep_dsp_status *status);
62203 int (*dsp_load)(struct snd_hwdep *hw,
62204 struct snd_hwdep_dsp_image *image);
62209 struct snd_card *card;
62210 diff --git a/include/sound/info.h b/include/sound/info.h
62211 index 5492cc4..1a65278 100644
62212 --- a/include/sound/info.h
62213 +++ b/include/sound/info.h
62214 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
62215 struct snd_info_buffer *buffer);
62216 void (*write)(struct snd_info_entry *entry,
62217 struct snd_info_buffer *buffer);
62221 struct snd_info_entry_ops {
62222 int (*open)(struct snd_info_entry *entry,
62223 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
62224 index 0cf91b2..b70cae4 100644
62225 --- a/include/sound/pcm.h
62226 +++ b/include/sound/pcm.h
62227 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
62228 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
62229 int (*ack)(struct snd_pcm_substream *substream);
62231 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
62235 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
62236 index af1b49e..a5d55a5 100644
62237 --- a/include/sound/sb16_csp.h
62238 +++ b/include/sound/sb16_csp.h
62239 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
62240 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
62241 int (*csp_stop) (struct snd_sb_csp * p);
62242 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
62248 diff --git a/include/sound/soc.h b/include/sound/soc.h
62249 index 11cfb59..e3f93f4 100644
62250 --- a/include/sound/soc.h
62251 +++ b/include/sound/soc.h
62252 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
62253 /* platform IO - used for platform DAPM */
62254 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
62255 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
62259 struct snd_soc_platform {
62261 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
62262 index 444cd6b..3327cc5 100644
62263 --- a/include/sound/ymfpci.h
62264 +++ b/include/sound/ymfpci.h
62265 @@ -358,7 +358,7 @@ struct snd_ymfpci {
62266 spinlock_t reg_lock;
62267 spinlock_t voice_lock;
62268 wait_queue_head_t interrupt_sleep;
62269 - atomic_t interrupt_sleep_count;
62270 + atomic_unchecked_t interrupt_sleep_count;
62271 struct snd_info_entry *proc_entry;
62272 const struct firmware *dsp_microcode;
62273 const struct firmware *controller_microcode;
62274 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
62275 index 94bbec3..3a8c6b0 100644
62276 --- a/include/target/target_core_base.h
62277 +++ b/include/target/target_core_base.h
62278 @@ -346,7 +346,7 @@ struct t10_reservation_ops {
62279 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
62280 int (*t10_pr_register)(struct se_cmd *);
62281 int (*t10_pr_clear)(struct se_cmd *);
62285 struct t10_reservation {
62286 /* Reservation effects all target ports */
62287 @@ -465,8 +465,8 @@ struct se_cmd {
62288 atomic_t t_se_count;
62289 atomic_t t_task_cdbs_left;
62290 atomic_t t_task_cdbs_ex_left;
62291 - atomic_t t_task_cdbs_sent;
62292 - atomic_t t_transport_aborted;
62293 + atomic_unchecked_t t_task_cdbs_sent;
62294 + atomic_unchecked_t t_transport_aborted;
62295 atomic_t t_transport_active;
62296 atomic_t t_transport_complete;
62297 atomic_t t_transport_queue_active;
62298 @@ -705,7 +705,7 @@ struct se_device {
62299 /* Active commands on this virtual SE device */
62300 atomic_t simple_cmds;
62301 atomic_t depth_left;
62302 - atomic_t dev_ordered_id;
62303 + atomic_unchecked_t dev_ordered_id;
62304 atomic_t execute_tasks;
62305 atomic_t dev_ordered_sync;
62306 atomic_t dev_qf_count;
62307 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
62308 index 1c09820..7f5ec79 100644
62309 --- a/include/trace/events/irq.h
62310 +++ b/include/trace/events/irq.h
62311 @@ -36,7 +36,7 @@ struct softirq_action;
62313 TRACE_EVENT(irq_handler_entry,
62315 - TP_PROTO(int irq, struct irqaction *action),
62316 + TP_PROTO(int irq, const struct irqaction *action),
62318 TP_ARGS(irq, action),
62320 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
62322 TRACE_EVENT(irq_handler_exit,
62324 - TP_PROTO(int irq, struct irqaction *action, int ret),
62325 + TP_PROTO(int irq, const struct irqaction *action, int ret),
62327 TP_ARGS(irq, action, ret),
62329 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
62330 index c41f308..6918de3 100644
62331 --- a/include/video/udlfb.h
62332 +++ b/include/video/udlfb.h
62333 @@ -52,10 +52,10 @@ struct dlfb_data {
62334 u32 pseudo_palette[256];
62335 int blank_mode; /*one of FB_BLANK_ */
62336 /* blit-only rendering path metrics, exposed through sysfs */
62337 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
62338 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
62339 - atomic_t bytes_sent; /* to usb, after compression including overhead */
62340 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
62341 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
62342 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
62343 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
62344 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
62347 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
62348 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
62349 index 0993a22..32ba2fe 100644
62350 --- a/include/video/uvesafb.h
62351 +++ b/include/video/uvesafb.h
62352 @@ -177,6 +177,7 @@ struct uvesafb_par {
62353 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
62354 u8 pmi_setpal; /* PMI for palette changes */
62355 u16 *pmi_base; /* protected mode interface location */
62356 + u8 *pmi_code; /* protected mode code location */
62359 u8 *vbe_state_orig; /*
62360 diff --git a/init/Kconfig b/init/Kconfig
62361 index 43298f9..2f56c12 100644
62364 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
62367 bool "Disable heap randomization"
62371 Randomizing heap placement makes heap exploits harder, but it
62372 also breaks ancient binaries (including anything libc5 based).
62373 diff --git a/init/do_mounts.c b/init/do_mounts.c
62374 index db6e5ee..7677ff7 100644
62375 --- a/init/do_mounts.c
62376 +++ b/init/do_mounts.c
62377 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
62379 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
62381 - int err = sys_mount(name, "/root", fs, flags, data);
62382 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
62386 - sys_chdir((const char __user __force *)"/root");
62387 + sys_chdir((const char __force_user*)"/root");
62388 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
62390 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
62391 @@ -448,18 +448,18 @@ void __init change_floppy(char *fmt, ...)
62392 va_start(args, fmt);
62393 vsprintf(buf, fmt, args);
62395 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
62396 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
62398 sys_ioctl(fd, FDEJECT, 0);
62401 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
62402 - fd = sys_open("/dev/console", O_RDWR, 0);
62403 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
62405 sys_ioctl(fd, TCGETS, (long)&termios);
62406 termios.c_lflag &= ~ICANON;
62407 sys_ioctl(fd, TCSETSF, (long)&termios);
62408 - sys_read(fd, &c, 1);
62409 + sys_read(fd, (char __user *)&c, 1);
62410 termios.c_lflag |= ICANON;
62411 sys_ioctl(fd, TCSETSF, (long)&termios);
62413 @@ -553,6 +553,6 @@ void __init prepare_namespace(void)
62416 devtmpfs_mount("dev");
62417 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62418 - sys_chroot((const char __user __force *)".");
62419 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62420 + sys_chroot((const char __force_user *)".");
62422 diff --git a/init/do_mounts.h b/init/do_mounts.h
62423 index f5b978a..69dbfe8 100644
62424 --- a/init/do_mounts.h
62425 +++ b/init/do_mounts.h
62426 @@ -15,15 +15,15 @@ extern int root_mountflags;
62428 static inline int create_dev(char *name, dev_t dev)
62430 - sys_unlink(name);
62431 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
62432 + sys_unlink((char __force_user *)name);
62433 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
62436 #if BITS_PER_LONG == 32
62437 static inline u32 bstat(char *name)
62439 struct stat64 stat;
62440 - if (sys_stat64(name, &stat) != 0)
62441 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
62443 if (!S_ISBLK(stat.st_mode))
62445 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
62446 static inline u32 bstat(char *name)
62449 - if (sys_newstat(name, &stat) != 0)
62450 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
62452 if (!S_ISBLK(stat.st_mode))
62454 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
62455 index 3098a38..253064e 100644
62456 --- a/init/do_mounts_initrd.c
62457 +++ b/init/do_mounts_initrd.c
62458 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
62459 create_dev("/dev/root.old", Root_RAM0);
62460 /* mount initrd on rootfs' /root */
62461 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
62462 - sys_mkdir("/old", 0700);
62463 - root_fd = sys_open("/", 0, 0);
62464 - old_fd = sys_open("/old", 0, 0);
62465 + sys_mkdir((const char __force_user *)"/old", 0700);
62466 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
62467 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
62468 /* move initrd over / and chdir/chroot in initrd root */
62469 - sys_chdir("/root");
62470 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62472 + sys_chdir((const char __force_user *)"/root");
62473 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62474 + sys_chroot((const char __force_user *)".");
62477 * In case that a resume from disk is carried out by linuxrc or one of
62478 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
62480 /* move initrd to rootfs' /old */
62481 sys_fchdir(old_fd);
62482 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
62483 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
62484 /* switch root and cwd back to / of rootfs */
62485 sys_fchdir(root_fd);
62487 + sys_chroot((const char __force_user *)".");
62489 sys_close(root_fd);
62491 if (new_decode_dev(real_root_dev) == Root_RAM0) {
62492 - sys_chdir("/old");
62493 + sys_chdir((const char __force_user *)"/old");
62497 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
62500 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
62501 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
62502 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
62506 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
62507 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
62508 if (error == -ENOENT)
62509 printk("/initrd does not exist. Ignored.\n");
62511 printk("failed\n");
62512 printk(KERN_NOTICE "Unmounting old root\n");
62513 - sys_umount("/old", MNT_DETACH);
62514 + sys_umount((char __force_user *)"/old", MNT_DETACH);
62515 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
62518 @@ -116,11 +116,11 @@ int __init initrd_load(void)
62519 * mounted in the normal path.
62521 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
62522 - sys_unlink("/initrd.image");
62523 + sys_unlink((const char __force_user *)"/initrd.image");
62528 - sys_unlink("/initrd.image");
62529 + sys_unlink((const char __force_user *)"/initrd.image");
62532 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
62533 index 32c4799..c27ee74 100644
62534 --- a/init/do_mounts_md.c
62535 +++ b/init/do_mounts_md.c
62536 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
62537 partitioned ? "_d" : "", minor,
62538 md_setup_args[ent].device_names);
62540 - fd = sys_open(name, 0, 0);
62541 + fd = sys_open((char __force_user *)name, 0, 0);
62543 printk(KERN_ERR "md: open failed - cannot start "
62544 "array %s\n", name);
62545 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
62549 - fd = sys_open(name, 0, 0);
62550 + fd = sys_open((char __force_user *)name, 0, 0);
62551 sys_ioctl(fd, BLKRRPART, 0);
62554 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
62556 wait_for_device_probe();
62558 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
62559 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
62561 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
62563 diff --git a/init/initramfs.c b/init/initramfs.c
62564 index 2531811..040d4d4 100644
62565 --- a/init/initramfs.c
62566 +++ b/init/initramfs.c
62567 @@ -74,7 +74,7 @@ static void __init free_hash(void)
62571 -static long __init do_utime(char __user *filename, time_t mtime)
62572 +static long __init do_utime(__force char __user *filename, time_t mtime)
62574 struct timespec t[2];
62576 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
62577 struct dir_entry *de, *tmp;
62578 list_for_each_entry_safe(de, tmp, &dir_list, list) {
62579 list_del(&de->list);
62580 - do_utime(de->name, de->mtime);
62581 + do_utime((char __force_user *)de->name, de->mtime);
62585 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
62587 char *old = find_link(major, minor, ino, mode, collected);
62589 - return (sys_link(old, collected) < 0) ? -1 : 1;
62590 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
62594 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
62598 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
62599 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
62600 if (S_ISDIR(st.st_mode))
62602 + sys_rmdir((char __force_user *)path);
62604 - sys_unlink(path);
62605 + sys_unlink((char __force_user *)path);
62609 @@ -305,7 +305,7 @@ static int __init do_name(void)
62610 int openflags = O_WRONLY|O_CREAT;
62612 openflags |= O_TRUNC;
62613 - wfd = sys_open(collected, openflags, mode);
62614 + wfd = sys_open((char __force_user *)collected, openflags, mode);
62617 sys_fchown(wfd, uid, gid);
62618 @@ -317,17 +317,17 @@ static int __init do_name(void)
62621 } else if (S_ISDIR(mode)) {
62622 - sys_mkdir(collected, mode);
62623 - sys_chown(collected, uid, gid);
62624 - sys_chmod(collected, mode);
62625 + sys_mkdir((char __force_user *)collected, mode);
62626 + sys_chown((char __force_user *)collected, uid, gid);
62627 + sys_chmod((char __force_user *)collected, mode);
62628 dir_add(collected, mtime);
62629 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
62630 S_ISFIFO(mode) || S_ISSOCK(mode)) {
62631 if (maybe_link() == 0) {
62632 - sys_mknod(collected, mode, rdev);
62633 - sys_chown(collected, uid, gid);
62634 - sys_chmod(collected, mode);
62635 - do_utime(collected, mtime);
62636 + sys_mknod((char __force_user *)collected, mode, rdev);
62637 + sys_chown((char __force_user *)collected, uid, gid);
62638 + sys_chmod((char __force_user *)collected, mode);
62639 + do_utime((char __force_user *)collected, mtime);
62643 @@ -336,15 +336,15 @@ static int __init do_name(void)
62644 static int __init do_copy(void)
62646 if (count >= body_len) {
62647 - sys_write(wfd, victim, body_len);
62648 + sys_write(wfd, (char __force_user *)victim, body_len);
62650 - do_utime(vcollected, mtime);
62651 + do_utime((char __force_user *)vcollected, mtime);
62657 - sys_write(wfd, victim, count);
62658 + sys_write(wfd, (char __force_user *)victim, count);
62662 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
62664 collected[N_ALIGN(name_len) + body_len] = '\0';
62665 clean_path(collected, 0);
62666 - sys_symlink(collected + N_ALIGN(name_len), collected);
62667 - sys_lchown(collected, uid, gid);
62668 - do_utime(collected, mtime);
62669 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
62670 + sys_lchown((char __force_user *)collected, uid, gid);
62671 + do_utime((char __force_user *)collected, mtime);
62673 next_state = Reset;
62675 diff --git a/init/main.c b/init/main.c
62676 index 217ed23..ec5406f 100644
62679 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
62680 extern void tc_init(void);
62683 +extern void grsecurity_init(void);
62686 * Debug helper: via this flag we know that we are in 'early bootup code'
62687 * where only the boot processor is running with IRQ disabled. This means
62688 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
62690 __setup("reset_devices", set_reset_devices);
62692 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
62693 +extern char pax_enter_kernel_user[];
62694 +extern char pax_exit_kernel_user[];
62695 +extern pgdval_t clone_pgd_mask;
62698 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
62699 +static int __init setup_pax_nouderef(char *str)
62701 +#ifdef CONFIG_X86_32
62702 + unsigned int cpu;
62703 + struct desc_struct *gdt;
62705 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
62706 + gdt = get_cpu_gdt_table(cpu);
62707 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
62708 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
62709 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
62710 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
62712 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
62714 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
62715 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
62716 + clone_pgd_mask = ~(pgdval_t)0UL;
62721 +early_param("pax_nouderef", setup_pax_nouderef);
62724 +#ifdef CONFIG_PAX_SOFTMODE
62727 +static int __init setup_pax_softmode(char *str)
62729 + get_option(&str, &pax_softmode);
62732 +__setup("pax_softmode=", setup_pax_softmode);
62735 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
62736 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
62737 static const char *panic_later, *panic_param;
62738 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
62740 int count = preempt_count();
62742 + const char *msg1 = "", *msg2 = "";
62744 if (initcall_debug)
62745 ret = do_one_initcall_debug(fn);
62746 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
62747 sprintf(msgbuf, "error code %d ", ret);
62749 if (preempt_count() != count) {
62750 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
62751 + msg1 = " preemption imbalance";
62752 preempt_count() = count;
62754 if (irqs_disabled()) {
62755 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
62756 + msg2 = " disabled interrupts";
62757 local_irq_enable();
62760 - printk("initcall %pF returned with %s\n", fn, msgbuf);
62761 + if (msgbuf[0] || *msg1 || *msg2) {
62762 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
62766 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
62769 /* Open the /dev/console on the rootfs, this should never fail */
62770 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
62771 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
62772 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
62775 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
62776 if (!ramdisk_execute_command)
62777 ramdisk_execute_command = "/init";
62779 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
62780 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
62781 ramdisk_execute_command = NULL;
62782 prepare_namespace();
62785 + grsecurity_init();
62788 * Ok, we have completed the initial bootup, and
62789 * we're essentially up and running. Get rid of the
62790 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
62791 index 5b4293d..f179875 100644
62794 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
62795 mq_bytes = (mq_msg_tblsz +
62796 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
62798 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
62799 spin_lock(&mq_lock);
62800 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
62801 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
62802 diff --git a/ipc/msg.c b/ipc/msg.c
62803 index 7385de2..a8180e08 100644
62806 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
62807 return security_msg_queue_associate(msq, msgflg);
62810 +static struct ipc_ops msg_ops = {
62811 + .getnew = newque,
62812 + .associate = msg_security,
62813 + .more_checks = NULL
62816 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
62818 struct ipc_namespace *ns;
62819 - struct ipc_ops msg_ops;
62820 struct ipc_params msg_params;
62822 ns = current->nsproxy->ipc_ns;
62824 - msg_ops.getnew = newque;
62825 - msg_ops.associate = msg_security;
62826 - msg_ops.more_checks = NULL;
62828 msg_params.key = key;
62829 msg_params.flg = msgflg;
62831 diff --git a/ipc/sem.c b/ipc/sem.c
62832 index 5215a81..cfc0cac 100644
62835 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
62839 +static struct ipc_ops sem_ops = {
62840 + .getnew = newary,
62841 + .associate = sem_security,
62842 + .more_checks = sem_more_checks
62845 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62847 struct ipc_namespace *ns;
62848 - struct ipc_ops sem_ops;
62849 struct ipc_params sem_params;
62851 ns = current->nsproxy->ipc_ns;
62852 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62853 if (nsems < 0 || nsems > ns->sc_semmsl)
62856 - sem_ops.getnew = newary;
62857 - sem_ops.associate = sem_security;
62858 - sem_ops.more_checks = sem_more_checks;
62860 sem_params.key = key;
62861 sem_params.flg = semflg;
62862 sem_params.u.nsems = nsems;
62863 diff --git a/ipc/shm.c b/ipc/shm.c
62864 index b76be5b..859e750 100644
62867 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
62868 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
62871 +#ifdef CONFIG_GRKERNSEC
62872 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62873 + const time_t shm_createtime, const uid_t cuid,
62874 + const int shmid);
62875 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62876 + const time_t shm_createtime);
62879 void shm_init_ns(struct ipc_namespace *ns)
62881 ns->shm_ctlmax = SHMMAX;
62882 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
62883 shp->shm_lprid = 0;
62884 shp->shm_atim = shp->shm_dtim = 0;
62885 shp->shm_ctim = get_seconds();
62886 +#ifdef CONFIG_GRKERNSEC
62888 + struct timespec timeval;
62889 + do_posix_clock_monotonic_gettime(&timeval);
62891 + shp->shm_createtime = timeval.tv_sec;
62894 shp->shm_segsz = size;
62895 shp->shm_nattch = 0;
62896 shp->shm_file = file;
62897 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
62901 +static struct ipc_ops shm_ops = {
62902 + .getnew = newseg,
62903 + .associate = shm_security,
62904 + .more_checks = shm_more_checks
62907 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
62909 struct ipc_namespace *ns;
62910 - struct ipc_ops shm_ops;
62911 struct ipc_params shm_params;
62913 ns = current->nsproxy->ipc_ns;
62915 - shm_ops.getnew = newseg;
62916 - shm_ops.associate = shm_security;
62917 - shm_ops.more_checks = shm_more_checks;
62919 shm_params.key = key;
62920 shm_params.flg = shmflg;
62921 shm_params.u.size = size;
62922 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62923 f_mode = FMODE_READ | FMODE_WRITE;
62925 if (shmflg & SHM_EXEC) {
62927 +#ifdef CONFIG_PAX_MPROTECT
62928 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
62933 acc_mode |= S_IXUGO;
62935 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62939 +#ifdef CONFIG_GRKERNSEC
62940 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
62941 + shp->shm_perm.cuid, shmid) ||
62942 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
62948 path = shp->shm_file->f_path;
62951 +#ifdef CONFIG_GRKERNSEC
62952 + shp->shm_lapid = current->pid;
62954 size = i_size_read(path.dentry->d_inode);
62957 diff --git a/kernel/acct.c b/kernel/acct.c
62958 index fa7eb3d..7faf116 100644
62959 --- a/kernel/acct.c
62960 +++ b/kernel/acct.c
62961 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
62963 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
62964 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
62965 - file->f_op->write(file, (char *)&ac,
62966 + file->f_op->write(file, (char __force_user *)&ac,
62967 sizeof(acct_t), &file->f_pos);
62968 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
62970 diff --git a/kernel/audit.c b/kernel/audit.c
62971 index 09fae26..ed71d5b 100644
62972 --- a/kernel/audit.c
62973 +++ b/kernel/audit.c
62974 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
62975 3) suppressed due to audit_rate_limit
62976 4) suppressed due to audit_backlog_limit
62978 -static atomic_t audit_lost = ATOMIC_INIT(0);
62979 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
62981 /* The netlink socket. */
62982 static struct sock *audit_sock;
62983 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
62987 - atomic_inc(&audit_lost);
62988 + atomic_inc_unchecked(&audit_lost);
62990 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
62992 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
62993 printk(KERN_WARNING
62994 "audit: audit_lost=%d audit_rate_limit=%d "
62995 "audit_backlog_limit=%d\n",
62996 - atomic_read(&audit_lost),
62997 + atomic_read_unchecked(&audit_lost),
62999 audit_backlog_limit);
63000 audit_panic(message);
63001 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
63002 status_set.pid = audit_pid;
63003 status_set.rate_limit = audit_rate_limit;
63004 status_set.backlog_limit = audit_backlog_limit;
63005 - status_set.lost = atomic_read(&audit_lost);
63006 + status_set.lost = atomic_read_unchecked(&audit_lost);
63007 status_set.backlog = skb_queue_len(&audit_skb_queue);
63008 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
63009 &status_set, sizeof(status_set));
63010 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
63011 avail = audit_expand(ab,
63012 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
63016 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
63026 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
63027 index 47b7fc1..c003c33 100644
63028 --- a/kernel/auditsc.c
63029 +++ b/kernel/auditsc.c
63030 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
63031 struct audit_buffer **ab,
63032 struct audit_aux_data_execve *axi)
63035 - size_t len, len_sent = 0;
63037 + size_t len_sent = 0;
63038 const char __user *p;
63041 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
63044 /* global counter which is incremented every time something logs in */
63045 -static atomic_t session_id = ATOMIC_INIT(0);
63046 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
63049 * audit_set_loginuid - set a task's audit_context loginuid
63050 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
63052 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
63054 - unsigned int sessionid = atomic_inc_return(&session_id);
63055 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
63056 struct audit_context *context = task->audit_context;
63058 if (context && context->in_syscall) {
63059 diff --git a/kernel/capability.c b/kernel/capability.c
63060 index b463871..fa3ea1f 100644
63061 --- a/kernel/capability.c
63062 +++ b/kernel/capability.c
63063 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
63064 * before modification is attempted and the application
63067 + if (tocopy > ARRAY_SIZE(kdata))
63070 if (copy_to_user(dataptr, kdata, tocopy
63071 * sizeof(struct __user_cap_data_struct))) {
63073 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
63077 - if (security_capable(ns, current_cred(), cap) == 0) {
63078 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
63079 current->flags |= PF_SUPERPRIV;
63082 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
63084 EXPORT_SYMBOL(ns_capable);
63086 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
63088 + if (unlikely(!cap_valid(cap))) {
63089 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
63093 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
63094 + current->flags |= PF_SUPERPRIV;
63099 +EXPORT_SYMBOL(ns_capable_nolog);
63101 +bool capable_nolog(int cap)
63103 + return ns_capable_nolog(&init_user_ns, cap);
63105 +EXPORT_SYMBOL(capable_nolog);
63108 * task_ns_capable - Determine whether current task has a superior
63109 * capability targeted at a specific task's user namespace.
63110 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
63112 EXPORT_SYMBOL(task_ns_capable);
63114 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
63116 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
63118 +EXPORT_SYMBOL(task_ns_capable_nolog);
63121 * nsown_capable - Check superior capability to one's own user_ns
63122 * @cap: The capability in question
63123 diff --git a/kernel/compat.c b/kernel/compat.c
63124 index f346ced..aa2b1f4 100644
63125 --- a/kernel/compat.c
63126 +++ b/kernel/compat.c
63129 #include <linux/linkage.h>
63130 #include <linux/compat.h>
63131 +#include <linux/module.h>
63132 #include <linux/errno.h>
63133 #include <linux/time.h>
63134 #include <linux/signal.h>
63135 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
63136 mm_segment_t oldfs;
63139 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
63140 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
63143 ret = hrtimer_nanosleep_restart(restart);
63144 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
63147 ret = hrtimer_nanosleep(&tu,
63148 - rmtp ? (struct timespec __user *)&rmt : NULL,
63149 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
63150 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
63153 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
63154 mm_segment_t old_fs = get_fs();
63157 - ret = sys_sigpending((old_sigset_t __user *) &s);
63158 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
63161 ret = put_user(s, set);
63162 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
63165 ret = sys_sigprocmask(how,
63166 - set ? (old_sigset_t __user *) &s : NULL,
63167 - oset ? (old_sigset_t __user *) &s : NULL);
63168 + set ? (old_sigset_t __force_user *) &s : NULL,
63169 + oset ? (old_sigset_t __force_user *) &s : NULL);
63173 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
63174 mm_segment_t old_fs = get_fs();
63177 - ret = sys_old_getrlimit(resource, &r);
63178 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
63182 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
63183 mm_segment_t old_fs = get_fs();
63186 - ret = sys_getrusage(who, (struct rusage __user *) &r);
63187 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
63191 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
63192 set_fs (KERNEL_DS);
63193 ret = sys_wait4(pid,
63195 - (unsigned int __user *) &status : NULL),
63196 - options, (struct rusage __user *) &r);
63197 + (unsigned int __force_user *) &status : NULL),
63198 + options, (struct rusage __force_user *) &r);
63202 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
63203 memset(&info, 0, sizeof(info));
63206 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
63207 - uru ? (struct rusage __user *)&ru : NULL);
63208 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
63209 + uru ? (struct rusage __force_user *)&ru : NULL);
63212 if ((ret < 0) || (info.si_signo == 0))
63213 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
63216 err = sys_timer_settime(timer_id, flags,
63217 - (struct itimerspec __user *) &newts,
63218 - (struct itimerspec __user *) &oldts);
63219 + (struct itimerspec __force_user *) &newts,
63220 + (struct itimerspec __force_user *) &oldts);
63222 if (!err && old && put_compat_itimerspec(old, &oldts))
63224 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
63227 err = sys_timer_gettime(timer_id,
63228 - (struct itimerspec __user *) &ts);
63229 + (struct itimerspec __force_user *) &ts);
63231 if (!err && put_compat_itimerspec(setting, &ts))
63233 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
63236 err = sys_clock_settime(which_clock,
63237 - (struct timespec __user *) &ts);
63238 + (struct timespec __force_user *) &ts);
63242 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
63245 err = sys_clock_gettime(which_clock,
63246 - (struct timespec __user *) &ts);
63247 + (struct timespec __force_user *) &ts);
63249 if (!err && put_compat_timespec(&ts, tp))
63251 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
63255 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
63256 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
63259 err = compat_put_timex(utp, &txc);
63260 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
63263 err = sys_clock_getres(which_clock,
63264 - (struct timespec __user *) &ts);
63265 + (struct timespec __force_user *) &ts);
63267 if (!err && tp && put_compat_timespec(&ts, tp))
63269 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
63271 mm_segment_t oldfs;
63272 struct timespec tu;
63273 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
63274 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
63276 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
63277 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
63280 err = clock_nanosleep_restart(restart);
63281 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
63284 err = sys_clock_nanosleep(which_clock, flags,
63285 - (struct timespec __user *) &in,
63286 - (struct timespec __user *) &out);
63287 + (struct timespec __force_user *) &in,
63288 + (struct timespec __force_user *) &out);
63291 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
63292 diff --git a/kernel/configs.c b/kernel/configs.c
63293 index 42e8fa0..9e7406b 100644
63294 --- a/kernel/configs.c
63295 +++ b/kernel/configs.c
63296 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
63297 struct proc_dir_entry *entry;
63299 /* create the current config file */
63300 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63301 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
63302 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
63303 + &ikconfig_file_ops);
63304 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63305 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
63306 + &ikconfig_file_ops);
63309 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
63310 &ikconfig_file_ops);
63316 diff --git a/kernel/cred.c b/kernel/cred.c
63317 index 5791612..a3c04dc 100644
63318 --- a/kernel/cred.c
63319 +++ b/kernel/cred.c
63320 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
63321 validate_creds(cred);
63325 +#ifdef CONFIG_GRKERNSEC_SETXID
63326 + cred = (struct cred *) tsk->delayed_cred;
63328 + tsk->delayed_cred = NULL;
63329 + validate_creds(cred);
63336 @@ -470,7 +479,7 @@ error_put:
63337 * Always returns 0 thus allowing this function to be tail-called at the end
63338 * of, say, sys_setgid().
63340 -int commit_creds(struct cred *new)
63341 +static int __commit_creds(struct cred *new)
63343 struct task_struct *task = current;
63344 const struct cred *old = task->real_cred;
63345 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
63347 get_cred(new); /* we will require a ref for the subj creds too */
63349 + gr_set_role_label(task, new->uid, new->gid);
63351 /* dumpability changes */
63352 if (old->euid != new->euid ||
63353 old->egid != new->egid ||
63354 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
63358 +#ifdef CONFIG_GRKERNSEC_SETXID
63359 +extern int set_user(struct cred *new);
63361 +void gr_delayed_cred_worker(void)
63363 + const struct cred *new = current->delayed_cred;
63364 + struct cred *ncred;
63366 + current->delayed_cred = NULL;
63368 + if (current_uid() && new != NULL) {
63369 + // from doing get_cred on it when queueing this
63372 + } else if (new == NULL)
63375 + ncred = prepare_creds();
63379 + ncred->uid = new->uid;
63380 + ncred->euid = new->euid;
63381 + ncred->suid = new->suid;
63382 + ncred->fsuid = new->fsuid;
63384 + ncred->gid = new->gid;
63385 + ncred->egid = new->egid;
63386 + ncred->sgid = new->sgid;
63387 + ncred->fsgid = new->fsgid;
63389 + if (set_groups(ncred, new->group_info) < 0) {
63390 + abort_creds(ncred);
63394 + ncred->securebits = new->securebits;
63395 + ncred->cap_inheritable = new->cap_inheritable;
63396 + ncred->cap_permitted = new->cap_permitted;
63397 + ncred->cap_effective = new->cap_effective;
63398 + ncred->cap_bset = new->cap_bset;
63400 + if (set_user(ncred)) {
63401 + abort_creds(ncred);
63405 + // from doing get_cred on it when queueing this
63408 + __commit_creds(ncred);
63411 + // from doing get_cred on it when queueing this
63413 + do_group_exit(SIGKILL);
63417 +int commit_creds(struct cred *new)
63419 +#ifdef CONFIG_GRKERNSEC_SETXID
63420 + struct task_struct *t;
63422 + /* we won't get called with tasklist_lock held for writing
63423 + and interrupts disabled as the cred struct in that case is
63426 + if (grsec_enable_setxid && !current_is_single_threaded() &&
63427 + !current_uid() && new->uid) {
63429 + read_lock(&tasklist_lock);
63430 + for (t = next_thread(current); t != current;
63431 + t = next_thread(t)) {
63432 + if (t->delayed_cred == NULL) {
63433 + t->delayed_cred = get_cred(new);
63434 + set_tsk_need_resched(t);
63437 + read_unlock(&tasklist_lock);
63438 + rcu_read_unlock();
63441 + return __commit_creds(new);
63444 EXPORT_SYMBOL(commit_creds);
63447 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
63448 index 0d7c087..01b8cef 100644
63449 --- a/kernel/debug/debug_core.c
63450 +++ b/kernel/debug/debug_core.c
63451 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
63453 static atomic_t masters_in_kgdb;
63454 static atomic_t slaves_in_kgdb;
63455 -static atomic_t kgdb_break_tasklet_var;
63456 +static atomic_unchecked_t kgdb_break_tasklet_var;
63457 atomic_t kgdb_setting_breakpoint;
63459 struct task_struct *kgdb_usethread;
63460 @@ -129,7 +129,7 @@ int kgdb_single_step;
63461 static pid_t kgdb_sstep_pid;
63463 /* to keep track of the CPU which is doing the single stepping*/
63464 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63465 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63468 * If you are debugging a problem where roundup (the collection of
63469 @@ -542,7 +542,7 @@ return_normal:
63470 * kernel will only try for the value of sstep_tries before
63471 * giving up and continuing on.
63473 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
63474 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
63475 (kgdb_info[cpu].task &&
63476 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
63477 atomic_set(&kgdb_active, -1);
63478 @@ -636,8 +636,8 @@ cpu_master_loop:
63482 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
63483 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
63484 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
63485 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
63486 if (kgdb_info[sstep_cpu].task)
63487 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
63489 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
63490 static void kgdb_tasklet_bpt(unsigned long ing)
63493 - atomic_set(&kgdb_break_tasklet_var, 0);
63494 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
63497 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
63499 void kgdb_schedule_breakpoint(void)
63501 - if (atomic_read(&kgdb_break_tasklet_var) ||
63502 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
63503 atomic_read(&kgdb_active) != -1 ||
63504 atomic_read(&kgdb_setting_breakpoint))
63506 - atomic_inc(&kgdb_break_tasklet_var);
63507 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
63508 tasklet_schedule(&kgdb_tasklet_breakpoint);
63510 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
63511 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
63512 index 63786e7..0780cac 100644
63513 --- a/kernel/debug/kdb/kdb_main.c
63514 +++ b/kernel/debug/kdb/kdb_main.c
63515 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
63516 list_for_each_entry(mod, kdb_modules, list) {
63518 kdb_printf("%-20s%8u 0x%p ", mod->name,
63519 - mod->core_size, (void *)mod);
63520 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
63521 #ifdef CONFIG_MODULE_UNLOAD
63522 kdb_printf("%4d ", module_refcount(mod));
63524 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
63525 kdb_printf(" (Loading)");
63527 kdb_printf(" (Live)");
63528 - kdb_printf(" 0x%p", mod->module_core);
63529 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
63531 #ifdef CONFIG_MODULE_UNLOAD
63533 diff --git a/kernel/events/core.c b/kernel/events/core.c
63534 index 58690af..d903d75 100644
63535 --- a/kernel/events/core.c
63536 +++ b/kernel/events/core.c
63537 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
63541 -static atomic64_t perf_event_id;
63542 +static atomic64_unchecked_t perf_event_id;
63544 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
63545 enum event_type_t event_type);
63546 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
63548 static inline u64 perf_event_count(struct perf_event *event)
63550 - return local64_read(&event->count) + atomic64_read(&event->child_count);
63551 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
63554 static u64 perf_event_read(struct perf_event *event)
63555 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
63556 mutex_lock(&event->child_mutex);
63557 total += perf_event_read(event);
63558 *enabled += event->total_time_enabled +
63559 - atomic64_read(&event->child_total_time_enabled);
63560 + atomic64_read_unchecked(&event->child_total_time_enabled);
63561 *running += event->total_time_running +
63562 - atomic64_read(&event->child_total_time_running);
63563 + atomic64_read_unchecked(&event->child_total_time_running);
63565 list_for_each_entry(child, &event->child_list, child_list) {
63566 total += perf_event_read(child);
63567 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
63568 userpg->offset -= local64_read(&event->hw.prev_count);
63570 userpg->time_enabled = enabled +
63571 - atomic64_read(&event->child_total_time_enabled);
63572 + atomic64_read_unchecked(&event->child_total_time_enabled);
63574 userpg->time_running = running +
63575 - atomic64_read(&event->child_total_time_running);
63576 + atomic64_read_unchecked(&event->child_total_time_running);
63580 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
63581 values[n++] = perf_event_count(event);
63582 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
63583 values[n++] = enabled +
63584 - atomic64_read(&event->child_total_time_enabled);
63585 + atomic64_read_unchecked(&event->child_total_time_enabled);
63587 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
63588 values[n++] = running +
63589 - atomic64_read(&event->child_total_time_running);
63590 + atomic64_read_unchecked(&event->child_total_time_running);
63592 if (read_format & PERF_FORMAT_ID)
63593 values[n++] = primary_event_id(event);
63594 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
63595 * need to add enough zero bytes after the string to handle
63596 * the 64bit alignment we do later.
63598 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
63599 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
63601 name = strncpy(tmp, "//enomem", sizeof(tmp));
63604 - name = d_path(&file->f_path, buf, PATH_MAX);
63605 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
63606 if (IS_ERR(name)) {
63607 name = strncpy(tmp, "//toolong", sizeof(tmp));
63609 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
63610 event->parent = parent_event;
63612 event->ns = get_pid_ns(current->nsproxy->pid_ns);
63613 - event->id = atomic64_inc_return(&perf_event_id);
63614 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
63616 event->state = PERF_EVENT_STATE_INACTIVE;
63618 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
63620 * Add back the child's count to the parent's count:
63622 - atomic64_add(child_val, &parent_event->child_count);
63623 - atomic64_add(child_event->total_time_enabled,
63624 + atomic64_add_unchecked(child_val, &parent_event->child_count);
63625 + atomic64_add_unchecked(child_event->total_time_enabled,
63626 &parent_event->child_total_time_enabled);
63627 - atomic64_add(child_event->total_time_running,
63628 + atomic64_add_unchecked(child_event->total_time_running,
63629 &parent_event->child_total_time_running);
63632 diff --git a/kernel/exit.c b/kernel/exit.c
63633 index e6e01b9..619f837 100644
63634 --- a/kernel/exit.c
63635 +++ b/kernel/exit.c
63637 #include <asm/pgtable.h>
63638 #include <asm/mmu_context.h>
63640 +#ifdef CONFIG_GRKERNSEC
63641 +extern rwlock_t grsec_exec_file_lock;
63644 static void exit_mm(struct task_struct * tsk);
63646 static void __unhash_process(struct task_struct *p, bool group_dead)
63647 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
63648 struct task_struct *leader;
63652 + gr_del_task_from_ip_table(p);
63655 /* don't need to get the RCU readlock here - the process is dead and
63656 * can't be modifying its own credentials. But shut RCU-lockdep up */
63658 @@ -380,7 +388,7 @@ int allow_signal(int sig)
63659 * know it'll be handled, so that they don't get converted to
63660 * SIGKILL or just silently dropped.
63662 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
63663 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
63664 recalc_sigpending();
63665 spin_unlock_irq(¤t->sighand->siglock);
63667 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
63668 vsnprintf(current->comm, sizeof(current->comm), name, args);
63671 +#ifdef CONFIG_GRKERNSEC
63672 + write_lock(&grsec_exec_file_lock);
63673 + if (current->exec_file) {
63674 + fput(current->exec_file);
63675 + current->exec_file = NULL;
63677 + write_unlock(&grsec_exec_file_lock);
63680 + gr_set_kernel_label(current);
63683 * If we were started as result of loading a module, close all of the
63684 * user space pages. We don't need them, and if we didn't close them
63685 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
63686 struct task_struct *tsk = current;
63691 profile_task_exit(tsk);
63693 WARN_ON(blk_needs_flush_plug(tsk));
63694 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
63695 * mm_release()->clear_child_tid() from writing to a user-controlled
63700 ptrace_event(PTRACE_EVENT_EXIT, code);
63702 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
63703 tsk->exit_code = code;
63704 taskstats_exit(tsk, group_dead);
63706 + gr_acl_handle_psacct(tsk, code);
63707 + gr_acl_handle_exit();
63712 diff --git a/kernel/fork.c b/kernel/fork.c
63713 index 0acf42c0..9e40e2e 100644
63714 --- a/kernel/fork.c
63715 +++ b/kernel/fork.c
63716 @@ -281,7 +281,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
63717 *stackend = STACK_END_MAGIC; /* for overflow detection */
63719 #ifdef CONFIG_CC_STACKPROTECTOR
63720 - tsk->stack_canary = get_random_int();
63721 + tsk->stack_canary = pax_get_random_long();
63725 @@ -305,13 +305,77 @@ out:
63729 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
63731 + struct vm_area_struct *tmp;
63732 + unsigned long charge;
63733 + struct mempolicy *pol;
63734 + struct file *file;
63737 + if (mpnt->vm_flags & VM_ACCOUNT) {
63738 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63739 + if (security_vm_enough_memory(len))
63743 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63748 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
63749 + pol = mpol_dup(vma_policy(mpnt));
63751 + goto fail_nomem_policy;
63752 + vma_set_policy(tmp, pol);
63753 + if (anon_vma_fork(tmp, mpnt))
63754 + goto fail_nomem_anon_vma_fork;
63755 + tmp->vm_flags &= ~VM_LOCKED;
63756 + tmp->vm_next = tmp->vm_prev = NULL;
63757 + tmp->vm_mirror = NULL;
63758 + file = tmp->vm_file;
63760 + struct inode *inode = file->f_path.dentry->d_inode;
63761 + struct address_space *mapping = file->f_mapping;
63764 + if (tmp->vm_flags & VM_DENYWRITE)
63765 + atomic_dec(&inode->i_writecount);
63766 + mutex_lock(&mapping->i_mmap_mutex);
63767 + if (tmp->vm_flags & VM_SHARED)
63768 + mapping->i_mmap_writable++;
63769 + flush_dcache_mmap_lock(mapping);
63770 + /* insert tmp into the share list, just after mpnt */
63771 + vma_prio_tree_add(tmp, mpnt);
63772 + flush_dcache_mmap_unlock(mapping);
63773 + mutex_unlock(&mapping->i_mmap_mutex);
63777 + * Clear hugetlb-related page reserves for children. This only
63778 + * affects MAP_PRIVATE mappings. Faults generated by the child
63779 + * are not guaranteed to succeed, even if read-only
63781 + if (is_vm_hugetlb_page(tmp))
63782 + reset_vma_resv_huge_pages(tmp);
63786 +fail_nomem_anon_vma_fork:
63788 +fail_nomem_policy:
63789 + kmem_cache_free(vm_area_cachep, tmp);
63791 + vm_unacct_memory(charge);
63795 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63797 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
63798 struct rb_node **rb_link, *rb_parent;
63800 - unsigned long charge;
63801 - struct mempolicy *pol;
63803 down_write(&oldmm->mmap_sem);
63804 flush_cache_dup_mm(oldmm);
63805 @@ -323,8 +387,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63808 mm->mmap_cache = NULL;
63809 - mm->free_area_cache = oldmm->mmap_base;
63810 - mm->cached_hole_size = ~0UL;
63811 + mm->free_area_cache = oldmm->free_area_cache;
63812 + mm->cached_hole_size = oldmm->cached_hole_size;
63814 cpumask_clear(mm_cpumask(mm));
63815 mm->mm_rb = RB_ROOT;
63816 @@ -340,8 +404,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63819 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
63820 - struct file *file;
63822 if (mpnt->vm_flags & VM_DONTCOPY) {
63823 long pages = vma_pages(mpnt);
63824 mm->total_vm -= pages;
63825 @@ -349,53 +411,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63830 - if (mpnt->vm_flags & VM_ACCOUNT) {
63831 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63832 - if (security_vm_enough_memory(len))
63835 + tmp = dup_vma(mm, mpnt);
63837 + retval = -ENOMEM;
63840 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63844 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
63845 - pol = mpol_dup(vma_policy(mpnt));
63846 - retval = PTR_ERR(pol);
63848 - goto fail_nomem_policy;
63849 - vma_set_policy(tmp, pol);
63851 - if (anon_vma_fork(tmp, mpnt))
63852 - goto fail_nomem_anon_vma_fork;
63853 - tmp->vm_flags &= ~VM_LOCKED;
63854 - tmp->vm_next = tmp->vm_prev = NULL;
63855 - file = tmp->vm_file;
63857 - struct inode *inode = file->f_path.dentry->d_inode;
63858 - struct address_space *mapping = file->f_mapping;
63861 - if (tmp->vm_flags & VM_DENYWRITE)
63862 - atomic_dec(&inode->i_writecount);
63863 - mutex_lock(&mapping->i_mmap_mutex);
63864 - if (tmp->vm_flags & VM_SHARED)
63865 - mapping->i_mmap_writable++;
63866 - flush_dcache_mmap_lock(mapping);
63867 - /* insert tmp into the share list, just after mpnt */
63868 - vma_prio_tree_add(tmp, mpnt);
63869 - flush_dcache_mmap_unlock(mapping);
63870 - mutex_unlock(&mapping->i_mmap_mutex);
63874 - * Clear hugetlb-related page reserves for children. This only
63875 - * affects MAP_PRIVATE mappings. Faults generated by the child
63876 - * are not guaranteed to succeed, even if read-only
63878 - if (is_vm_hugetlb_page(tmp))
63879 - reset_vma_resv_huge_pages(tmp);
63882 * Link in the new vma and copy the page table entries.
63883 @@ -418,6 +438,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63888 +#ifdef CONFIG_PAX_SEGMEXEC
63889 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
63890 + struct vm_area_struct *mpnt_m;
63892 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
63893 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
63895 + if (!mpnt->vm_mirror)
63898 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
63899 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
63900 + mpnt->vm_mirror = mpnt_m;
63902 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
63903 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
63904 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
63905 + mpnt->vm_mirror->vm_mirror = mpnt;
63912 /* a new mm has just been created */
63913 arch_dup_mmap(oldmm, mm);
63915 @@ -426,14 +471,6 @@ out:
63916 flush_tlb_mm(oldmm);
63917 up_write(&oldmm->mmap_sem);
63919 -fail_nomem_anon_vma_fork:
63921 -fail_nomem_policy:
63922 - kmem_cache_free(vm_area_cachep, tmp);
63924 - retval = -ENOMEM;
63925 - vm_unacct_memory(charge);
63929 static inline int mm_alloc_pgd(struct mm_struct *mm)
63930 @@ -645,6 +682,26 @@ struct mm_struct *get_task_mm(struct task_struct *task)
63932 EXPORT_SYMBOL_GPL(get_task_mm);
63934 +struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
63936 + struct mm_struct *mm;
63939 + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
63941 + return ERR_PTR(err);
63943 + mm = get_task_mm(task);
63944 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
63945 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
63947 + mm = ERR_PTR(-EACCES);
63949 + mutex_unlock(&task->signal->cred_guard_mutex);
63954 /* Please note the differences between mmput and mm_release.
63955 * mmput is called whenever we stop holding onto a mm_struct,
63956 * error success whatever.
63957 @@ -830,13 +887,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
63958 spin_unlock(&fs->lock);
63962 + atomic_inc(&fs->users);
63963 spin_unlock(&fs->lock);
63966 tsk->fs = copy_fs_struct(fs);
63969 + gr_set_chroot_entries(tsk, &tsk->fs->root);
63973 @@ -1100,6 +1158,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63974 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
63978 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
63980 if (atomic_read(&p->real_cred->user->processes) >=
63981 task_rlimit(p, RLIMIT_NPROC)) {
63982 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
63983 @@ -1259,6 +1320,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63984 if (clone_flags & CLONE_THREAD)
63985 p->tgid = current->tgid;
63987 + gr_copy_label(p);
63989 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
63991 * Clear TID on mm_release()?
63992 @@ -1421,6 +1484,8 @@ bad_fork_cleanup_count:
63996 + gr_log_forkfail(retval);
63998 return ERR_PTR(retval);
64001 @@ -1521,6 +1586,8 @@ long do_fork(unsigned long clone_flags,
64002 if (clone_flags & CLONE_PARENT_SETTID)
64003 put_user(nr, parent_tidptr);
64005 + gr_handle_brute_check();
64007 if (clone_flags & CLONE_VFORK) {
64008 p->vfork_done = &vfork;
64009 init_completion(&vfork);
64010 @@ -1630,7 +1697,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
64013 /* don't need lock here; in the worst case we'll do useless copy */
64014 - if (fs->users == 1)
64015 + if (atomic_read(&fs->users) == 1)
64018 *new_fsp = copy_fs_struct(fs);
64019 @@ -1719,7 +1786,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
64021 spin_lock(&fs->lock);
64022 current->fs = new_fs;
64024 + gr_set_chroot_entries(current, ¤t->fs->root);
64025 + if (atomic_dec_return(&fs->users))
64029 diff --git a/kernel/futex.c b/kernel/futex.c
64030 index 1614be2..37abc7e 100644
64031 --- a/kernel/futex.c
64032 +++ b/kernel/futex.c
64034 #include <linux/mount.h>
64035 #include <linux/pagemap.h>
64036 #include <linux/syscalls.h>
64037 +#include <linux/ptrace.h>
64038 #include <linux/signal.h>
64039 #include <linux/export.h>
64040 #include <linux/magic.h>
64041 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
64042 struct page *page, *page_head;
64045 +#ifdef CONFIG_PAX_SEGMEXEC
64046 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
64051 * The futex address must be "naturally" aligned.
64053 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
64057 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64058 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
64061 pcred = __task_cred(p);
64062 /* If victim is in different user_ns, then uids are not
64063 comparable, so we must have CAP_SYS_PTRACE */
64064 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
64068 + mm_segment_t oldfs;
64071 * This will fail and we want it. Some arch implementations do
64072 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
64073 * implementation, the non-functional ones will return
64076 + oldfs = get_fs();
64078 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
64079 futex_cmpxchg_enabled = 1;
64082 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
64083 plist_head_init(&futex_queues[i].chain);
64084 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
64085 index 5f9e689..582d46d 100644
64086 --- a/kernel/futex_compat.c
64087 +++ b/kernel/futex_compat.c
64089 #include <linux/compat.h>
64090 #include <linux/nsproxy.h>
64091 #include <linux/futex.h>
64092 +#include <linux/ptrace.h>
64094 #include <asm/uaccess.h>
64096 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
64098 struct compat_robust_list_head __user *head;
64100 - const struct cred *cred = current_cred(), *pcred;
64101 + const struct cred *cred = current_cred();
64102 + const struct cred *pcred;
64104 if (!futex_cmpxchg_enabled)
64106 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
64110 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64111 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
64114 pcred = __task_cred(p);
64115 /* If victim is in different user_ns, then uids are not
64116 comparable, so we must have CAP_SYS_PTRACE */
64117 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
64118 index 9b22d03..6295b62 100644
64119 --- a/kernel/gcov/base.c
64120 +++ b/kernel/gcov/base.c
64121 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
64124 #ifdef CONFIG_MODULES
64125 -static inline int within(void *addr, void *start, unsigned long size)
64127 - return ((addr >= start) && (addr < start + size));
64130 /* Update list and generate events when modules are unloaded. */
64131 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
64133 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
64135 /* Remove entries located in module from linked list. */
64136 for (info = gcov_info_head; info; info = info->next) {
64137 - if (within(info, mod->module_core, mod->core_size)) {
64138 + if (within_module_core_rw((unsigned long)info, mod)) {
64140 prev->next = info->next;
64142 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
64143 index ae34bf5..4e2f3d0 100644
64144 --- a/kernel/hrtimer.c
64145 +++ b/kernel/hrtimer.c
64146 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
64147 local_irq_restore(flags);
64150 -static void run_hrtimer_softirq(struct softirq_action *h)
64151 +static void run_hrtimer_softirq(void)
64153 hrtimer_peek_ahead_timers();
64155 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
64156 index 66ff710..05a5128 100644
64157 --- a/kernel/jump_label.c
64158 +++ b/kernel/jump_label.c
64159 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
64161 size = (((unsigned long)stop - (unsigned long)start)
64162 / sizeof(struct jump_entry));
64163 + pax_open_kernel();
64164 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
64165 + pax_close_kernel();
64168 static void jump_label_update(struct jump_label_key *key, int enable);
64169 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
64170 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
64171 struct jump_entry *iter;
64173 + pax_open_kernel();
64174 for (iter = iter_start; iter < iter_stop; iter++) {
64175 if (within_module_init(iter->code, mod))
64178 + pax_close_kernel();
64182 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
64183 index 079f1d3..a407562 100644
64184 --- a/kernel/kallsyms.c
64185 +++ b/kernel/kallsyms.c
64187 * Changed the compression method from stem compression to "table lookup"
64188 * compression (see scripts/kallsyms.c for a more complete description)
64190 +#ifdef CONFIG_GRKERNSEC_HIDESYM
64191 +#define __INCLUDED_BY_HIDESYM 1
64193 #include <linux/kallsyms.h>
64194 #include <linux/module.h>
64195 #include <linux/init.h>
64196 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
64198 static inline int is_kernel_inittext(unsigned long addr)
64200 + if (system_state != SYSTEM_BOOTING)
64203 if (addr >= (unsigned long)_sinittext
64204 && addr <= (unsigned long)_einittext)
64209 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
64210 +#ifdef CONFIG_MODULES
64211 +static inline int is_module_text(unsigned long addr)
64213 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
64216 + addr = ktla_ktva(addr);
64217 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
64220 +static inline int is_module_text(unsigned long addr)
64227 static inline int is_kernel_text(unsigned long addr)
64229 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
64230 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
64232 static inline int is_kernel(unsigned long addr)
64235 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
64236 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
64239 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
64241 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
64245 return in_gate_area_no_mm(addr);
64248 static int is_ksym_addr(unsigned long addr)
64251 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
64252 + if (is_module_text(addr))
64257 return is_kernel(addr);
64259 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
64261 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
64263 - iter->name[0] = '\0';
64264 iter->nameoff = get_symbol_offset(new_pos);
64265 iter->pos = new_pos;
64267 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
64269 struct kallsym_iter *iter = m->private;
64271 +#ifdef CONFIG_GRKERNSEC_HIDESYM
64272 + if (current_uid())
64276 /* Some debugging symbols have no name. Ignore them. */
64277 if (!iter->name[0])
64279 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
64280 struct kallsym_iter *iter;
64283 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
64284 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
64287 reset_iter(iter, 0);
64288 diff --git a/kernel/kexec.c b/kernel/kexec.c
64289 index dc7bc08..4601964 100644
64290 --- a/kernel/kexec.c
64291 +++ b/kernel/kexec.c
64292 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
64293 unsigned long flags)
64295 struct compat_kexec_segment in;
64296 - struct kexec_segment out, __user *ksegments;
64297 + struct kexec_segment out;
64298 + struct kexec_segment __user *ksegments;
64299 unsigned long i, result;
64301 /* Don't allow clients that don't understand the native
64302 diff --git a/kernel/kmod.c b/kernel/kmod.c
64303 index a4bea97..7a1ae9a 100644
64304 --- a/kernel/kmod.c
64305 +++ b/kernel/kmod.c
64306 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
64307 * If module auto-loading support is disabled then this function
64308 * becomes a no-operation.
64310 -int __request_module(bool wait, const char *fmt, ...)
64311 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
64314 char module_name[MODULE_NAME_LEN];
64315 unsigned int max_modprobes;
64317 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
64318 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
64319 static char *envp[] = { "HOME=/",
64321 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
64322 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
64323 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
64324 static int kmod_loop_msg;
64326 - va_start(args, fmt);
64327 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
64329 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
64330 if (ret >= MODULE_NAME_LEN)
64331 return -ENAMETOOLONG;
64333 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
64337 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64338 + if (!current_uid()) {
64339 + /* hack to workaround consolekit/udisks stupidity */
64340 + read_lock(&tasklist_lock);
64341 + if (!strcmp(current->comm, "mount") &&
64342 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
64343 + read_unlock(&tasklist_lock);
64344 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
64347 + read_unlock(&tasklist_lock);
64351 /* If modprobe needs a service that is in a module, we get a recursive
64352 * loop. Limit the number of running kmod threads to max_threads/2 or
64353 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
64354 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
64355 atomic_dec(&kmod_concurrent);
64359 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
64364 + va_start(args, fmt);
64365 + ret = ____request_module(wait, module_param, fmt, args);
64371 +int __request_module(bool wait, const char *fmt, ...)
64376 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64377 + if (current_uid()) {
64378 + char module_param[MODULE_NAME_LEN];
64380 + memset(module_param, 0, sizeof(module_param));
64382 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
64384 + va_start(args, fmt);
64385 + ret = ____request_module(wait, module_param, fmt, args);
64392 + va_start(args, fmt);
64393 + ret = ____request_module(wait, NULL, fmt, args);
64399 EXPORT_SYMBOL(__request_module);
64400 #endif /* CONFIG_MODULES */
64402 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
64404 * Thus the __user pointer cast is valid here.
64406 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
64407 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
64410 * If ret is 0, either ____call_usermodehelper failed and the
64411 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
64412 index faa39d1..d7ad37e 100644
64413 --- a/kernel/kprobes.c
64414 +++ b/kernel/kprobes.c
64415 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
64416 * kernel image and loaded module images reside. This is required
64417 * so x86_64 can correctly handle the %rip-relative fixups.
64419 - kip->insns = module_alloc(PAGE_SIZE);
64420 + kip->insns = module_alloc_exec(PAGE_SIZE);
64424 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
64426 if (!list_is_singular(&kip->list)) {
64427 list_del(&kip->list);
64428 - module_free(NULL, kip->insns);
64429 + module_free_exec(NULL, kip->insns);
64433 @@ -1953,7 +1953,7 @@ static int __init init_kprobes(void)
64436 unsigned long offset = 0, size = 0;
64437 - char *modname, namebuf[128];
64438 + char *modname, namebuf[KSYM_NAME_LEN];
64439 const char *symbol_name;
64441 struct kprobe_blackpoint *kb;
64442 @@ -2079,7 +2079,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
64443 const char *sym = NULL;
64444 unsigned int i = *(loff_t *) v;
64445 unsigned long offset = 0;
64446 - char *modname, namebuf[128];
64447 + char *modname, namebuf[KSYM_NAME_LEN];
64449 head = &kprobe_table[i];
64451 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
64452 index b2e08c9..01d8049 100644
64453 --- a/kernel/lockdep.c
64454 +++ b/kernel/lockdep.c
64455 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
64456 end = (unsigned long) &_end,
64457 addr = (unsigned long) obj;
64459 +#ifdef CONFIG_PAX_KERNEXEC
64460 + start = ktla_ktva(start);
64466 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
64467 if (!static_obj(lock->key)) {
64469 printk("INFO: trying to register non-static key.\n");
64470 + printk("lock:%pS key:%pS.\n", lock, lock->key);
64471 printk("the code is fine but needs lockdep annotation.\n");
64472 printk("turning off the locking correctness validator.\n");
64474 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
64478 - atomic_inc((atomic_t *)&class->ops);
64479 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
64480 if (very_verbose(class)) {
64481 printk("\nacquire class [%p] %s", class->key, class->name);
64482 if (class->name_version > 1)
64483 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
64484 index 91c32a0..b2c71c5 100644
64485 --- a/kernel/lockdep_proc.c
64486 +++ b/kernel/lockdep_proc.c
64487 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
64489 static void print_name(struct seq_file *m, struct lock_class *class)
64492 + char str[KSYM_NAME_LEN];
64493 const char *name = class->name;
64496 diff --git a/kernel/module.c b/kernel/module.c
64497 index 178333c..04e3408 100644
64498 --- a/kernel/module.c
64499 +++ b/kernel/module.c
64501 #include <linux/jump_label.h>
64502 #include <linux/pfn.h>
64503 #include <linux/bsearch.h>
64504 +#include <linux/grsecurity.h>
64506 #define CREATE_TRACE_POINTS
64507 #include <trace/events/module.h>
64508 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
64510 /* Bounds of module allocation, for speeding __module_address.
64511 * Protected by module_mutex. */
64512 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
64513 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
64514 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
64516 int register_module_notifier(struct notifier_block * nb)
64518 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64521 list_for_each_entry_rcu(mod, &modules, list) {
64522 - struct symsearch arr[] = {
64523 + struct symsearch modarr[] = {
64524 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
64525 NOT_GPL_ONLY, false },
64526 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
64527 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64531 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
64532 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
64536 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
64537 static int percpu_modalloc(struct module *mod,
64538 unsigned long size, unsigned long align)
64540 - if (align > PAGE_SIZE) {
64541 + if (align-1 >= PAGE_SIZE) {
64542 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
64543 mod->name, align, PAGE_SIZE);
64545 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
64547 #ifdef CONFIG_SYSFS
64549 -#ifdef CONFIG_KALLSYMS
64550 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64551 static inline bool sect_empty(const Elf_Shdr *sect)
64553 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
64554 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
64556 static void unset_module_core_ro_nx(struct module *mod)
64558 - set_page_attributes(mod->module_core + mod->core_text_size,
64559 - mod->module_core + mod->core_size,
64560 + set_page_attributes(mod->module_core_rw,
64561 + mod->module_core_rw + mod->core_size_rw,
64563 - set_page_attributes(mod->module_core,
64564 - mod->module_core + mod->core_ro_size,
64565 + set_page_attributes(mod->module_core_rx,
64566 + mod->module_core_rx + mod->core_size_rx,
64570 static void unset_module_init_ro_nx(struct module *mod)
64572 - set_page_attributes(mod->module_init + mod->init_text_size,
64573 - mod->module_init + mod->init_size,
64574 + set_page_attributes(mod->module_init_rw,
64575 + mod->module_init_rw + mod->init_size_rw,
64577 - set_page_attributes(mod->module_init,
64578 - mod->module_init + mod->init_ro_size,
64579 + set_page_attributes(mod->module_init_rx,
64580 + mod->module_init_rx + mod->init_size_rx,
64584 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
64586 mutex_lock(&module_mutex);
64587 list_for_each_entry_rcu(mod, &modules, list) {
64588 - if ((mod->module_core) && (mod->core_text_size)) {
64589 - set_page_attributes(mod->module_core,
64590 - mod->module_core + mod->core_text_size,
64591 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64592 + set_page_attributes(mod->module_core_rx,
64593 + mod->module_core_rx + mod->core_size_rx,
64596 - if ((mod->module_init) && (mod->init_text_size)) {
64597 - set_page_attributes(mod->module_init,
64598 - mod->module_init + mod->init_text_size,
64599 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64600 + set_page_attributes(mod->module_init_rx,
64601 + mod->module_init_rx + mod->init_size_rx,
64605 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
64607 mutex_lock(&module_mutex);
64608 list_for_each_entry_rcu(mod, &modules, list) {
64609 - if ((mod->module_core) && (mod->core_text_size)) {
64610 - set_page_attributes(mod->module_core,
64611 - mod->module_core + mod->core_text_size,
64612 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64613 + set_page_attributes(mod->module_core_rx,
64614 + mod->module_core_rx + mod->core_size_rx,
64617 - if ((mod->module_init) && (mod->init_text_size)) {
64618 - set_page_attributes(mod->module_init,
64619 - mod->module_init + mod->init_text_size,
64620 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64621 + set_page_attributes(mod->module_init_rx,
64622 + mod->module_init_rx + mod->init_size_rx,
64626 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
64628 /* This may be NULL, but that's OK */
64629 unset_module_init_ro_nx(mod);
64630 - module_free(mod, mod->module_init);
64631 + module_free(mod, mod->module_init_rw);
64632 + module_free_exec(mod, mod->module_init_rx);
64634 percpu_modfree(mod);
64636 /* Free lock-classes: */
64637 - lockdep_free_key_range(mod->module_core, mod->core_size);
64638 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
64639 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
64641 /* Finally, free the core (containing the module structure) */
64642 unset_module_core_ro_nx(mod);
64643 - module_free(mod, mod->module_core);
64644 + module_free_exec(mod, mod->module_core_rx);
64645 + module_free(mod, mod->module_core_rw);
64648 update_protections(current->mm);
64649 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64652 const struct kernel_symbol *ksym;
64653 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64654 + int is_fs_load = 0;
64655 + int register_filesystem_found = 0;
64658 + p = strstr(mod->args, "grsec_modharden_fs");
64660 + char *endptr = p + strlen("grsec_modharden_fs");
64661 + /* copy \0 as well */
64662 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
64667 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
64668 const char *name = info->strtab + sym[i].st_name;
64670 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64671 + /* it's a real shame this will never get ripped and copied
64674 + if (is_fs_load && !strcmp(name, "register_filesystem"))
64675 + register_filesystem_found = 1;
64678 switch (sym[i].st_shndx) {
64680 /* We compiled with -fno-common. These are not
64681 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64682 ksym = resolve_symbol_wait(mod, info, name);
64683 /* Ok if resolved. */
64684 if (ksym && !IS_ERR(ksym)) {
64685 + pax_open_kernel();
64686 sym[i].st_value = ksym->value;
64687 + pax_close_kernel();
64691 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64692 secbase = (unsigned long)mod_percpu(mod);
64694 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
64695 + pax_open_kernel();
64696 sym[i].st_value += secbase;
64697 + pax_close_kernel();
64702 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64703 + if (is_fs_load && !register_filesystem_found) {
64704 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
64712 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
64713 || s->sh_entsize != ~0UL
64714 || strstarts(sname, ".init"))
64716 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
64717 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64718 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
64720 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
64721 DEBUGP("\t%s\n", name);
64724 - case 0: /* executable */
64725 - mod->core_size = debug_align(mod->core_size);
64726 - mod->core_text_size = mod->core_size;
64728 - case 1: /* RO: text and ro-data */
64729 - mod->core_size = debug_align(mod->core_size);
64730 - mod->core_ro_size = mod->core_size;
64732 - case 3: /* whole core */
64733 - mod->core_size = debug_align(mod->core_size);
64738 DEBUGP("Init section allocation order:\n");
64739 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
64740 || s->sh_entsize != ~0UL
64741 || !strstarts(sname, ".init"))
64743 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
64744 - | INIT_OFFSET_MASK);
64745 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64746 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
64748 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
64749 + s->sh_entsize |= INIT_OFFSET_MASK;
64750 DEBUGP("\t%s\n", sname);
64753 - case 0: /* executable */
64754 - mod->init_size = debug_align(mod->init_size);
64755 - mod->init_text_size = mod->init_size;
64757 - case 1: /* RO: text and ro-data */
64758 - mod->init_size = debug_align(mod->init_size);
64759 - mod->init_ro_size = mod->init_size;
64761 - case 3: /* whole init */
64762 - mod->init_size = debug_align(mod->init_size);
64768 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64770 /* Put symbol section at end of init part of module. */
64771 symsect->sh_flags |= SHF_ALLOC;
64772 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
64773 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
64774 info->index.sym) | INIT_OFFSET_MASK;
64775 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
64777 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64780 /* Append room for core symbols at end of core part. */
64781 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
64782 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
64783 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
64784 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
64786 /* Put string table section at end of init part of module. */
64787 strsect->sh_flags |= SHF_ALLOC;
64788 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
64789 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
64790 info->index.str) | INIT_OFFSET_MASK;
64791 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
64793 /* Append room for core symbols' strings at end of core part. */
64794 - info->stroffs = mod->core_size;
64795 + info->stroffs = mod->core_size_rx;
64796 __set_bit(0, info->strmap);
64797 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
64798 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
64801 static void add_kallsyms(struct module *mod, const struct load_info *info)
64802 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64803 /* Make sure we get permanent strtab: don't use info->strtab. */
64804 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
64806 + pax_open_kernel();
64808 /* Set types up while we still have access to sections. */
64809 for (i = 0; i < mod->num_symtab; i++)
64810 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
64812 - mod->core_symtab = dst = mod->module_core + info->symoffs;
64813 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
64816 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
64817 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64819 mod->core_num_syms = ndst;
64821 - mod->core_strtab = s = mod->module_core + info->stroffs;
64822 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
64823 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
64824 if (test_bit(i, info->strmap))
64825 *++s = mod->strtab[i];
64827 + pax_close_kernel();
64830 static inline void layout_symtab(struct module *mod, struct load_info *info)
64831 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
64832 return size == 0 ? NULL : vmalloc_exec(size);
64835 -static void *module_alloc_update_bounds(unsigned long size)
64836 +static void *module_alloc_update_bounds_rw(unsigned long size)
64838 void *ret = module_alloc(size);
64841 mutex_lock(&module_mutex);
64842 /* Update module bounds. */
64843 - if ((unsigned long)ret < module_addr_min)
64844 - module_addr_min = (unsigned long)ret;
64845 - if ((unsigned long)ret + size > module_addr_max)
64846 - module_addr_max = (unsigned long)ret + size;
64847 + if ((unsigned long)ret < module_addr_min_rw)
64848 + module_addr_min_rw = (unsigned long)ret;
64849 + if ((unsigned long)ret + size > module_addr_max_rw)
64850 + module_addr_max_rw = (unsigned long)ret + size;
64851 + mutex_unlock(&module_mutex);
64856 +static void *module_alloc_update_bounds_rx(unsigned long size)
64858 + void *ret = module_alloc_exec(size);
64861 + mutex_lock(&module_mutex);
64862 + /* Update module bounds. */
64863 + if ((unsigned long)ret < module_addr_min_rx)
64864 + module_addr_min_rx = (unsigned long)ret;
64865 + if ((unsigned long)ret + size > module_addr_max_rx)
64866 + module_addr_max_rx = (unsigned long)ret + size;
64867 mutex_unlock(&module_mutex);
64870 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
64871 static int check_modinfo(struct module *mod, struct load_info *info)
64873 const char *modmagic = get_modinfo(info, "vermagic");
64874 + const char *license = get_modinfo(info, "license");
64877 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
64878 + if (!license || !license_is_gpl_compatible(license))
64882 /* This is allowed: modprobe --force will invalidate it. */
64884 err = try_to_force_load(mod, "bad vermagic");
64885 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
64888 /* Set up license info based on the info section */
64889 - set_license(mod, get_modinfo(info, "license"));
64890 + set_license(mod, license);
64894 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
64897 /* Do the allocs. */
64898 - ptr = module_alloc_update_bounds(mod->core_size);
64899 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
64901 * The pointer to this block is stored in the module structure
64902 * which is inside the block. Just mark it as not being a
64903 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
64907 - memset(ptr, 0, mod->core_size);
64908 - mod->module_core = ptr;
64909 + memset(ptr, 0, mod->core_size_rw);
64910 + mod->module_core_rw = ptr;
64912 - ptr = module_alloc_update_bounds(mod->init_size);
64913 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
64915 * The pointer to this block is stored in the module structure
64916 * which is inside the block. This block doesn't need to be
64917 * scanned as it contains data and code that will be freed
64918 * after the module is initialized.
64920 - kmemleak_ignore(ptr);
64921 - if (!ptr && mod->init_size) {
64922 - module_free(mod, mod->module_core);
64923 + kmemleak_not_leak(ptr);
64924 + if (!ptr && mod->init_size_rw) {
64925 + module_free(mod, mod->module_core_rw);
64928 - memset(ptr, 0, mod->init_size);
64929 - mod->module_init = ptr;
64930 + memset(ptr, 0, mod->init_size_rw);
64931 + mod->module_init_rw = ptr;
64933 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
64934 + kmemleak_not_leak(ptr);
64936 + module_free(mod, mod->module_init_rw);
64937 + module_free(mod, mod->module_core_rw);
64941 + pax_open_kernel();
64942 + memset(ptr, 0, mod->core_size_rx);
64943 + pax_close_kernel();
64944 + mod->module_core_rx = ptr;
64946 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
64947 + kmemleak_not_leak(ptr);
64948 + if (!ptr && mod->init_size_rx) {
64949 + module_free_exec(mod, mod->module_core_rx);
64950 + module_free(mod, mod->module_init_rw);
64951 + module_free(mod, mod->module_core_rw);
64955 + pax_open_kernel();
64956 + memset(ptr, 0, mod->init_size_rx);
64957 + pax_close_kernel();
64958 + mod->module_init_rx = ptr;
64960 /* Transfer each section which specifies SHF_ALLOC */
64961 DEBUGP("final section addresses:\n");
64962 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
64963 if (!(shdr->sh_flags & SHF_ALLOC))
64966 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
64967 - dest = mod->module_init
64968 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64970 - dest = mod->module_core + shdr->sh_entsize;
64971 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
64972 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64973 + dest = mod->module_init_rw
64974 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64976 + dest = mod->module_init_rx
64977 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64979 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64980 + dest = mod->module_core_rw + shdr->sh_entsize;
64982 + dest = mod->module_core_rx + shdr->sh_entsize;
64985 + if (shdr->sh_type != SHT_NOBITS) {
64987 +#ifdef CONFIG_PAX_KERNEXEC
64988 +#ifdef CONFIG_X86_64
64989 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
64990 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
64992 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
64993 + pax_open_kernel();
64994 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64995 + pax_close_kernel();
64999 - if (shdr->sh_type != SHT_NOBITS)
65000 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
65002 /* Update sh_addr to point to copy in image. */
65003 - shdr->sh_addr = (unsigned long)dest;
65005 +#ifdef CONFIG_PAX_KERNEXEC
65006 + if (shdr->sh_flags & SHF_EXECINSTR)
65007 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
65011 + shdr->sh_addr = (unsigned long)dest;
65012 DEBUGP("\t0x%lx %s\n",
65013 shdr->sh_addr, info->secstrings + shdr->sh_name);
65015 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
65016 * Do it before processing of module parameters, so the module
65017 * can provide parameter accessor functions of its own.
65019 - if (mod->module_init)
65020 - flush_icache_range((unsigned long)mod->module_init,
65021 - (unsigned long)mod->module_init
65022 - + mod->init_size);
65023 - flush_icache_range((unsigned long)mod->module_core,
65024 - (unsigned long)mod->module_core + mod->core_size);
65025 + if (mod->module_init_rx)
65026 + flush_icache_range((unsigned long)mod->module_init_rx,
65027 + (unsigned long)mod->module_init_rx
65028 + + mod->init_size_rx);
65029 + flush_icache_range((unsigned long)mod->module_core_rx,
65030 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
65034 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
65036 kfree(info->strmap);
65037 percpu_modfree(mod);
65038 - module_free(mod, mod->module_init);
65039 - module_free(mod, mod->module_core);
65040 + module_free_exec(mod, mod->module_init_rx);
65041 + module_free_exec(mod, mod->module_core_rx);
65042 + module_free(mod, mod->module_init_rw);
65043 + module_free(mod, mod->module_core_rw);
65046 int __weak module_finalize(const Elf_Ehdr *hdr,
65047 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
65051 + /* Now copy in args */
65052 + mod->args = strndup_user(uargs, ~0UL >> 1);
65053 + if (IS_ERR(mod->args)) {
65054 + err = PTR_ERR(mod->args);
65055 + goto free_unload;
65058 /* Set up MODINFO_ATTR fields */
65059 setup_modinfo(mod, &info);
65061 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65065 + if (strstr(mod->args, "grsec_modharden_netdev")) {
65066 + 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);
65068 + goto free_modinfo;
65069 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
65070 + p += strlen("grsec_modharden_normal");
65071 + p2 = strstr(p, "_");
65074 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
65078 + goto free_modinfo;
65083 /* Fix up syms, so that st_value is a pointer to location. */
65084 err = simplify_symbols(mod, &info);
65086 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
65088 flush_module_icache(mod);
65090 - /* Now copy in args */
65091 - mod->args = strndup_user(uargs, ~0UL >> 1);
65092 - if (IS_ERR(mod->args)) {
65093 - err = PTR_ERR(mod->args);
65094 - goto free_arch_cleanup;
65097 /* Mark state as coming so strong_try_module_get() ignores us. */
65098 mod->state = MODULE_STATE_COMING;
65100 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
65102 mutex_unlock(&module_mutex);
65103 synchronize_sched();
65104 - kfree(mod->args);
65105 - free_arch_cleanup:
65106 module_arch_cleanup(mod);
65109 + kfree(mod->args);
65111 module_unload_free(mod);
65113 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
65114 MODULE_STATE_COMING, mod);
65116 /* Set RO and NX regions for core */
65117 - set_section_ro_nx(mod->module_core,
65118 - mod->core_text_size,
65119 - mod->core_ro_size,
65121 + set_section_ro_nx(mod->module_core_rx,
65122 + mod->core_size_rx,
65123 + mod->core_size_rx,
65124 + mod->core_size_rx);
65126 /* Set RO and NX regions for init */
65127 - set_section_ro_nx(mod->module_init,
65128 - mod->init_text_size,
65129 - mod->init_ro_size,
65131 + set_section_ro_nx(mod->module_init_rx,
65132 + mod->init_size_rx,
65133 + mod->init_size_rx,
65134 + mod->init_size_rx);
65137 /* Start the module */
65138 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
65139 mod->strtab = mod->core_strtab;
65141 unset_module_init_ro_nx(mod);
65142 - module_free(mod, mod->module_init);
65143 - mod->module_init = NULL;
65144 - mod->init_size = 0;
65145 - mod->init_ro_size = 0;
65146 - mod->init_text_size = 0;
65147 + module_free(mod, mod->module_init_rw);
65148 + module_free_exec(mod, mod->module_init_rx);
65149 + mod->module_init_rw = NULL;
65150 + mod->module_init_rx = NULL;
65151 + mod->init_size_rw = 0;
65152 + mod->init_size_rx = 0;
65153 mutex_unlock(&module_mutex);
65156 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
65157 unsigned long nextval;
65159 /* At worse, next value is at end of module */
65160 - if (within_module_init(addr, mod))
65161 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
65162 + if (within_module_init_rx(addr, mod))
65163 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
65164 + else if (within_module_init_rw(addr, mod))
65165 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
65166 + else if (within_module_core_rx(addr, mod))
65167 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
65168 + else if (within_module_core_rw(addr, mod))
65169 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
65171 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
65174 /* Scan for closest preceding symbol, and next symbol. (ELF
65175 starts real symbols at 1). */
65176 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
65179 seq_printf(m, "%s %u",
65180 - mod->name, mod->init_size + mod->core_size);
65181 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
65182 print_unload_info(m, mod);
65184 /* Informative for users. */
65185 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
65186 mod->state == MODULE_STATE_COMING ? "Loading":
65188 /* Used by oprofile and other similar tools. */
65189 - seq_printf(m, " 0x%pK", mod->module_core);
65190 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
65194 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
65196 static int __init proc_modules_init(void)
65198 +#ifndef CONFIG_GRKERNSEC_HIDESYM
65199 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65200 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
65201 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65202 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
65204 proc_create("modules", 0, NULL, &proc_modules_operations);
65207 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
65211 module_init(proc_modules_init);
65212 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
65214 struct module *mod;
65216 - if (addr < module_addr_min || addr > module_addr_max)
65217 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
65218 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
65221 list_for_each_entry_rcu(mod, &modules, list)
65222 - if (within_module_core(addr, mod)
65223 - || within_module_init(addr, mod))
65224 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
65228 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
65230 struct module *__module_text_address(unsigned long addr)
65232 - struct module *mod = __module_address(addr);
65233 + struct module *mod;
65235 +#ifdef CONFIG_X86_32
65236 + addr = ktla_ktva(addr);
65239 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
65242 + mod = __module_address(addr);
65245 /* Make sure it's within the text section. */
65246 - if (!within(addr, mod->module_init, mod->init_text_size)
65247 - && !within(addr, mod->module_core, mod->core_text_size))
65248 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
65252 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
65253 index 7e3443f..b2a1e6b 100644
65254 --- a/kernel/mutex-debug.c
65255 +++ b/kernel/mutex-debug.c
65256 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
65259 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
65260 - struct thread_info *ti)
65261 + struct task_struct *task)
65263 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
65265 /* Mark the current thread as blocked on the lock: */
65266 - ti->task->blocked_on = waiter;
65267 + task->blocked_on = waiter;
65270 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
65271 - struct thread_info *ti)
65272 + struct task_struct *task)
65274 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
65275 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
65276 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
65277 - ti->task->blocked_on = NULL;
65278 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
65279 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
65280 + task->blocked_on = NULL;
65282 list_del_init(&waiter->list);
65283 waiter->task = NULL;
65284 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
65285 index 0799fd3..d06ae3b 100644
65286 --- a/kernel/mutex-debug.h
65287 +++ b/kernel/mutex-debug.h
65288 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
65289 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
65290 extern void debug_mutex_add_waiter(struct mutex *lock,
65291 struct mutex_waiter *waiter,
65292 - struct thread_info *ti);
65293 + struct task_struct *task);
65294 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
65295 - struct thread_info *ti);
65296 + struct task_struct *task);
65297 extern void debug_mutex_unlock(struct mutex *lock);
65298 extern void debug_mutex_init(struct mutex *lock, const char *name,
65299 struct lock_class_key *key);
65300 diff --git a/kernel/mutex.c b/kernel/mutex.c
65301 index 89096dd..f91ebc5 100644
65302 --- a/kernel/mutex.c
65303 +++ b/kernel/mutex.c
65304 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65305 spin_lock_mutex(&lock->wait_lock, flags);
65307 debug_mutex_lock_common(lock, &waiter);
65308 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
65309 + debug_mutex_add_waiter(lock, &waiter, task);
65311 /* add waiting tasks to the end of the waitqueue (FIFO): */
65312 list_add_tail(&waiter.list, &lock->wait_list);
65313 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65314 * TASK_UNINTERRUPTIBLE case.)
65316 if (unlikely(signal_pending_state(state, task))) {
65317 - mutex_remove_waiter(lock, &waiter,
65318 - task_thread_info(task));
65319 + mutex_remove_waiter(lock, &waiter, task);
65320 mutex_release(&lock->dep_map, 1, ip);
65321 spin_unlock_mutex(&lock->wait_lock, flags);
65323 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65325 lock_acquired(&lock->dep_map, ip);
65326 /* got the lock - rejoice! */
65327 - mutex_remove_waiter(lock, &waiter, current_thread_info());
65328 + mutex_remove_waiter(lock, &waiter, task);
65329 mutex_set_owner(lock);
65331 /* set it to 0 if there are no waiters left: */
65332 diff --git a/kernel/padata.c b/kernel/padata.c
65333 index b452599..5d68f4e 100644
65334 --- a/kernel/padata.c
65335 +++ b/kernel/padata.c
65336 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
65338 padata->cb_cpu = cb_cpu;
65340 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
65341 - atomic_set(&pd->seq_nr, -1);
65342 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
65343 + atomic_set_unchecked(&pd->seq_nr, -1);
65345 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
65346 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
65348 target_cpu = padata_cpu_hash(padata);
65349 queue = per_cpu_ptr(pd->pqueue, target_cpu);
65350 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
65351 padata_init_pqueues(pd);
65352 padata_init_squeues(pd);
65353 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
65354 - atomic_set(&pd->seq_nr, -1);
65355 + atomic_set_unchecked(&pd->seq_nr, -1);
65356 atomic_set(&pd->reorder_objects, 0);
65357 atomic_set(&pd->refcnt, 0);
65359 diff --git a/kernel/panic.c b/kernel/panic.c
65360 index 3458469..342c500 100644
65361 --- a/kernel/panic.c
65362 +++ b/kernel/panic.c
65363 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
65365 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
65366 #ifdef CONFIG_DEBUG_BUGVERBOSE
65369 + * Avoid nested stack-dumping if a panic occurs during oops processing
65371 + if (!oops_in_progress)
65376 @@ -382,7 +386,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
65379 printk(KERN_WARNING "------------[ cut here ]------------\n");
65380 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
65381 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
65382 board = dmi_get_system_info(DMI_PRODUCT_NAME);
65384 printk(KERN_WARNING "Hardware name: %s\n", board);
65385 @@ -437,7 +441,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
65387 void __stack_chk_fail(void)
65389 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
65391 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
65392 __builtin_return_address(0));
65394 EXPORT_SYMBOL(__stack_chk_fail);
65395 diff --git a/kernel/pid.c b/kernel/pid.c
65396 index fa5f722..0c93e57 100644
65400 #include <linux/rculist.h>
65401 #include <linux/bootmem.h>
65402 #include <linux/hash.h>
65403 +#include <linux/security.h>
65404 #include <linux/pid_namespace.h>
65405 #include <linux/init_task.h>
65406 #include <linux/syscalls.h>
65407 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
65409 int pid_max = PID_MAX_DEFAULT;
65411 -#define RESERVED_PIDS 300
65412 +#define RESERVED_PIDS 500
65414 int pid_max_min = RESERVED_PIDS + 1;
65415 int pid_max_max = PID_MAX_LIMIT;
65416 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
65418 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
65420 + struct task_struct *task;
65422 rcu_lockdep_assert(rcu_read_lock_held(),
65423 "find_task_by_pid_ns() needs rcu_read_lock()"
65425 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65427 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65429 + if (gr_pid_is_chrooted(task))
65435 struct task_struct *find_task_by_vpid(pid_t vnr)
65436 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
65437 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
65440 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
65442 + rcu_lockdep_assert(rcu_read_lock_held(),
65443 + "find_task_by_pid_ns() needs rcu_read_lock()"
65445 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
65448 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
65451 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
65452 index e7cb76d..75eceb3 100644
65453 --- a/kernel/posix-cpu-timers.c
65454 +++ b/kernel/posix-cpu-timers.c
65456 #include <linux/posix-timers.h>
65457 #include <linux/errno.h>
65458 #include <linux/math64.h>
65459 +#include <linux/security.h>
65460 #include <asm/uaccess.h>
65461 #include <linux/kernel_stat.h>
65462 #include <trace/events/timer.h>
65463 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
65465 static __init int init_posix_cpu_timers(void)
65467 - struct k_clock process = {
65468 + static struct k_clock process = {
65469 .clock_getres = process_cpu_clock_getres,
65470 .clock_get = process_cpu_clock_get,
65471 .timer_create = process_cpu_timer_create,
65472 .nsleep = process_cpu_nsleep,
65473 .nsleep_restart = process_cpu_nsleep_restart,
65475 - struct k_clock thread = {
65476 + static struct k_clock thread = {
65477 .clock_getres = thread_cpu_clock_getres,
65478 .clock_get = thread_cpu_clock_get,
65479 .timer_create = thread_cpu_timer_create,
65480 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
65481 index 69185ae..cc2847a 100644
65482 --- a/kernel/posix-timers.c
65483 +++ b/kernel/posix-timers.c
65485 #include <linux/idr.h>
65486 #include <linux/posix-clock.h>
65487 #include <linux/posix-timers.h>
65488 +#include <linux/grsecurity.h>
65489 #include <linux/syscalls.h>
65490 #include <linux/wait.h>
65491 #include <linux/workqueue.h>
65492 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
65493 * which we beg off on and pass to do_sys_settimeofday().
65496 -static struct k_clock posix_clocks[MAX_CLOCKS];
65497 +static struct k_clock *posix_clocks[MAX_CLOCKS];
65500 * These ones are defined below.
65501 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
65503 static __init int init_posix_timers(void)
65505 - struct k_clock clock_realtime = {
65506 + static struct k_clock clock_realtime = {
65507 .clock_getres = hrtimer_get_res,
65508 .clock_get = posix_clock_realtime_get,
65509 .clock_set = posix_clock_realtime_set,
65510 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
65511 .timer_get = common_timer_get,
65512 .timer_del = common_timer_del,
65514 - struct k_clock clock_monotonic = {
65515 + static struct k_clock clock_monotonic = {
65516 .clock_getres = hrtimer_get_res,
65517 .clock_get = posix_ktime_get_ts,
65518 .nsleep = common_nsleep,
65519 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
65520 .timer_get = common_timer_get,
65521 .timer_del = common_timer_del,
65523 - struct k_clock clock_monotonic_raw = {
65524 + static struct k_clock clock_monotonic_raw = {
65525 .clock_getres = hrtimer_get_res,
65526 .clock_get = posix_get_monotonic_raw,
65528 - struct k_clock clock_realtime_coarse = {
65529 + static struct k_clock clock_realtime_coarse = {
65530 .clock_getres = posix_get_coarse_res,
65531 .clock_get = posix_get_realtime_coarse,
65533 - struct k_clock clock_monotonic_coarse = {
65534 + static struct k_clock clock_monotonic_coarse = {
65535 .clock_getres = posix_get_coarse_res,
65536 .clock_get = posix_get_monotonic_coarse,
65538 - struct k_clock clock_boottime = {
65539 + static struct k_clock clock_boottime = {
65540 .clock_getres = hrtimer_get_res,
65541 .clock_get = posix_get_boottime,
65542 .nsleep = common_nsleep,
65543 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
65547 - posix_clocks[clock_id] = *new_clock;
65548 + posix_clocks[clock_id] = new_clock;
65550 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
65552 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
65553 return (id & CLOCKFD_MASK) == CLOCKFD ?
65554 &clock_posix_dynamic : &clock_posix_cpu;
65556 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
65557 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
65559 - return &posix_clocks[id];
65560 + return posix_clocks[id];
65563 static int common_timer_create(struct k_itimer *new_timer)
65564 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
65565 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
65568 + /* only the CLOCK_REALTIME clock can be set, all other clocks
65569 + have their clock_set fptr set to a nosettime dummy function
65570 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
65571 + call common_clock_set, which calls do_sys_settimeofday, which
65575 return kc->clock_set(which_clock, &new_tp);
65578 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
65579 index d523593..68197a4 100644
65580 --- a/kernel/power/poweroff.c
65581 +++ b/kernel/power/poweroff.c
65582 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
65583 .enable_mask = SYSRQ_ENABLE_BOOT,
65586 -static int pm_sysrq_init(void)
65587 +static int __init pm_sysrq_init(void)
65589 register_sysrq_key('o', &sysrq_poweroff_op);
65591 diff --git a/kernel/power/process.c b/kernel/power/process.c
65592 index 3d4b954..11af930 100644
65593 --- a/kernel/power/process.c
65594 +++ b/kernel/power/process.c
65595 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
65596 u64 elapsed_csecs64;
65597 unsigned int elapsed_csecs;
65598 bool wakeup = false;
65599 + bool timedout = false;
65601 do_gettimeofday(&start);
65603 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
65607 + if (time_after(jiffies, end_time))
65609 read_lock(&tasklist_lock);
65610 do_each_thread(g, p) {
65611 if (frozen(p) || !freezable(p))
65612 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
65613 * try_to_stop() after schedule() in ptrace/signal
65614 * stop sees TIF_FREEZE.
65616 - if (!task_is_stopped_or_traced(p) &&
65617 - !freezer_should_skip(p))
65618 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
65621 + printk(KERN_ERR "Task refusing to freeze:\n");
65622 + sched_show_task(p);
65625 } while_each_thread(g, p);
65626 read_unlock(&tasklist_lock);
65628 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
65632 - if (!todo || time_after(jiffies, end_time))
65633 + if (!todo || timedout)
65636 if (pm_wakeup_pending()) {
65637 diff --git a/kernel/printk.c b/kernel/printk.c
65638 index 7982a0a..2095fdc 100644
65639 --- a/kernel/printk.c
65640 +++ b/kernel/printk.c
65641 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
65642 if (from_file && type != SYSLOG_ACTION_OPEN)
65645 +#ifdef CONFIG_GRKERNSEC_DMESG
65646 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
65650 if (syslog_action_restricted(type)) {
65651 if (capable(CAP_SYSLOG))
65653 diff --git a/kernel/profile.c b/kernel/profile.c
65654 index 76b8e77..a2930e8 100644
65655 --- a/kernel/profile.c
65656 +++ b/kernel/profile.c
65657 @@ -39,7 +39,7 @@ struct profile_hit {
65658 /* Oprofile timer tick hook */
65659 static int (*timer_hook)(struct pt_regs *) __read_mostly;
65661 -static atomic_t *prof_buffer;
65662 +static atomic_unchecked_t *prof_buffer;
65663 static unsigned long prof_len, prof_shift;
65665 int prof_on __read_mostly;
65666 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
65670 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65671 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65672 hits[i].hits = hits[i].pc = 0;
65675 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65676 * Add the current hit(s) and flush the write-queue out
65677 * to the global buffer:
65679 - atomic_add(nr_hits, &prof_buffer[pc]);
65680 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
65681 for (i = 0; i < NR_PROFILE_HIT; ++i) {
65682 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65683 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65684 hits[i].pc = hits[i].hits = 0;
65687 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65690 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
65691 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65692 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65694 #endif /* !CONFIG_SMP */
65696 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
65698 buf++; p++; count--; read++;
65700 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
65701 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
65702 if (copy_to_user(buf, (void *)pnt, count))
65705 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
65708 profile_discard_flip_buffers();
65709 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
65710 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
65714 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
65715 index 78ab24a..332c915 100644
65716 --- a/kernel/ptrace.c
65717 +++ b/kernel/ptrace.c
65718 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
65722 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65723 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
65724 + unsigned int log)
65726 const struct cred *cred = current_cred(), *tcred;
65728 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65729 cred->gid == tcred->sgid &&
65730 cred->gid == tcred->gid))
65732 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
65733 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
65734 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
65738 @@ -207,7 +209,9 @@ ok:
65741 dumpable = get_dumpable(task->mm);
65742 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
65744 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
65745 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
65748 return security_ptrace_access_check(task, mode);
65749 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
65753 - err = __ptrace_may_access(task, mode);
65754 + err = __ptrace_may_access(task, mode, 0);
65755 + task_unlock(task);
65759 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
65761 + return __ptrace_may_access(task, mode, 0);
65764 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
65768 + err = __ptrace_may_access(task, mode, 1);
65772 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65776 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
65777 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
65781 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65782 task->ptrace = PT_PTRACED;
65784 task->ptrace |= PT_SEIZED;
65785 - if (task_ns_capable(task, CAP_SYS_PTRACE))
65786 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
65787 task->ptrace |= PT_PTRACE_CAP;
65789 __ptrace_link(task, current);
65790 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
65794 - if (copy_to_user(dst, buf, retval))
65795 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
65799 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
65800 bool seized = child->ptrace & PT_SEIZED;
65802 siginfo_t siginfo, *si;
65803 - void __user *datavp = (void __user *) data;
65804 + void __user *datavp = (__force void __user *) data;
65805 unsigned long __user *datalp = datavp;
65806 unsigned long flags;
65808 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
65812 + if (gr_handle_ptrace(child, request)) {
65814 + goto out_put_task_struct;
65817 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65818 ret = ptrace_attach(child, request, data);
65820 * Some architectures need to do book-keeping after
65825 arch_ptrace_attach(child);
65826 + gr_audit_ptrace(child);
65828 goto out_put_task_struct;
65831 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
65832 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
65833 if (copied != sizeof(tmp))
65835 - return put_user(tmp, (unsigned long __user *)data);
65836 + return put_user(tmp, (__force unsigned long __user *)data);
65839 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
65840 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
65844 + if (gr_handle_ptrace(child, request)) {
65846 + goto out_put_task_struct;
65849 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65850 ret = ptrace_attach(child, request, data);
65852 * Some architectures need to do book-keeping after
65857 arch_ptrace_attach(child);
65858 + gr_audit_ptrace(child);
65860 goto out_put_task_struct;
65863 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
65864 index 764825c..3aa6ac4 100644
65865 --- a/kernel/rcutorture.c
65866 +++ b/kernel/rcutorture.c
65867 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
65869 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
65871 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65872 -static atomic_t n_rcu_torture_alloc;
65873 -static atomic_t n_rcu_torture_alloc_fail;
65874 -static atomic_t n_rcu_torture_free;
65875 -static atomic_t n_rcu_torture_mberror;
65876 -static atomic_t n_rcu_torture_error;
65877 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65878 +static atomic_unchecked_t n_rcu_torture_alloc;
65879 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
65880 +static atomic_unchecked_t n_rcu_torture_free;
65881 +static atomic_unchecked_t n_rcu_torture_mberror;
65882 +static atomic_unchecked_t n_rcu_torture_error;
65883 static long n_rcu_torture_boost_ktrerror;
65884 static long n_rcu_torture_boost_rterror;
65885 static long n_rcu_torture_boost_failure;
65886 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
65888 spin_lock_bh(&rcu_torture_lock);
65889 if (list_empty(&rcu_torture_freelist)) {
65890 - atomic_inc(&n_rcu_torture_alloc_fail);
65891 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
65892 spin_unlock_bh(&rcu_torture_lock);
65895 - atomic_inc(&n_rcu_torture_alloc);
65896 + atomic_inc_unchecked(&n_rcu_torture_alloc);
65897 p = rcu_torture_freelist.next;
65899 spin_unlock_bh(&rcu_torture_lock);
65900 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
65902 rcu_torture_free(struct rcu_torture *p)
65904 - atomic_inc(&n_rcu_torture_free);
65905 + atomic_inc_unchecked(&n_rcu_torture_free);
65906 spin_lock_bh(&rcu_torture_lock);
65907 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
65908 spin_unlock_bh(&rcu_torture_lock);
65909 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
65910 i = rp->rtort_pipe_count;
65911 if (i > RCU_TORTURE_PIPE_LEN)
65912 i = RCU_TORTURE_PIPE_LEN;
65913 - atomic_inc(&rcu_torture_wcount[i]);
65914 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65915 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65916 rp->rtort_mbtest = 0;
65917 rcu_torture_free(rp);
65918 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
65919 i = rp->rtort_pipe_count;
65920 if (i > RCU_TORTURE_PIPE_LEN)
65921 i = RCU_TORTURE_PIPE_LEN;
65922 - atomic_inc(&rcu_torture_wcount[i]);
65923 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65924 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65925 rp->rtort_mbtest = 0;
65926 list_del(&rp->rtort_free);
65927 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
65928 i = old_rp->rtort_pipe_count;
65929 if (i > RCU_TORTURE_PIPE_LEN)
65930 i = RCU_TORTURE_PIPE_LEN;
65931 - atomic_inc(&rcu_torture_wcount[i]);
65932 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65933 old_rp->rtort_pipe_count++;
65934 cur_ops->deferred_free(old_rp);
65936 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
65939 if (p->rtort_mbtest == 0)
65940 - atomic_inc(&n_rcu_torture_mberror);
65941 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65942 spin_lock(&rand_lock);
65943 cur_ops->read_delay(&rand);
65944 n_rcu_torture_timers++;
65945 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
65948 if (p->rtort_mbtest == 0)
65949 - atomic_inc(&n_rcu_torture_mberror);
65950 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65951 cur_ops->read_delay(&rand);
65953 pipe_count = p->rtort_pipe_count;
65954 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
65955 rcu_torture_current,
65956 rcu_torture_current_version,
65957 list_empty(&rcu_torture_freelist),
65958 - atomic_read(&n_rcu_torture_alloc),
65959 - atomic_read(&n_rcu_torture_alloc_fail),
65960 - atomic_read(&n_rcu_torture_free),
65961 - atomic_read(&n_rcu_torture_mberror),
65962 + atomic_read_unchecked(&n_rcu_torture_alloc),
65963 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
65964 + atomic_read_unchecked(&n_rcu_torture_free),
65965 + atomic_read_unchecked(&n_rcu_torture_mberror),
65966 n_rcu_torture_boost_ktrerror,
65967 n_rcu_torture_boost_rterror,
65968 n_rcu_torture_boost_failure,
65969 n_rcu_torture_boosts,
65970 n_rcu_torture_timers);
65971 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
65972 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
65973 n_rcu_torture_boost_ktrerror != 0 ||
65974 n_rcu_torture_boost_rterror != 0 ||
65975 n_rcu_torture_boost_failure != 0)
65976 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
65977 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
65979 cnt += sprintf(&page[cnt], "!!! ");
65980 - atomic_inc(&n_rcu_torture_error);
65981 + atomic_inc_unchecked(&n_rcu_torture_error);
65984 cnt += sprintf(&page[cnt], "Reader Pipe: ");
65985 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
65986 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
65987 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65988 cnt += sprintf(&page[cnt], " %d",
65989 - atomic_read(&rcu_torture_wcount[i]));
65990 + atomic_read_unchecked(&rcu_torture_wcount[i]));
65992 cnt += sprintf(&page[cnt], "\n");
65993 if (cur_ops->stats)
65994 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
65996 if (cur_ops->cleanup)
65997 cur_ops->cleanup();
65998 - if (atomic_read(&n_rcu_torture_error))
65999 + if (atomic_read_unchecked(&n_rcu_torture_error))
66000 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
66002 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
66003 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
66005 rcu_torture_current = NULL;
66006 rcu_torture_current_version = 0;
66007 - atomic_set(&n_rcu_torture_alloc, 0);
66008 - atomic_set(&n_rcu_torture_alloc_fail, 0);
66009 - atomic_set(&n_rcu_torture_free, 0);
66010 - atomic_set(&n_rcu_torture_mberror, 0);
66011 - atomic_set(&n_rcu_torture_error, 0);
66012 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
66013 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
66014 + atomic_set_unchecked(&n_rcu_torture_free, 0);
66015 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
66016 + atomic_set_unchecked(&n_rcu_torture_error, 0);
66017 n_rcu_torture_boost_ktrerror = 0;
66018 n_rcu_torture_boost_rterror = 0;
66019 n_rcu_torture_boost_failure = 0;
66020 n_rcu_torture_boosts = 0;
66021 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
66022 - atomic_set(&rcu_torture_wcount[i], 0);
66023 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
66024 for_each_possible_cpu(cpu) {
66025 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
66026 per_cpu(rcu_torture_count, cpu)[i] = 0;
66027 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
66028 index 6b76d81..7afc1b3 100644
66029 --- a/kernel/rcutree.c
66030 +++ b/kernel/rcutree.c
66031 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
66032 trace_rcu_dyntick("Start");
66033 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
66034 smp_mb__before_atomic_inc(); /* See above. */
66035 - atomic_inc(&rdtp->dynticks);
66036 + atomic_inc_unchecked(&rdtp->dynticks);
66037 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
66038 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
66039 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
66040 local_irq_restore(flags);
66043 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
66046 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
66047 - atomic_inc(&rdtp->dynticks);
66048 + atomic_inc_unchecked(&rdtp->dynticks);
66049 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
66050 smp_mb__after_atomic_inc(); /* See above. */
66051 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
66052 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
66053 trace_rcu_dyntick("End");
66054 local_irq_restore(flags);
66056 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
66057 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
66059 if (rdtp->dynticks_nmi_nesting == 0 &&
66060 - (atomic_read(&rdtp->dynticks) & 0x1))
66061 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
66063 rdtp->dynticks_nmi_nesting++;
66064 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
66065 - atomic_inc(&rdtp->dynticks);
66066 + atomic_inc_unchecked(&rdtp->dynticks);
66067 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
66068 smp_mb__after_atomic_inc(); /* See above. */
66069 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
66070 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
66074 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
66076 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
66077 smp_mb__before_atomic_inc(); /* See above. */
66078 - atomic_inc(&rdtp->dynticks);
66079 + atomic_inc_unchecked(&rdtp->dynticks);
66080 smp_mb__after_atomic_inc(); /* Force delay to next write. */
66081 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
66082 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
66086 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
66088 static int dyntick_save_progress_counter(struct rcu_data *rdp)
66090 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
66091 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
66095 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
66099 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
66100 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
66101 snap = (unsigned int)rdp->dynticks_snap;
66104 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
66106 * Do RCU core processing for the current CPU.
66108 -static void rcu_process_callbacks(struct softirq_action *unused)
66109 +static void rcu_process_callbacks(void)
66111 trace_rcu_utilization("Start RCU core");
66112 __rcu_process_callbacks(&rcu_sched_state,
66113 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
66114 index 849ce9e..74bc9de 100644
66115 --- a/kernel/rcutree.h
66116 +++ b/kernel/rcutree.h
66118 struct rcu_dynticks {
66119 int dynticks_nesting; /* Track irq/process nesting level. */
66120 int dynticks_nmi_nesting; /* Track NMI nesting level. */
66121 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
66122 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
66125 /* RCU's kthread states for tracing. */
66126 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
66127 index 4b9b9f8..2326053 100644
66128 --- a/kernel/rcutree_plugin.h
66129 +++ b/kernel/rcutree_plugin.h
66130 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
66132 /* Clean up and exit. */
66133 smp_mb(); /* ensure expedited GP seen before counter increment. */
66134 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
66135 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
66137 mutex_unlock(&sync_rcu_preempt_exp_mutex);
66139 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
66141 #else /* #ifndef CONFIG_SMP */
66143 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
66144 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
66145 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
66146 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
66148 static int synchronize_sched_expedited_cpu_stop(void *data)
66150 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
66151 int firstsnap, s, snap, trycount = 0;
66153 /* Note that atomic_inc_return() implies full memory barrier. */
66154 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
66155 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
66159 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
66162 /* Check to see if someone else did our work for us. */
66163 - s = atomic_read(&sync_sched_expedited_done);
66164 + s = atomic_read_unchecked(&sync_sched_expedited_done);
66165 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
66166 smp_mb(); /* ensure test happens before caller kfree */
66168 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
66169 * grace period works for us.
66172 - snap = atomic_read(&sync_sched_expedited_started) - 1;
66173 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
66174 smp_mb(); /* ensure read is before try_stop_cpus(). */
66177 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
66178 * than we did beat us to the punch.
66181 - s = atomic_read(&sync_sched_expedited_done);
66182 + s = atomic_read_unchecked(&sync_sched_expedited_done);
66183 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
66184 smp_mb(); /* ensure test happens before caller kfree */
66187 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
66188 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
66192 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
66193 for_each_online_cpu(thatcpu) {
66194 if (thatcpu == cpu)
66196 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
66197 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
66198 thatcpu).dynticks);
66199 smp_mb(); /* Order sampling of snap with end of grace period. */
66200 if ((snap & 0x1) != 0) {
66201 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
66202 index 9feffa4..54058df 100644
66203 --- a/kernel/rcutree_trace.c
66204 +++ b/kernel/rcutree_trace.c
66205 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
66207 #ifdef CONFIG_NO_HZ
66208 seq_printf(m, " dt=%d/%d/%d df=%lu",
66209 - atomic_read(&rdp->dynticks->dynticks),
66210 + atomic_read_unchecked(&rdp->dynticks->dynticks),
66211 rdp->dynticks->dynticks_nesting,
66212 rdp->dynticks->dynticks_nmi_nesting,
66213 rdp->dynticks_fqs);
66214 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
66216 #ifdef CONFIG_NO_HZ
66217 seq_printf(m, ",%d,%d,%d,%lu",
66218 - atomic_read(&rdp->dynticks->dynticks),
66219 + atomic_read_unchecked(&rdp->dynticks->dynticks),
66220 rdp->dynticks->dynticks_nesting,
66221 rdp->dynticks->dynticks_nmi_nesting,
66222 rdp->dynticks_fqs);
66223 diff --git a/kernel/resource.c b/kernel/resource.c
66224 index 7640b3a..5879283 100644
66225 --- a/kernel/resource.c
66226 +++ b/kernel/resource.c
66227 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
66229 static int __init ioresources_init(void)
66231 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66232 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66233 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
66234 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
66235 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66236 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
66237 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
66240 proc_create("ioports", 0, NULL, &proc_ioports_operations);
66241 proc_create("iomem", 0, NULL, &proc_iomem_operations);
66245 __initcall(ioresources_init);
66246 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
66247 index 3d9f31c..7fefc9e 100644
66248 --- a/kernel/rtmutex-tester.c
66249 +++ b/kernel/rtmutex-tester.c
66251 #define MAX_RT_TEST_MUTEXES 8
66253 static spinlock_t rttest_lock;
66254 -static atomic_t rttest_event;
66255 +static atomic_unchecked_t rttest_event;
66257 struct test_thread_data {
66259 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66261 case RTTEST_LOCKCONT:
66262 td->mutexes[td->opdata] = 1;
66263 - td->event = atomic_add_return(1, &rttest_event);
66264 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66268 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66271 case RTTEST_RESETEVENT:
66272 - atomic_set(&rttest_event, 0);
66273 + atomic_set_unchecked(&rttest_event, 0);
66277 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66280 td->mutexes[id] = 1;
66281 - td->event = atomic_add_return(1, &rttest_event);
66282 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66283 rt_mutex_lock(&mutexes[id]);
66284 - td->event = atomic_add_return(1, &rttest_event);
66285 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66286 td->mutexes[id] = 4;
66289 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66292 td->mutexes[id] = 1;
66293 - td->event = atomic_add_return(1, &rttest_event);
66294 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66295 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
66296 - td->event = atomic_add_return(1, &rttest_event);
66297 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66298 td->mutexes[id] = ret ? 0 : 4;
66299 return ret ? -EINTR : 0;
66301 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66302 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
66305 - td->event = atomic_add_return(1, &rttest_event);
66306 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66307 rt_mutex_unlock(&mutexes[id]);
66308 - td->event = atomic_add_return(1, &rttest_event);
66309 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66310 td->mutexes[id] = 0;
66313 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66316 td->mutexes[dat] = 2;
66317 - td->event = atomic_add_return(1, &rttest_event);
66318 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66322 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66325 td->mutexes[dat] = 3;
66326 - td->event = atomic_add_return(1, &rttest_event);
66327 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66330 case RTTEST_LOCKNOWAIT:
66331 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66334 td->mutexes[dat] = 1;
66335 - td->event = atomic_add_return(1, &rttest_event);
66336 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66340 diff --git a/kernel/sched.c b/kernel/sched.c
66341 index d6b149c..896cbb8 100644
66342 --- a/kernel/sched.c
66343 +++ b/kernel/sched.c
66344 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
66345 BUG(); /* the idle class will always have a runnable task */
66348 +#ifdef CONFIG_GRKERNSEC_SETXID
66349 +extern void gr_delayed_cred_worker(void);
66350 +static inline void gr_cred_schedule(void)
66352 + if (unlikely(current->delayed_cred))
66353 + gr_delayed_cred_worker();
66356 +static inline void gr_cred_schedule(void)
66362 * __schedule() is the main scheduler function.
66364 @@ -4408,6 +4421,8 @@ need_resched:
66366 schedule_debug(prev);
66368 + gr_cred_schedule();
66370 if (sched_feat(HRTICK))
66373 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
66374 /* convert nice value [19,-20] to rlimit style value [1,40] */
66375 int nice_rlim = 20 - nice;
66377 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
66379 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
66380 capable(CAP_SYS_NICE));
66382 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
66386 - if (increment < 0 && !can_nice(current, nice))
66387 + if (increment < 0 && (!can_nice(current, nice) ||
66388 + gr_handle_chroot_nice()))
66391 retval = security_task_setnice(current, nice);
66392 @@ -5288,6 +5306,7 @@ recheck:
66393 unsigned long rlim_rtprio =
66394 task_rlimit(p, RLIMIT_RTPRIO);
66396 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
66397 /* can't set/change the rt policy */
66398 if (policy != p->policy && !rlim_rtprio)
66400 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
66401 index 429242f..d7cca82 100644
66402 --- a/kernel/sched_autogroup.c
66403 +++ b/kernel/sched_autogroup.c
66406 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
66407 static struct autogroup autogroup_default;
66408 -static atomic_t autogroup_seq_nr;
66409 +static atomic_unchecked_t autogroup_seq_nr;
66411 static void __init autogroup_init(struct task_struct *init_task)
66413 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
66415 kref_init(&ag->kref);
66416 init_rwsem(&ag->lock);
66417 - ag->id = atomic_inc_return(&autogroup_seq_nr);
66418 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
66420 #ifdef CONFIG_RT_GROUP_SCHED
66422 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
66423 index 8a39fa3..34f3dbc 100644
66424 --- a/kernel/sched_fair.c
66425 +++ b/kernel/sched_fair.c
66426 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
66427 * run_rebalance_domains is triggered when needed from the scheduler tick.
66428 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
66430 -static void run_rebalance_domains(struct softirq_action *h)
66431 +static void run_rebalance_domains(void)
66433 int this_cpu = smp_processor_id();
66434 struct rq *this_rq = cpu_rq(this_cpu);
66435 diff --git a/kernel/signal.c b/kernel/signal.c
66436 index 2065515..aed2987 100644
66437 --- a/kernel/signal.c
66438 +++ b/kernel/signal.c
66439 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
66441 int print_fatal_signals __read_mostly;
66443 -static void __user *sig_handler(struct task_struct *t, int sig)
66444 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
66446 return t->sighand->action[sig - 1].sa.sa_handler;
66449 -static int sig_handler_ignored(void __user *handler, int sig)
66450 +static int sig_handler_ignored(__sighandler_t handler, int sig)
66452 /* Is it explicitly or implicitly ignored? */
66453 return handler == SIG_IGN ||
66454 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
66455 static int sig_task_ignored(struct task_struct *t, int sig,
66456 int from_ancestor_ns)
66458 - void __user *handler;
66459 + __sighandler_t handler;
66461 handler = sig_handler(t, sig);
66463 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
66464 atomic_inc(&user->sigpending);
66467 + if (!override_rlimit)
66468 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
66470 if (override_rlimit ||
66471 atomic_read(&user->sigpending) <=
66472 task_rlimit(t, RLIMIT_SIGPENDING)) {
66473 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
66475 int unhandled_signal(struct task_struct *tsk, int sig)
66477 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
66478 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
66479 if (is_global_init(tsk))
66481 if (handler != SIG_IGN && handler != SIG_DFL)
66482 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
66486 + /* allow glibc communication via tgkill to other threads in our
66488 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
66489 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
66490 + && gr_handle_signal(t, sig))
66493 return security_task_kill(t, info, sig, 0);
66496 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66497 return send_signal(sig, info, p, 1);
66502 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66504 return send_signal(sig, info, t, 0);
66505 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66506 unsigned long int flags;
66507 int ret, blocked, ignored;
66508 struct k_sigaction *action;
66509 + int is_unhandled = 0;
66511 spin_lock_irqsave(&t->sighand->siglock, flags);
66512 action = &t->sighand->action[sig-1];
66513 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66515 if (action->sa.sa_handler == SIG_DFL)
66516 t->signal->flags &= ~SIGNAL_UNKILLABLE;
66517 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
66518 + is_unhandled = 1;
66519 ret = specific_send_sig_info(sig, info, t);
66520 spin_unlock_irqrestore(&t->sighand->siglock, flags);
66522 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
66523 + normal operation */
66524 + if (is_unhandled) {
66525 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
66526 + gr_handle_crash(t, sig);
66532 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66533 ret = check_kill_permission(sig, info, p);
66537 + if (!ret && sig) {
66538 ret = do_send_sig_info(sig, info, p, true);
66540 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
66545 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
66546 int error = -ESRCH;
66549 - p = find_task_by_vpid(pid);
66550 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66551 + /* allow glibc communication via tgkill to other threads in our
66553 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
66554 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
66555 + p = find_task_by_vpid_unrestricted(pid);
66558 + p = find_task_by_vpid(pid);
66559 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
66560 error = check_kill_permission(sig, info, p);
66562 diff --git a/kernel/smp.c b/kernel/smp.c
66563 index db197d6..17aef0b 100644
66566 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
66568 EXPORT_SYMBOL(smp_call_function);
66570 -void ipi_call_lock(void)
66571 +void ipi_call_lock(void) __acquires(call_function.lock)
66573 raw_spin_lock(&call_function.lock);
66576 -void ipi_call_unlock(void)
66577 +void ipi_call_unlock(void) __releases(call_function.lock)
66579 raw_spin_unlock(&call_function.lock);
66582 -void ipi_call_lock_irq(void)
66583 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
66585 raw_spin_lock_irq(&call_function.lock);
66588 -void ipi_call_unlock_irq(void)
66589 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
66591 raw_spin_unlock_irq(&call_function.lock);
66593 diff --git a/kernel/softirq.c b/kernel/softirq.c
66594 index 2c71d91..1021f81 100644
66595 --- a/kernel/softirq.c
66596 +++ b/kernel/softirq.c
66597 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
66599 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
66601 -char *softirq_to_name[NR_SOFTIRQS] = {
66602 +const char * const softirq_to_name[NR_SOFTIRQS] = {
66603 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
66604 "TASKLET", "SCHED", "HRTIMER", "RCU"
66606 @@ -235,7 +235,7 @@ restart:
66607 kstat_incr_softirqs_this_cpu(vec_nr);
66609 trace_softirq_entry(vec_nr);
66612 trace_softirq_exit(vec_nr);
66613 if (unlikely(prev_count != preempt_count())) {
66614 printk(KERN_ERR "huh, entered softirq %u %s %p"
66615 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
66616 local_irq_restore(flags);
66619 -void open_softirq(int nr, void (*action)(struct softirq_action *))
66620 +void open_softirq(int nr, void (*action)(void))
66622 - softirq_vec[nr].action = action;
66623 + pax_open_kernel();
66624 + *(void **)&softirq_vec[nr].action = action;
66625 + pax_close_kernel();
66629 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
66631 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
66633 -static void tasklet_action(struct softirq_action *a)
66634 +static void tasklet_action(void)
66636 struct tasklet_struct *list;
66638 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
66642 -static void tasklet_hi_action(struct softirq_action *a)
66643 +static void tasklet_hi_action(void)
66645 struct tasklet_struct *list;
66647 diff --git a/kernel/sys.c b/kernel/sys.c
66648 index 481611f..0754d86 100644
66651 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
66656 + if (gr_handle_chroot_setpriority(p, niceval)) {
66661 no_nice = security_task_setnice(p, niceval);
66664 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
66668 + if (gr_check_group_change(new->gid, new->egid, -1))
66671 if (rgid != (gid_t) -1 ||
66672 (egid != (gid_t) -1 && egid != old->gid))
66673 new->sgid = new->egid;
66674 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
66675 old = current_cred();
66679 + if (gr_check_group_change(gid, gid, gid))
66682 if (nsown_capable(CAP_SETGID))
66683 new->gid = new->egid = new->sgid = new->fsgid = gid;
66684 else if (gid == old->gid || gid == old->sgid)
66685 @@ -618,7 +631,7 @@ error:
66687 * change the user struct in a credentials set to match the new UID
66689 -static int set_user(struct cred *new)
66690 +int set_user(struct cred *new)
66692 struct user_struct *new_user;
66694 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
66698 + if (gr_check_user_change(new->uid, new->euid, -1))
66701 if (new->uid != old->uid) {
66702 retval = set_user(new);
66704 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
66705 old = current_cred();
66709 + if (gr_check_crash_uid(uid))
66711 + if (gr_check_user_change(uid, uid, uid))
66714 if (nsown_capable(CAP_SETUID)) {
66715 new->suid = new->uid = uid;
66716 if (uid != old->uid) {
66717 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
66721 + if (gr_check_user_change(ruid, euid, -1))
66724 if (ruid != (uid_t) -1) {
66726 if (ruid != old->uid) {
66727 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
66731 + if (gr_check_group_change(rgid, egid, -1))
66734 if (rgid != (gid_t) -1)
66736 if (egid != (gid_t) -1)
66737 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66738 old = current_cred();
66739 old_fsuid = old->fsuid;
66741 + if (gr_check_user_change(-1, -1, uid))
66744 if (uid == old->uid || uid == old->euid ||
66745 uid == old->suid || uid == old->fsuid ||
66746 nsown_capable(CAP_SETUID)) {
66747 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66755 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
66756 if (gid == old->gid || gid == old->egid ||
66757 gid == old->sgid || gid == old->fsgid ||
66758 nsown_capable(CAP_SETGID)) {
66759 + if (gr_check_group_change(-1, -1, gid))
66762 if (gid != old_fsgid) {
66772 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
66774 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
66775 snprintf(buf, len, "2.6.%u%s", v, rest);
66776 - ret = copy_to_user(release, buf, len);
66777 + if (len > sizeof(buf))
66780 + ret = copy_to_user(release, buf, len);
66784 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
66787 down_read(&uts_sem);
66788 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
66789 + error = __copy_to_user(name->sysname, &utsname()->sysname,
66791 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
66792 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
66793 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
66795 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
66796 - error |= __copy_to_user(&name->release, &utsname()->release,
66797 + error |= __copy_to_user(name->release, &utsname()->release,
66799 error |= __put_user(0, name->release + __OLD_UTS_LEN);
66800 - error |= __copy_to_user(&name->version, &utsname()->version,
66801 + error |= __copy_to_user(name->version, &utsname()->version,
66803 error |= __put_user(0, name->version + __OLD_UTS_LEN);
66804 - error |= __copy_to_user(&name->machine, &utsname()->machine,
66805 + error |= __copy_to_user(name->machine, &utsname()->machine,
66807 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
66809 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
66810 error = get_dumpable(me->mm);
66812 case PR_SET_DUMPABLE:
66813 - if (arg2 < 0 || arg2 > 1) {
66818 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
66819 index ae27196..7506d69 100644
66820 --- a/kernel/sysctl.c
66821 +++ b/kernel/sysctl.c
66825 #if defined(CONFIG_SYSCTL)
66826 +#include <linux/grsecurity.h>
66827 +#include <linux/grinternal.h>
66829 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
66830 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66832 +extern int gr_handle_chroot_sysctl(const int op);
66834 /* External variables not in a header file. */
66835 extern int sysctl_overcommit_memory;
66836 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
66840 +extern struct ctl_table grsecurity_table[];
66842 static struct ctl_table root_table[];
66843 static struct ctl_table_root sysctl_table_root;
66844 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
66845 int sysctl_legacy_va_layout;
66848 +#ifdef CONFIG_PAX_SOFTMODE
66849 +static ctl_table pax_table[] = {
66851 + .procname = "softmode",
66852 + .data = &pax_softmode,
66853 + .maxlen = sizeof(unsigned int),
66855 + .proc_handler = &proc_dointvec,
66862 /* The default sysctl tables: */
66864 static struct ctl_table root_table[] = {
66865 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
66868 static struct ctl_table kern_table[] = {
66869 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66871 + .procname = "grsecurity",
66873 + .child = grsecurity_table,
66877 +#ifdef CONFIG_PAX_SOFTMODE
66879 + .procname = "pax",
66881 + .child = pax_table,
66886 .procname = "sched_child_runs_first",
66887 .data = &sysctl_sched_child_runs_first,
66888 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
66889 .data = &modprobe_path,
66890 .maxlen = KMOD_PATH_LEN,
66892 - .proc_handler = proc_dostring,
66893 + .proc_handler = proc_dostring_modpriv,
66896 .procname = "modules_disabled",
66897 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
66903 .procname = "kptr_restrict",
66904 .data = &kptr_restrict,
66905 .maxlen = sizeof(int),
66907 .proc_handler = proc_dmesg_restrict,
66908 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66917 .procname = "ngroups_max",
66918 .data = &ngroups_max,
66919 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
66920 .proc_handler = proc_dointvec_minmax,
66924 + .procname = "heap_stack_gap",
66925 + .data = &sysctl_heap_stack_gap,
66926 + .maxlen = sizeof(sysctl_heap_stack_gap),
66928 + .proc_handler = proc_doulongvec_minmax,
66932 .procname = "nr_trim_pages",
66933 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
66934 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
66939 + if (table->parent != NULL && table->parent->procname != NULL &&
66940 + table->procname != NULL &&
66941 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
66943 + if (gr_handle_chroot_sysctl(op))
66945 + error = gr_handle_sysctl(table, op);
66949 if (root->permissions)
66950 mode = root->permissions(root, current->nsproxy, table);
66951 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
66952 buffer, lenp, ppos);
66955 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66956 + void __user *buffer, size_t *lenp, loff_t *ppos)
66958 + if (write && !capable(CAP_SYS_MODULE))
66961 + return _proc_do_string(table->data, table->maxlen, write,
66962 + buffer, lenp, ppos);
66965 static size_t proc_skip_spaces(char **buf)
66968 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
66972 + if (len > sizeof(tmp))
66973 + len = sizeof(tmp);
66974 if (copy_to_user(*buf, tmp, len))
66977 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
66980 val = convdiv * (*i) / convmul;
66983 err = proc_put_char(&buffer, &left, '\t');
66987 err = proc_put_long(&buffer, &left, val, false);
66990 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
66994 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66995 + void __user *buffer, size_t *lenp, loff_t *ppos)
67000 int proc_dointvec(struct ctl_table *table, int write,
67001 void __user *buffer, size_t *lenp, loff_t *ppos)
67003 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
67004 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
67005 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
67006 EXPORT_SYMBOL(proc_dostring);
67007 +EXPORT_SYMBOL(proc_dostring_modpriv);
67008 EXPORT_SYMBOL(proc_doulongvec_minmax);
67009 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
67010 EXPORT_SYMBOL(register_sysctl_table);
67011 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
67012 index a650694..aaeeb20 100644
67013 --- a/kernel/sysctl_binary.c
67014 +++ b/kernel/sysctl_binary.c
67015 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
67019 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
67020 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
67024 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
67028 - result = vfs_write(file, buffer, str - buffer, &pos);
67029 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
67033 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
67037 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
67038 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
67042 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
67046 - result = vfs_write(file, buffer, str - buffer, &pos);
67047 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
67051 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
67055 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
67056 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
67060 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
67064 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
67065 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
67069 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
67070 le16_to_cpu(dnaddr) & 0x3ff);
67073 - result = vfs_write(file, buf, len, &pos);
67074 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
67078 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
67079 index 362da65..ab8ef8c 100644
67080 --- a/kernel/sysctl_check.c
67081 +++ b/kernel/sysctl_check.c
67082 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
67083 set_fail(&fail, table, "Directory with extra2");
67085 if ((table->proc_handler == proc_dostring) ||
67086 + (table->proc_handler == proc_dostring_modpriv) ||
67087 (table->proc_handler == proc_dointvec) ||
67088 (table->proc_handler == proc_dointvec_minmax) ||
67089 (table->proc_handler == proc_dointvec_jiffies) ||
67090 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
67091 index e660464..c8b9e67 100644
67092 --- a/kernel/taskstats.c
67093 +++ b/kernel/taskstats.c
67095 #include <linux/cgroup.h>
67096 #include <linux/fs.h>
67097 #include <linux/file.h>
67098 +#include <linux/grsecurity.h>
67099 #include <net/genetlink.h>
67100 #include <linux/atomic.h>
67102 +extern int gr_is_taskstats_denied(int pid);
67105 * Maximum length of a cpumask that can be specified in
67106 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
67107 @@ -556,6 +559,9 @@ err:
67109 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
67111 + if (gr_is_taskstats_denied(current->pid))
67114 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
67115 return cmd_attr_register_cpumask(info);
67116 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
67117 diff --git a/kernel/time.c b/kernel/time.c
67118 index 73e416d..cfc6f69 100644
67119 --- a/kernel/time.c
67120 +++ b/kernel/time.c
67121 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
67125 + /* we log in do_settimeofday called below, so don't log twice
67128 + gr_log_timechange();
67130 /* SMP safe, global irq locking makes it work. */
67132 update_vsyscall_tz();
67133 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
67134 index 8a46f5d..bbe6f9c 100644
67135 --- a/kernel/time/alarmtimer.c
67136 +++ b/kernel/time/alarmtimer.c
67137 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
67138 struct platform_device *pdev;
67141 - struct k_clock alarm_clock = {
67142 + static struct k_clock alarm_clock = {
67143 .clock_getres = alarm_clock_getres,
67144 .clock_get = alarm_clock_get,
67145 .timer_create = alarm_timer_create,
67146 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
67147 index fd4a7b1..fae5c2a 100644
67148 --- a/kernel/time/tick-broadcast.c
67149 +++ b/kernel/time/tick-broadcast.c
67150 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
67151 * then clear the broadcast bit.
67153 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
67154 - int cpu = smp_processor_id();
67155 + cpu = smp_processor_id();
67157 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
67158 tick_broadcast_clear_oneshot(cpu);
67159 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
67160 index 2378413..be455fd 100644
67161 --- a/kernel/time/timekeeping.c
67162 +++ b/kernel/time/timekeeping.c
67164 #include <linux/init.h>
67165 #include <linux/mm.h>
67166 #include <linux/sched.h>
67167 +#include <linux/grsecurity.h>
67168 #include <linux/syscore_ops.h>
67169 #include <linux/clocksource.h>
67170 #include <linux/jiffies.h>
67171 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
67172 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
67175 + gr_log_timechange();
67177 write_seqlock_irqsave(&xtime_lock, flags);
67179 timekeeping_forward_now();
67180 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
67181 index 3258455..f35227d 100644
67182 --- a/kernel/time/timer_list.c
67183 +++ b/kernel/time/timer_list.c
67184 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
67186 static void print_name_offset(struct seq_file *m, void *sym)
67188 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67189 + SEQ_printf(m, "<%p>", NULL);
67191 char symname[KSYM_NAME_LEN];
67193 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
67194 SEQ_printf(m, "<%pK>", sym);
67196 SEQ_printf(m, "%s", symname);
67201 @@ -112,7 +116,11 @@ next_one:
67203 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
67205 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67206 + SEQ_printf(m, " .base: %p\n", NULL);
67208 SEQ_printf(m, " .base: %pK\n", base);
67210 SEQ_printf(m, " .index: %d\n",
67212 SEQ_printf(m, " .resolution: %Lu nsecs\n",
67213 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
67215 struct proc_dir_entry *pe;
67217 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67218 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
67220 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
67225 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
67226 index 0b537f2..9e71eca 100644
67227 --- a/kernel/time/timer_stats.c
67228 +++ b/kernel/time/timer_stats.c
67229 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
67230 static unsigned long nr_entries;
67231 static struct entry entries[MAX_ENTRIES];
67233 -static atomic_t overflow_count;
67234 +static atomic_unchecked_t overflow_count;
67237 * The entries are in a hash-table, for fast lookup:
67238 @@ -140,7 +140,7 @@ static void reset_entries(void)
67240 memset(entries, 0, sizeof(entries));
67241 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
67242 - atomic_set(&overflow_count, 0);
67243 + atomic_set_unchecked(&overflow_count, 0);
67246 static struct entry *alloc_entry(void)
67247 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
67251 - atomic_inc(&overflow_count);
67252 + atomic_inc_unchecked(&overflow_count);
67255 raw_spin_unlock_irqrestore(lock, flags);
67256 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
67258 static void print_name_offset(struct seq_file *m, unsigned long addr)
67260 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67261 + seq_printf(m, "<%p>", NULL);
67263 char symname[KSYM_NAME_LEN];
67265 if (lookup_symbol_name(addr, symname) < 0)
67266 seq_printf(m, "<%p>", (void *)addr);
67268 seq_printf(m, "%s", symname);
67272 static int tstats_show(struct seq_file *m, void *v)
67273 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
67275 seq_puts(m, "Timer Stats Version: v0.2\n");
67276 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
67277 - if (atomic_read(&overflow_count))
67278 + if (atomic_read_unchecked(&overflow_count))
67279 seq_printf(m, "Overflow: %d entries\n",
67280 - atomic_read(&overflow_count));
67281 + atomic_read_unchecked(&overflow_count));
67283 for (i = 0; i < nr_entries; i++) {
67284 entry = entries + i;
67285 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
67287 struct proc_dir_entry *pe;
67289 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67290 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
67292 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
67297 diff --git a/kernel/timer.c b/kernel/timer.c
67298 index 9c3c62b..441690e 100644
67299 --- a/kernel/timer.c
67300 +++ b/kernel/timer.c
67301 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
67303 * This function runs timers and the timer-tq in bottom half context.
67305 -static void run_timer_softirq(struct softirq_action *h)
67306 +static void run_timer_softirq(void)
67308 struct tvec_base *base = __this_cpu_read(tvec_bases);
67310 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
67311 index 16fc34a..efd8bb8 100644
67312 --- a/kernel/trace/blktrace.c
67313 +++ b/kernel/trace/blktrace.c
67314 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
67315 struct blk_trace *bt = filp->private_data;
67318 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
67319 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
67321 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
67323 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
67326 bt = buf->chan->private_data;
67327 - atomic_inc(&bt->dropped);
67328 + atomic_inc_unchecked(&bt->dropped);
67332 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
67336 - atomic_set(&bt->dropped, 0);
67337 + atomic_set_unchecked(&bt->dropped, 0);
67340 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
67341 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
67342 index 25b4f4d..6f4772d 100644
67343 --- a/kernel/trace/ftrace.c
67344 +++ b/kernel/trace/ftrace.c
67345 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
67346 if (unlikely(ftrace_disabled))
67349 + ret = ftrace_arch_code_modify_prepare();
67350 + FTRACE_WARN_ON(ret);
67354 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
67355 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
67357 ftrace_bug(ret, ip);
67361 + return ret ? 0 : 1;
67365 @@ -2608,7 +2613,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
67368 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
67372 struct ftrace_func_probe *entry;
67373 struct ftrace_page *pg;
67374 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
67375 index f2bd275..adaf3a2 100644
67376 --- a/kernel/trace/trace.c
67377 +++ b/kernel/trace/trace.c
67378 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
67382 -static struct dentry *d_tracer;
67384 struct dentry *tracing_init_dentry(void)
67386 + static struct dentry *d_tracer;
67390 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
67394 -static struct dentry *d_percpu;
67396 struct dentry *tracing_dentry_percpu(void)
67398 + static struct dentry *d_percpu;
67400 struct dentry *d_tracer;
67402 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
67403 index c212a7f..7b02394 100644
67404 --- a/kernel/trace/trace_events.c
67405 +++ b/kernel/trace/trace_events.c
67406 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
67407 struct ftrace_module_file_ops {
67408 struct list_head list;
67409 struct module *mod;
67410 - struct file_operations id;
67411 - struct file_operations enable;
67412 - struct file_operations format;
67413 - struct file_operations filter;
67416 static struct ftrace_module_file_ops *
67417 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
67419 file_ops->mod = mod;
67421 - file_ops->id = ftrace_event_id_fops;
67422 - file_ops->id.owner = mod;
67424 - file_ops->enable = ftrace_enable_fops;
67425 - file_ops->enable.owner = mod;
67427 - file_ops->filter = ftrace_event_filter_fops;
67428 - file_ops->filter.owner = mod;
67430 - file_ops->format = ftrace_event_format_fops;
67431 - file_ops->format.owner = mod;
67432 + pax_open_kernel();
67433 + *(void **)&mod->trace_id.owner = mod;
67434 + *(void **)&mod->trace_enable.owner = mod;
67435 + *(void **)&mod->trace_filter.owner = mod;
67436 + *(void **)&mod->trace_format.owner = mod;
67437 + pax_close_kernel();
67439 list_add(&file_ops->list, &ftrace_module_file_list);
67441 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
67443 for_each_event(call, start, end) {
67444 __trace_add_event_call(*call, mod,
67445 - &file_ops->id, &file_ops->enable,
67446 - &file_ops->filter, &file_ops->format);
67447 + &mod->trace_id, &mod->trace_enable,
67448 + &mod->trace_filter, &mod->trace_format);
67452 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
67453 index 00d527c..7c5b1a3 100644
67454 --- a/kernel/trace/trace_kprobe.c
67455 +++ b/kernel/trace/trace_kprobe.c
67456 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67458 int maxlen = get_rloc_len(*(u32 *)dest);
67459 u8 *dst = get_rloc_data(dest);
67461 + const u8 __user *src = (const u8 __force_user *)addr;
67462 mm_segment_t old_fs = get_fs();
67465 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67466 pagefault_disable();
67468 ret = __copy_from_user_inatomic(dst++, src++, 1);
67469 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
67470 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
67472 pagefault_enable();
67474 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67475 ((u8 *)get_rloc_data(dest))[0] = '\0';
67476 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
67478 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
67479 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
67480 get_rloc_offs(*(u32 *)dest));
67482 /* Return the length of string -- including null terminal byte */
67483 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
67485 pagefault_disable();
67487 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
67488 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
67490 } while (c && ret == 0 && len < MAX_STRING_SIZE);
67491 pagefault_enable();
67492 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
67493 index fd3c8aa..5f324a6 100644
67494 --- a/kernel/trace/trace_mmiotrace.c
67495 +++ b/kernel/trace/trace_mmiotrace.c
67496 @@ -24,7 +24,7 @@ struct header_iter {
67497 static struct trace_array *mmio_trace_array;
67498 static bool overrun_detected;
67499 static unsigned long prev_overruns;
67500 -static atomic_t dropped_count;
67501 +static atomic_unchecked_t dropped_count;
67503 static void mmio_reset_data(struct trace_array *tr)
67505 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
67507 static unsigned long count_overruns(struct trace_iterator *iter)
67509 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
67510 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
67511 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
67513 if (over > prev_overruns)
67514 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
67515 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
67516 sizeof(*entry), 0, pc);
67518 - atomic_inc(&dropped_count);
67519 + atomic_inc_unchecked(&dropped_count);
67522 entry = ring_buffer_event_data(event);
67523 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
67524 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
67525 sizeof(*entry), 0, pc);
67527 - atomic_inc(&dropped_count);
67528 + atomic_inc_unchecked(&dropped_count);
67531 entry = ring_buffer_event_data(event);
67532 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
67533 index 5199930..26c73a0 100644
67534 --- a/kernel/trace/trace_output.c
67535 +++ b/kernel/trace/trace_output.c
67536 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
67538 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
67540 - p = mangle_path(s->buffer + s->len, p, "\n");
67541 + p = mangle_path(s->buffer + s->len, p, "\n\\");
67543 s->len = p - s->buffer;
67545 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
67546 index 77575b3..6e623d1 100644
67547 --- a/kernel/trace/trace_stack.c
67548 +++ b/kernel/trace/trace_stack.c
67549 @@ -50,7 +50,7 @@ static inline void check_stack(void)
67552 /* we do not handle interrupt stacks yet */
67553 - if (!object_is_on_stack(&this_size))
67554 + if (!object_starts_on_stack(&this_size))
67557 local_irq_save(flags);
67558 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
67559 index 209b379..7f76423 100644
67560 --- a/kernel/trace/trace_workqueue.c
67561 +++ b/kernel/trace/trace_workqueue.c
67562 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
67565 /* Can be inserted from interrupt or user context, need to be atomic */
67566 - atomic_t inserted;
67567 + atomic_unchecked_t inserted;
67569 * Don't need to be atomic, works are serialized in a single workqueue thread
67571 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
67572 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
67573 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
67574 if (node->pid == wq_thread->pid) {
67575 - atomic_inc(&node->inserted);
67576 + atomic_inc_unchecked(&node->inserted);
67580 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
67581 tsk = get_pid_task(pid, PIDTYPE_PID);
67583 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
67584 - atomic_read(&cws->inserted), cws->executed,
67585 + atomic_read_unchecked(&cws->inserted), cws->executed,
67587 put_task_struct(tsk);
67589 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
67590 index 82928f5..92da771 100644
67591 --- a/lib/Kconfig.debug
67592 +++ b/lib/Kconfig.debug
67593 @@ -1103,6 +1103,7 @@ config LATENCYTOP
67594 depends on DEBUG_KERNEL
67595 depends on STACKTRACE_SUPPORT
67597 + depends on !GRKERNSEC_HIDESYM
67598 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
67600 select KALLSYMS_ALL
67601 diff --git a/lib/bitmap.c b/lib/bitmap.c
67602 index 0d4a127..33a06c7 100644
67605 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
67607 int c, old_c, totaldigits, ndigits, nchunks, nbits;
67609 - const char __user __force *ubuf = (const char __user __force *)buf;
67610 + const char __user *ubuf = (const char __force_user *)buf;
67612 bitmap_zero(maskp, nmaskbits);
67614 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
67616 if (!access_ok(VERIFY_READ, ubuf, ulen))
67618 - return __bitmap_parse((const char __force *)ubuf,
67619 + return __bitmap_parse((const char __force_kernel *)ubuf,
67620 ulen, 1, maskp, nmaskbits);
67623 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
67626 int c, old_c, totaldigits;
67627 - const char __user __force *ubuf = (const char __user __force *)buf;
67628 + const char __user *ubuf = (const char __force_user *)buf;
67629 int exp_digit, in_range;
67631 totaldigits = c = 0;
67632 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
67634 if (!access_ok(VERIFY_READ, ubuf, ulen))
67636 - return __bitmap_parselist((const char __force *)ubuf,
67637 + return __bitmap_parselist((const char __force_kernel *)ubuf,
67638 ulen, 1, maskp, nmaskbits);
67640 EXPORT_SYMBOL(bitmap_parselist_user);
67641 diff --git a/lib/bug.c b/lib/bug.c
67642 index 1955209..cbbb2ad 100644
67645 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
67646 return BUG_TRAP_TYPE_NONE;
67648 bug = find_bug(bugaddr);
67650 + return BUG_TRAP_TYPE_NONE;
67654 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
67655 index a78b7c6..2c73084 100644
67656 --- a/lib/debugobjects.c
67657 +++ b/lib/debugobjects.c
67658 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
67662 - is_on_stack = object_is_on_stack(addr);
67663 + is_on_stack = object_starts_on_stack(addr);
67664 if (is_on_stack == onstack)
67667 diff --git a/lib/devres.c b/lib/devres.c
67668 index 7c0e953..f642b5c 100644
67671 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
67672 void devm_iounmap(struct device *dev, void __iomem *addr)
67674 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
67676 + (void __force *)addr));
67679 EXPORT_SYMBOL(devm_iounmap);
67680 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
67682 ioport_unmap(addr);
67683 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
67684 - devm_ioport_map_match, (void *)addr));
67685 + devm_ioport_map_match, (void __force *)addr));
67687 EXPORT_SYMBOL(devm_ioport_unmap);
67689 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
67690 index fea790a..ebb0e82 100644
67691 --- a/lib/dma-debug.c
67692 +++ b/lib/dma-debug.c
67693 @@ -925,7 +925,7 @@ out:
67695 static void check_for_stack(struct device *dev, void *addr)
67697 - if (object_is_on_stack(addr))
67698 + if (object_starts_on_stack(addr))
67699 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
67700 "stack [addr=%p]\n", addr);
67702 diff --git a/lib/extable.c b/lib/extable.c
67703 index 4cac81e..63e9b8f 100644
67704 --- a/lib/extable.c
67705 +++ b/lib/extable.c
67707 #include <linux/init.h>
67708 #include <linux/sort.h>
67709 #include <asm/uaccess.h>
67710 +#include <asm/pgtable.h>
67712 #ifndef ARCH_HAS_SORT_EXTABLE
67714 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
67715 void sort_extable(struct exception_table_entry *start,
67716 struct exception_table_entry *finish)
67718 + pax_open_kernel();
67719 sort(start, finish - start, sizeof(struct exception_table_entry),
67721 + pax_close_kernel();
67724 #ifdef CONFIG_MODULES
67725 diff --git a/lib/inflate.c b/lib/inflate.c
67726 index 013a761..c28f3fc 100644
67727 --- a/lib/inflate.c
67728 +++ b/lib/inflate.c
67729 @@ -269,7 +269,7 @@ static void free(void *where)
67730 malloc_ptr = free_mem_ptr;
67733 -#define malloc(a) kmalloc(a, GFP_KERNEL)
67734 +#define malloc(a) kmalloc((a), GFP_KERNEL)
67735 #define free(a) kfree(a)
67738 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
67739 index bd2bea9..6b3c95e 100644
67740 --- a/lib/is_single_threaded.c
67741 +++ b/lib/is_single_threaded.c
67742 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
67743 struct task_struct *p, *t;
67749 if (atomic_read(&task->signal->live) != 1)
67752 diff --git a/lib/kref.c b/lib/kref.c
67753 index 3efb882..8492f4c 100644
67756 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
67758 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
67760 - WARN_ON(release == NULL);
67761 + BUG_ON(release == NULL);
67762 WARN_ON(release == (void (*)(struct kref *))kfree);
67764 if (atomic_dec_and_test(&kref->refcount)) {
67765 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
67766 index d9df745..e73c2fe 100644
67767 --- a/lib/radix-tree.c
67768 +++ b/lib/radix-tree.c
67769 @@ -80,7 +80,7 @@ struct radix_tree_preload {
67771 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
67773 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
67774 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
67776 static inline void *ptr_to_indirect(void *ptr)
67778 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
67779 index 993599e..f1dbc14 100644
67780 --- a/lib/vsprintf.c
67781 +++ b/lib/vsprintf.c
67783 * - scnprintf and vscnprintf
67786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67787 +#define __INCLUDED_BY_HIDESYM 1
67789 #include <stdarg.h>
67790 #include <linux/module.h>
67791 #include <linux/types.h>
67792 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
67793 char sym[KSYM_SYMBOL_LEN];
67795 sprint_backtrace(sym, value);
67796 - else if (ext != 'f' && ext != 's')
67797 + else if (ext != 'f' && ext != 's' && ext != 'a')
67798 sprint_symbol(sym, value);
67800 kallsyms_lookup(value, NULL, NULL, NULL, sym);
67801 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
67802 return string(buf, end, uuid, spec);
67805 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67806 +int kptr_restrict __read_mostly = 2;
67808 int kptr_restrict __read_mostly;
67812 * Show a '%p' thing. A kernel extension is that the '%p' is followed
67813 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
67814 * - 'S' For symbolic direct pointers with offset
67815 * - 's' For symbolic direct pointers without offset
67816 * - 'B' For backtraced symbolic direct pointers with offset
67817 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
67818 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
67819 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
67820 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
67821 * - 'M' For a 6-byte MAC address, it prints the address in the
67822 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67824 if (!ptr && *fmt != 'K') {
67826 - * Print (null) with the same width as a pointer so it makes
67827 + * Print (nil) with the same width as a pointer so it makes
67828 * tabular output look nice.
67830 if (spec.field_width == -1)
67831 spec.field_width = 2 * sizeof(void *);
67832 - return string(buf, end, "(null)", spec);
67833 + return string(buf, end, "(nil)", spec);
67837 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67841 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67844 + return symbol_string(buf, end, ptr, spec, *fmt);
67849 return symbol_string(buf, end, ptr, spec, *fmt);
67851 @@ -878,9 +894,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67853 return uuid_string(buf, end, ptr, spec, fmt);
67855 - return buf + vsnprintf(buf, end > buf ? end - buf : 0,
67856 - ((struct va_format *)ptr)->fmt,
67857 - *(((struct va_format *)ptr)->va));
67861 + va_copy(va, *((struct va_format *)ptr)->va);
67862 + buf += vsnprintf(buf, end > buf ? end - buf : 0,
67863 + ((struct va_format *)ptr)->fmt, va);
67869 * %pK cannot be used in IRQ context because its test
67870 @@ -1608,11 +1630,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67871 typeof(type) value; \
67872 if (sizeof(type) == 8) { \
67873 args = PTR_ALIGN(args, sizeof(u32)); \
67874 - *(u32 *)&value = *(u32 *)args; \
67875 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
67876 + *(u32 *)&value = *(const u32 *)args; \
67877 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
67879 args = PTR_ALIGN(args, sizeof(type)); \
67880 - value = *(typeof(type) *)args; \
67881 + value = *(const typeof(type) *)args; \
67883 args += sizeof(type); \
67885 @@ -1675,7 +1697,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67886 case FORMAT_TYPE_STR: {
67887 const char *str_arg = args;
67888 args += strlen(str_arg) + 1;
67889 - str = string(str, end, (char *)str_arg, spec);
67890 + str = string(str, end, str_arg, spec);
67894 diff --git a/localversion-grsec b/localversion-grsec
67895 new file mode 100644
67896 index 0000000..7cd6065
67898 +++ b/localversion-grsec
67901 diff --git a/mm/Kconfig b/mm/Kconfig
67902 index 011b110..b492af2 100644
67905 @@ -241,10 +241,10 @@ config KSM
67906 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
67908 config DEFAULT_MMAP_MIN_ADDR
67909 - int "Low address space to protect from user allocation"
67910 + int "Low address space to protect from user allocation"
67916 This is the portion of low virtual memory which should be protected
67917 from userspace allocation. Keeping a user from writing to low pages
67918 can help reduce the impact of kernel NULL pointer bugs.
67919 diff --git a/mm/filemap.c b/mm/filemap.c
67920 index 03c5b0e..a01e793 100644
67923 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
67924 struct address_space *mapping = file->f_mapping;
67926 if (!mapping->a_ops->readpage)
67929 file_accessed(file);
67930 vma->vm_ops = &generic_file_vm_ops;
67931 vma->vm_flags |= VM_CAN_NONLINEAR;
67932 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
67933 *pos = i_size_read(inode);
67935 if (limit != RLIM_INFINITY) {
67936 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
67937 if (*pos >= limit) {
67938 send_sig(SIGXFSZ, current, 0);
67940 diff --git a/mm/fremap.c b/mm/fremap.c
67941 index 9ed4fd4..c42648d 100644
67944 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
67946 vma = find_vma(mm, start);
67948 +#ifdef CONFIG_PAX_SEGMEXEC
67949 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
67954 * Make sure the vma is shared, that it supports prefaulting,
67955 * and that the remapped range is valid and fully within
67956 diff --git a/mm/highmem.c b/mm/highmem.c
67957 index 57d82c6..e9e0552 100644
67960 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
67961 * So no dangers, even with speculative execution.
67963 page = pte_page(pkmap_page_table[i]);
67964 + pax_open_kernel();
67965 pte_clear(&init_mm, (unsigned long)page_address(page),
67966 &pkmap_page_table[i]);
67968 + pax_close_kernel();
67969 set_page_address(page, NULL);
67972 @@ -186,9 +187,11 @@ start:
67975 vaddr = PKMAP_ADDR(last_pkmap_nr);
67977 + pax_open_kernel();
67978 set_pte_at(&init_mm, vaddr,
67979 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
67981 + pax_close_kernel();
67982 pkmap_count[last_pkmap_nr] = 1;
67983 set_page_address(page, (void *)vaddr);
67985 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
67986 index 33141f5..e56bef9 100644
67987 --- a/mm/huge_memory.c
67988 +++ b/mm/huge_memory.c
67989 @@ -703,7 +703,7 @@ out:
67990 * run pte_offset_map on the pmd, if an huge pmd could
67991 * materialize from under us from a different thread.
67993 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
67994 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
67995 return VM_FAULT_OOM;
67996 /* if an huge pmd materialized from under us just retry later */
67997 if (unlikely(pmd_trans_huge(*pmd)))
67998 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
67999 index 2316840..b418671 100644
68002 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
68006 +#ifdef CONFIG_PAX_SEGMEXEC
68007 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
68009 + struct mm_struct *mm = vma->vm_mm;
68010 + struct vm_area_struct *vma_m;
68011 + unsigned long address_m;
68014 + vma_m = pax_find_mirror_vma(vma);
68018 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68019 + address_m = address + SEGMEXEC_TASK_SIZE;
68020 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
68021 + get_page(page_m);
68022 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
68023 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
68028 * Hugetlb_cow() should be called with page lock of the original hugepage held.
68030 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
68031 make_huge_pte(vma, new_page, 1));
68032 page_remove_rmap(old_page);
68033 hugepage_add_new_anon_rmap(new_page, vma, address);
68035 +#ifdef CONFIG_PAX_SEGMEXEC
68036 + pax_mirror_huge_pte(vma, address, new_page);
68039 /* Make the old page be freed below */
68040 new_page = old_page;
68041 mmu_notifier_invalidate_range_end(mm,
68042 @@ -2601,6 +2627,10 @@ retry:
68043 && (vma->vm_flags & VM_SHARED)));
68044 set_huge_pte_at(mm, address, ptep, new_pte);
68046 +#ifdef CONFIG_PAX_SEGMEXEC
68047 + pax_mirror_huge_pte(vma, address, page);
68050 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
68051 /* Optimization, do the COW without a second fault */
68052 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
68053 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68054 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
68055 struct hstate *h = hstate_vma(vma);
68057 +#ifdef CONFIG_PAX_SEGMEXEC
68058 + struct vm_area_struct *vma_m;
68061 ptep = huge_pte_offset(mm, address);
68063 entry = huge_ptep_get(ptep);
68064 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68065 VM_FAULT_SET_HINDEX(h - hstates);
68068 +#ifdef CONFIG_PAX_SEGMEXEC
68069 + vma_m = pax_find_mirror_vma(vma);
68071 + unsigned long address_m;
68073 + if (vma->vm_start > vma_m->vm_start) {
68074 + address_m = address;
68075 + address -= SEGMEXEC_TASK_SIZE;
68077 + h = hstate_vma(vma);
68079 + address_m = address + SEGMEXEC_TASK_SIZE;
68081 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
68082 + return VM_FAULT_OOM;
68083 + address_m &= HPAGE_MASK;
68084 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
68088 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
68090 return VM_FAULT_OOM;
68091 diff --git a/mm/internal.h b/mm/internal.h
68092 index 2189af4..f2ca332 100644
68093 --- a/mm/internal.h
68094 +++ b/mm/internal.h
68095 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
68096 * in mm/page_alloc.c
68098 extern void __free_pages_bootmem(struct page *page, unsigned int order);
68099 +extern void free_compound_page(struct page *page);
68100 extern void prep_compound_page(struct page *page, unsigned long order);
68101 #ifdef CONFIG_MEMORY_FAILURE
68102 extern bool is_free_buddy_page(struct page *page);
68103 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
68104 index f3b2a00..61da94d 100644
68105 --- a/mm/kmemleak.c
68106 +++ b/mm/kmemleak.c
68107 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
68109 for (i = 0; i < object->trace_len; i++) {
68110 void *ptr = (void *)object->trace[i];
68111 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
68112 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
68116 diff --git a/mm/maccess.c b/mm/maccess.c
68117 index d53adf9..03a24bf 100644
68120 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
68122 pagefault_disable();
68123 ret = __copy_from_user_inatomic(dst,
68124 - (__force const void __user *)src, size);
68125 + (const void __force_user *)src, size);
68126 pagefault_enable();
68129 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
68132 pagefault_disable();
68133 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
68134 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
68135 pagefault_enable();
68138 diff --git a/mm/madvise.c b/mm/madvise.c
68139 index 74bf193..feb6fd3 100644
68142 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
68144 unsigned long new_flags = vma->vm_flags;
68146 +#ifdef CONFIG_PAX_SEGMEXEC
68147 + struct vm_area_struct *vma_m;
68150 switch (behavior) {
68152 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
68153 @@ -110,6 +114,13 @@ success:
68155 * vm_flags is protected by the mmap_sem held in write mode.
68158 +#ifdef CONFIG_PAX_SEGMEXEC
68159 + vma_m = pax_find_mirror_vma(vma);
68161 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
68164 vma->vm_flags = new_flags;
68167 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
68168 struct vm_area_struct ** prev,
68169 unsigned long start, unsigned long end)
68172 +#ifdef CONFIG_PAX_SEGMEXEC
68173 + struct vm_area_struct *vma_m;
68177 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
68179 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
68180 zap_page_range(vma, start, end - start, &details);
68182 zap_page_range(vma, start, end - start, NULL);
68184 +#ifdef CONFIG_PAX_SEGMEXEC
68185 + vma_m = pax_find_mirror_vma(vma);
68187 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
68188 + struct zap_details details = {
68189 + .nonlinear_vma = vma_m,
68190 + .last_index = ULONG_MAX,
68192 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
68194 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
68201 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
68205 +#ifdef CONFIG_PAX_SEGMEXEC
68206 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
68207 + if (end > SEGMEXEC_TASK_SIZE)
68212 + if (end > TASK_SIZE)
68218 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
68219 index 06d3479..0778eef 100644
68220 --- a/mm/memory-failure.c
68221 +++ b/mm/memory-failure.c
68222 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
68224 int sysctl_memory_failure_recovery __read_mostly = 1;
68226 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
68227 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
68229 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
68231 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
68232 si.si_signo = SIGBUS;
68234 si.si_code = BUS_MCEERR_AO;
68235 - si.si_addr = (void *)addr;
68236 + si.si_addr = (void __user *)addr;
68237 #ifdef __ARCH_SI_TRAPNO
68238 si.si_trapno = trapno;
68240 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
68243 nr_pages = 1 << compound_trans_order(hpage);
68244 - atomic_long_add(nr_pages, &mce_bad_pages);
68245 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
68248 * We need/can do nothing about count=0 pages.
68249 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
68250 if (!PageHWPoison(hpage)
68251 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
68252 || (p != hpage && TestSetPageHWPoison(hpage))) {
68253 - atomic_long_sub(nr_pages, &mce_bad_pages);
68254 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68257 set_page_hwpoison_huge_page(hpage);
68258 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
68260 if (hwpoison_filter(p)) {
68261 if (TestClearPageHWPoison(p))
68262 - atomic_long_sub(nr_pages, &mce_bad_pages);
68263 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68264 unlock_page(hpage);
68267 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
68270 if (TestClearPageHWPoison(p))
68271 - atomic_long_sub(nr_pages, &mce_bad_pages);
68272 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68273 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
68276 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
68278 if (TestClearPageHWPoison(page)) {
68279 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
68280 - atomic_long_sub(nr_pages, &mce_bad_pages);
68281 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68283 if (PageHuge(page))
68284 clear_page_hwpoison_huge_page(page);
68285 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
68288 if (!PageHWPoison(hpage))
68289 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
68290 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
68291 set_page_hwpoison_huge_page(hpage);
68292 dequeue_hwpoisoned_huge_page(hpage);
68293 /* keep elevated page count for bad page */
68294 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
68298 - atomic_long_add(1, &mce_bad_pages);
68299 + atomic_long_add_unchecked(1, &mce_bad_pages);
68300 SetPageHWPoison(page);
68301 /* keep elevated page count for bad page */
68303 diff --git a/mm/memory.c b/mm/memory.c
68304 index 829d437..3d3926a 100644
68307 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
68310 pmd = pmd_offset(pud, start);
68312 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
68314 pmd_free_tlb(tlb, pmd, start);
68319 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
68320 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
68321 if (end - 1 > ceiling - 1)
68324 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
68325 pud = pud_offset(pgd, start);
68327 pud_free_tlb(tlb, pud, start);
68333 @@ -1566,12 +1573,6 @@ no_page_table:
68337 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
68339 - return stack_guard_page_start(vma, addr) ||
68340 - stack_guard_page_end(vma, addr+PAGE_SIZE);
68344 * __get_user_pages() - pin user pages in memory
68345 * @tsk: task_struct of target task
68346 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68347 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
68351 + while (nr_pages) {
68352 struct vm_area_struct *vma;
68354 - vma = find_extend_vma(mm, start);
68355 + vma = find_vma(mm, start);
68356 if (!vma && in_gate_area(mm, start)) {
68357 unsigned long pg = start & PAGE_MASK;
68359 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68364 + if (!vma || start < vma->vm_start ||
68365 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
68366 !(vm_flags & vma->vm_flags))
68367 return i ? : -EFAULT;
68368 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68370 unsigned int fault_flags = 0;
68372 - /* For mlock, just skip the stack guard page. */
68373 - if (foll_flags & FOLL_MLOCK) {
68374 - if (stack_guard_page(vma, start))
68377 if (foll_flags & FOLL_WRITE)
68378 fault_flags |= FAULT_FLAG_WRITE;
68380 @@ -1800,7 +1796,7 @@ next_page:
68381 start += PAGE_SIZE;
68383 } while (nr_pages && start < vma->vm_end);
68384 - } while (nr_pages);
68388 EXPORT_SYMBOL(__get_user_pages);
68389 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
68390 page_add_file_rmap(page);
68391 set_pte_at(mm, addr, pte, mk_pte(page, prot));
68393 +#ifdef CONFIG_PAX_SEGMEXEC
68394 + pax_mirror_file_pte(vma, addr, page, ptl);
68398 pte_unmap_unlock(pte, ptl);
68400 @@ -2041,10 +2041,22 @@ out:
68401 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
68405 +#ifdef CONFIG_PAX_SEGMEXEC
68406 + struct vm_area_struct *vma_m;
68409 if (addr < vma->vm_start || addr >= vma->vm_end)
68411 if (!page_count(page))
68414 +#ifdef CONFIG_PAX_SEGMEXEC
68415 + vma_m = pax_find_mirror_vma(vma);
68417 + vma_m->vm_flags |= VM_INSERTPAGE;
68420 vma->vm_flags |= VM_INSERTPAGE;
68421 return insert_page(vma, addr, page, vma->vm_page_prot);
68423 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
68426 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
68427 + BUG_ON(vma->vm_mirror);
68429 if (addr < vma->vm_start || addr >= vma->vm_end)
68431 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
68432 copy_user_highpage(dst, src, va, vma);
68435 +#ifdef CONFIG_PAX_SEGMEXEC
68436 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
68438 + struct mm_struct *mm = vma->vm_mm;
68440 + pte_t *pte, entry;
68442 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
68444 + if (!pte_present(entry)) {
68445 + if (!pte_none(entry)) {
68446 + BUG_ON(pte_file(entry));
68447 + free_swap_and_cache(pte_to_swp_entry(entry));
68448 + pte_clear_not_present_full(mm, address, pte, 0);
68451 + struct page *page;
68453 + flush_cache_page(vma, address, pte_pfn(entry));
68454 + entry = ptep_clear_flush(vma, address, pte);
68455 + BUG_ON(pte_dirty(entry));
68456 + page = vm_normal_page(vma, address, entry);
68458 + update_hiwater_rss(mm);
68459 + if (PageAnon(page))
68460 + dec_mm_counter_fast(mm, MM_ANONPAGES);
68462 + dec_mm_counter_fast(mm, MM_FILEPAGES);
68463 + page_remove_rmap(page);
68464 + page_cache_release(page);
68467 + pte_unmap_unlock(pte, ptl);
68470 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
68472 + * the ptl of the lower mapped page is held on entry and is not released on exit
68473 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
68475 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68477 + struct mm_struct *mm = vma->vm_mm;
68478 + unsigned long address_m;
68479 + spinlock_t *ptl_m;
68480 + struct vm_area_struct *vma_m;
68482 + pte_t *pte_m, entry_m;
68484 + BUG_ON(!page_m || !PageAnon(page_m));
68486 + vma_m = pax_find_mirror_vma(vma);
68490 + BUG_ON(!PageLocked(page_m));
68491 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68492 + address_m = address + SEGMEXEC_TASK_SIZE;
68493 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68494 + pte_m = pte_offset_map(pmd_m, address_m);
68495 + ptl_m = pte_lockptr(mm, pmd_m);
68496 + if (ptl != ptl_m) {
68497 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68498 + if (!pte_none(*pte_m))
68502 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68503 + page_cache_get(page_m);
68504 + page_add_anon_rmap(page_m, vma_m, address_m);
68505 + inc_mm_counter_fast(mm, MM_ANONPAGES);
68506 + set_pte_at(mm, address_m, pte_m, entry_m);
68507 + update_mmu_cache(vma_m, address_m, entry_m);
68509 + if (ptl != ptl_m)
68510 + spin_unlock(ptl_m);
68511 + pte_unmap(pte_m);
68512 + unlock_page(page_m);
68515 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68517 + struct mm_struct *mm = vma->vm_mm;
68518 + unsigned long address_m;
68519 + spinlock_t *ptl_m;
68520 + struct vm_area_struct *vma_m;
68522 + pte_t *pte_m, entry_m;
68524 + BUG_ON(!page_m || PageAnon(page_m));
68526 + vma_m = pax_find_mirror_vma(vma);
68530 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68531 + address_m = address + SEGMEXEC_TASK_SIZE;
68532 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68533 + pte_m = pte_offset_map(pmd_m, address_m);
68534 + ptl_m = pte_lockptr(mm, pmd_m);
68535 + if (ptl != ptl_m) {
68536 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68537 + if (!pte_none(*pte_m))
68541 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68542 + page_cache_get(page_m);
68543 + page_add_file_rmap(page_m);
68544 + inc_mm_counter_fast(mm, MM_FILEPAGES);
68545 + set_pte_at(mm, address_m, pte_m, entry_m);
68546 + update_mmu_cache(vma_m, address_m, entry_m);
68548 + if (ptl != ptl_m)
68549 + spin_unlock(ptl_m);
68550 + pte_unmap(pte_m);
68553 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
68555 + struct mm_struct *mm = vma->vm_mm;
68556 + unsigned long address_m;
68557 + spinlock_t *ptl_m;
68558 + struct vm_area_struct *vma_m;
68560 + pte_t *pte_m, entry_m;
68562 + vma_m = pax_find_mirror_vma(vma);
68566 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68567 + address_m = address + SEGMEXEC_TASK_SIZE;
68568 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68569 + pte_m = pte_offset_map(pmd_m, address_m);
68570 + ptl_m = pte_lockptr(mm, pmd_m);
68571 + if (ptl != ptl_m) {
68572 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68573 + if (!pte_none(*pte_m))
68577 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
68578 + set_pte_at(mm, address_m, pte_m, entry_m);
68580 + if (ptl != ptl_m)
68581 + spin_unlock(ptl_m);
68582 + pte_unmap(pte_m);
68585 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
68587 + struct page *page_m;
68590 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
68594 + page_m = vm_normal_page(vma, address, entry);
68596 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
68597 + else if (PageAnon(page_m)) {
68598 + if (pax_find_mirror_vma(vma)) {
68599 + pte_unmap_unlock(pte, ptl);
68600 + lock_page(page_m);
68601 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
68602 + if (pte_same(entry, *pte))
68603 + pax_mirror_anon_pte(vma, address, page_m, ptl);
68605 + unlock_page(page_m);
68608 + pax_mirror_file_pte(vma, address, page_m, ptl);
68611 + pte_unmap_unlock(pte, ptl);
68616 * This routine handles present pages, when users try to write
68617 * to a shared page. It is done by copying the page to a new address
68618 @@ -2656,6 +2849,12 @@ gotten:
68620 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68621 if (likely(pte_same(*page_table, orig_pte))) {
68623 +#ifdef CONFIG_PAX_SEGMEXEC
68624 + if (pax_find_mirror_vma(vma))
68625 + BUG_ON(!trylock_page(new_page));
68629 if (!PageAnon(old_page)) {
68630 dec_mm_counter_fast(mm, MM_FILEPAGES);
68631 @@ -2707,6 +2906,10 @@ gotten:
68632 page_remove_rmap(old_page);
68635 +#ifdef CONFIG_PAX_SEGMEXEC
68636 + pax_mirror_anon_pte(vma, address, new_page, ptl);
68639 /* Free the old page.. */
68640 new_page = old_page;
68641 ret |= VM_FAULT_WRITE;
68642 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68644 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
68645 try_to_free_swap(page);
68647 +#ifdef CONFIG_PAX_SEGMEXEC
68648 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
68654 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68656 /* No need to invalidate - it was non-present before */
68657 update_mmu_cache(vma, address, page_table);
68659 +#ifdef CONFIG_PAX_SEGMEXEC
68660 + pax_mirror_anon_pte(vma, address, page, ptl);
68664 pte_unmap_unlock(page_table, ptl);
68666 @@ -3028,40 +3241,6 @@ out_release:
68670 - * This is like a special single-page "expand_{down|up}wards()",
68671 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
68672 - * doesn't hit another vma.
68674 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
68676 - address &= PAGE_MASK;
68677 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
68678 - struct vm_area_struct *prev = vma->vm_prev;
68681 - * Is there a mapping abutting this one below?
68683 - * That's only ok if it's the same stack mapping
68684 - * that has gotten split..
68686 - if (prev && prev->vm_end == address)
68687 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
68689 - expand_downwards(vma, address - PAGE_SIZE);
68691 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
68692 - struct vm_area_struct *next = vma->vm_next;
68694 - /* As VM_GROWSDOWN but s/below/above/ */
68695 - if (next && next->vm_start == address + PAGE_SIZE)
68696 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
68698 - expand_upwards(vma, address + PAGE_SIZE);
68704 * We enter with non-exclusive mmap_sem (to exclude vma changes,
68705 * but allow concurrent faults), and pte mapped but not yet locked.
68706 * We return with mmap_sem still held, but pte unmapped and unlocked.
68707 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68708 unsigned long address, pte_t *page_table, pmd_t *pmd,
68709 unsigned int flags)
68711 - struct page *page;
68712 + struct page *page = NULL;
68716 - pte_unmap(page_table);
68718 - /* Check if we need to add a guard page to the stack */
68719 - if (check_stack_guard_page(vma, address) < 0)
68720 - return VM_FAULT_SIGBUS;
68722 - /* Use the zero-page for reads */
68723 if (!(flags & FAULT_FLAG_WRITE)) {
68724 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
68725 vma->vm_page_prot));
68726 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68727 + ptl = pte_lockptr(mm, pmd);
68729 if (!pte_none(*page_table))
68734 /* Allocate our own private page. */
68735 + pte_unmap(page_table);
68737 if (unlikely(anon_vma_prepare(vma)))
68739 page = alloc_zeroed_user_highpage_movable(vma, address);
68740 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68741 if (!pte_none(*page_table))
68744 +#ifdef CONFIG_PAX_SEGMEXEC
68745 + if (pax_find_mirror_vma(vma))
68746 + BUG_ON(!trylock_page(page));
68749 inc_mm_counter_fast(mm, MM_ANONPAGES);
68750 page_add_new_anon_rmap(page, vma, address);
68752 @@ -3116,6 +3296,12 @@ setpte:
68754 /* No need to invalidate - it was non-present before */
68755 update_mmu_cache(vma, address, page_table);
68757 +#ifdef CONFIG_PAX_SEGMEXEC
68759 + pax_mirror_anon_pte(vma, address, page, ptl);
68763 pte_unmap_unlock(page_table, ptl);
68765 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68767 /* Only go through if we didn't race with anybody else... */
68768 if (likely(pte_same(*page_table, orig_pte))) {
68770 +#ifdef CONFIG_PAX_SEGMEXEC
68771 + if (anon && pax_find_mirror_vma(vma))
68772 + BUG_ON(!trylock_page(page));
68775 flush_icache_page(vma, page);
68776 entry = mk_pte(page, vma->vm_page_prot);
68777 if (flags & FAULT_FLAG_WRITE)
68778 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68780 /* no need to invalidate: a not-present page won't be cached */
68781 update_mmu_cache(vma, address, page_table);
68783 +#ifdef CONFIG_PAX_SEGMEXEC
68785 + pax_mirror_anon_pte(vma, address, page, ptl);
68787 + pax_mirror_file_pte(vma, address, page, ptl);
68792 mem_cgroup_uncharge_page(cow_page);
68793 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
68794 if (flags & FAULT_FLAG_WRITE)
68795 flush_tlb_fix_spurious_fault(vma, address);
68798 +#ifdef CONFIG_PAX_SEGMEXEC
68799 + pax_mirror_pte(vma, address, pte, pmd, ptl);
68804 pte_unmap_unlock(pte, ptl);
68806 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68810 +#ifdef CONFIG_PAX_SEGMEXEC
68811 + struct vm_area_struct *vma_m;
68814 __set_current_state(TASK_RUNNING);
68816 count_vm_event(PGFAULT);
68817 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68818 if (unlikely(is_vm_hugetlb_page(vma)))
68819 return hugetlb_fault(mm, vma, address, flags);
68821 +#ifdef CONFIG_PAX_SEGMEXEC
68822 + vma_m = pax_find_mirror_vma(vma);
68824 + unsigned long address_m;
68829 + if (vma->vm_start > vma_m->vm_start) {
68830 + address_m = address;
68831 + address -= SEGMEXEC_TASK_SIZE;
68834 + address_m = address + SEGMEXEC_TASK_SIZE;
68836 + pgd_m = pgd_offset(mm, address_m);
68837 + pud_m = pud_alloc(mm, pgd_m, address_m);
68839 + return VM_FAULT_OOM;
68840 + pmd_m = pmd_alloc(mm, pud_m, address_m);
68842 + return VM_FAULT_OOM;
68843 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
68844 + return VM_FAULT_OOM;
68845 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
68849 pgd = pgd_offset(mm, address);
68850 pud = pud_alloc(mm, pgd, address);
68852 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68853 * run pte_offset_map on the pmd, if an huge pmd could
68854 * materialize from under us from a different thread.
68856 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
68857 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
68858 return VM_FAULT_OOM;
68859 /* if an huge pmd materialized from under us just retry later */
68860 if (unlikely(pmd_trans_huge(*pmd)))
68861 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
68862 gate_vma.vm_start = FIXADDR_USER_START;
68863 gate_vma.vm_end = FIXADDR_USER_END;
68864 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
68865 - gate_vma.vm_page_prot = __P101;
68866 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
68868 * Make sure the vDSO gets into every core dump.
68869 * Dumping its contents makes post-mortem fully interpretable later
68870 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
68871 index c3fdbcb..2e8ef90 100644
68872 --- a/mm/mempolicy.c
68873 +++ b/mm/mempolicy.c
68874 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68875 unsigned long vmstart;
68876 unsigned long vmend;
68878 +#ifdef CONFIG_PAX_SEGMEXEC
68879 + struct vm_area_struct *vma_m;
68882 vma = find_vma_prev(mm, start, &prev);
68883 if (!vma || vma->vm_start > start)
68885 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68886 err = policy_vma(vma, new_pol);
68890 +#ifdef CONFIG_PAX_SEGMEXEC
68891 + vma_m = pax_find_mirror_vma(vma);
68893 + err = policy_vma(vma_m, new_pol);
68902 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
68907 +#ifdef CONFIG_PAX_SEGMEXEC
68908 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
68909 + if (end > SEGMEXEC_TASK_SIZE)
68914 + if (end > TASK_SIZE)
68920 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68924 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68925 + if (mm != current->mm &&
68926 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68933 * Check if this process has the right to modify the specified
68934 * process. The right exists if the process has administrative
68935 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68937 tcred = __task_cred(task);
68938 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68939 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68940 - !capable(CAP_SYS_NICE)) {
68941 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68945 diff --git a/mm/migrate.c b/mm/migrate.c
68946 index 177aca4..ab3a744 100644
68949 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68953 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68954 + if (mm != current->mm &&
68955 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68962 * Check if this process has the right to modify the specified
68963 * process. The right exists if the process has administrative
68964 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68966 tcred = __task_cred(task);
68967 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68968 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68969 - !capable(CAP_SYS_NICE)) {
68970 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68974 diff --git a/mm/mlock.c b/mm/mlock.c
68975 index 4f4f53b..9511904 100644
68979 #include <linux/pagemap.h>
68980 #include <linux/mempolicy.h>
68981 #include <linux/syscalls.h>
68982 +#include <linux/security.h>
68983 #include <linux/sched.h>
68984 #include <linux/export.h>
68985 #include <linux/rmap.h>
68986 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
68990 + if (end > TASK_SIZE)
68993 vma = find_vma_prev(current->mm, start, &prev);
68994 if (!vma || vma->vm_start > start)
68996 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
68997 for (nstart = start ; ; ) {
68998 vm_flags_t newflags;
69000 +#ifdef CONFIG_PAX_SEGMEXEC
69001 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
69005 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
69007 newflags = vma->vm_flags | VM_LOCKED;
69008 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
69009 lock_limit >>= PAGE_SHIFT;
69011 /* check against resource limits */
69012 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
69013 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
69014 error = do_mlock(start, len, 1);
69015 up_write(¤t->mm->mmap_sem);
69016 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
69017 static int do_mlockall(int flags)
69019 struct vm_area_struct * vma, * prev = NULL;
69020 - unsigned int def_flags = 0;
69022 if (flags & MCL_FUTURE)
69023 - def_flags = VM_LOCKED;
69024 - current->mm->def_flags = def_flags;
69025 + current->mm->def_flags |= VM_LOCKED;
69027 + current->mm->def_flags &= ~VM_LOCKED;
69028 if (flags == MCL_FUTURE)
69031 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
69032 vm_flags_t newflags;
69034 +#ifdef CONFIG_PAX_SEGMEXEC
69035 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
69039 + BUG_ON(vma->vm_end > TASK_SIZE);
69040 newflags = vma->vm_flags | VM_LOCKED;
69041 if (!(flags & MCL_CURRENT))
69042 newflags &= ~VM_LOCKED;
69043 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
69044 lock_limit >>= PAGE_SHIFT;
69047 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
69048 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
69049 capable(CAP_IPC_LOCK))
69050 ret = do_mlockall(flags);
69051 diff --git a/mm/mmap.c b/mm/mmap.c
69052 index eae90af..c930262 100644
69056 #define arch_rebalance_pgtables(addr, len) (addr)
69059 +static inline void verify_mm_writelocked(struct mm_struct *mm)
69061 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
69062 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
69063 + up_read(&mm->mmap_sem);
69069 static void unmap_region(struct mm_struct *mm,
69070 struct vm_area_struct *vma, struct vm_area_struct *prev,
69071 unsigned long start, unsigned long end);
69072 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
69073 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
69076 -pgprot_t protection_map[16] = {
69077 +pgprot_t protection_map[16] __read_only = {
69078 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
69079 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
69082 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
69083 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
69085 - return __pgprot(pgprot_val(protection_map[vm_flags &
69086 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
69087 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
69088 pgprot_val(arch_vm_get_page_prot(vm_flags)));
69090 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69091 + if (!(__supported_pte_mask & _PAGE_NX) &&
69092 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
69093 + (vm_flags & (VM_READ | VM_WRITE)))
69094 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
69099 EXPORT_SYMBOL(vm_get_page_prot);
69101 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
69102 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
69103 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
69104 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
69106 * Make sure vm_committed_as in one cacheline and not cacheline shared with
69107 * other variables. It can be updated by several CPUs frequently.
69108 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
69109 struct vm_area_struct *next = vma->vm_next;
69112 + BUG_ON(vma->vm_mirror);
69113 if (vma->vm_ops && vma->vm_ops->close)
69114 vma->vm_ops->close(vma);
69115 if (vma->vm_file) {
69116 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
69117 * not page aligned -Ram Gupta
69119 rlim = rlimit(RLIMIT_DATA);
69120 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
69121 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
69122 (mm->end_data - mm->start_data) > rlim)
69124 @@ -689,6 +711,12 @@ static int
69125 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
69126 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
69129 +#ifdef CONFIG_PAX_SEGMEXEC
69130 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
69134 if (is_mergeable_vma(vma, file, vm_flags) &&
69135 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
69136 if (vma->vm_pgoff == vm_pgoff)
69137 @@ -708,6 +736,12 @@ static int
69138 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
69139 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
69142 +#ifdef CONFIG_PAX_SEGMEXEC
69143 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
69147 if (is_mergeable_vma(vma, file, vm_flags) &&
69148 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
69150 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
69151 struct vm_area_struct *vma_merge(struct mm_struct *mm,
69152 struct vm_area_struct *prev, unsigned long addr,
69153 unsigned long end, unsigned long vm_flags,
69154 - struct anon_vma *anon_vma, struct file *file,
69155 + struct anon_vma *anon_vma, struct file *file,
69156 pgoff_t pgoff, struct mempolicy *policy)
69158 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
69159 struct vm_area_struct *area, *next;
69162 +#ifdef CONFIG_PAX_SEGMEXEC
69163 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
69164 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
69166 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
69170 * We later require that vma->vm_flags == vm_flags,
69171 * so this tests vma->vm_flags & VM_SPECIAL, too.
69172 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
69173 if (next && next->vm_end == end) /* cases 6, 7, 8 */
69174 next = next->vm_next;
69176 +#ifdef CONFIG_PAX_SEGMEXEC
69178 + prev_m = pax_find_mirror_vma(prev);
69180 + area_m = pax_find_mirror_vma(area);
69182 + next_m = pax_find_mirror_vma(next);
69186 * Can it merge with the predecessor?
69188 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
69190 err = vma_adjust(prev, prev->vm_start,
69191 next->vm_end, prev->vm_pgoff, NULL);
69192 - } else /* cases 2, 5, 7 */
69194 +#ifdef CONFIG_PAX_SEGMEXEC
69195 + if (!err && prev_m)
69196 + err = vma_adjust(prev_m, prev_m->vm_start,
69197 + next_m->vm_end, prev_m->vm_pgoff, NULL);
69200 + } else { /* cases 2, 5, 7 */
69201 err = vma_adjust(prev, prev->vm_start,
69202 end, prev->vm_pgoff, NULL);
69204 +#ifdef CONFIG_PAX_SEGMEXEC
69205 + if (!err && prev_m)
69206 + err = vma_adjust(prev_m, prev_m->vm_start,
69207 + end_m, prev_m->vm_pgoff, NULL);
69213 khugepaged_enter_vma_merge(prev);
69214 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
69215 mpol_equal(policy, vma_policy(next)) &&
69216 can_vma_merge_before(next, vm_flags,
69217 anon_vma, file, pgoff+pglen)) {
69218 - if (prev && addr < prev->vm_end) /* case 4 */
69219 + if (prev && addr < prev->vm_end) { /* case 4 */
69220 err = vma_adjust(prev, prev->vm_start,
69221 addr, prev->vm_pgoff, NULL);
69222 - else /* cases 3, 8 */
69224 +#ifdef CONFIG_PAX_SEGMEXEC
69225 + if (!err && prev_m)
69226 + err = vma_adjust(prev_m, prev_m->vm_start,
69227 + addr_m, prev_m->vm_pgoff, NULL);
69230 + } else { /* cases 3, 8 */
69231 err = vma_adjust(area, addr, next->vm_end,
69232 next->vm_pgoff - pglen, NULL);
69234 +#ifdef CONFIG_PAX_SEGMEXEC
69235 + if (!err && area_m)
69236 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
69237 + next_m->vm_pgoff - pglen, NULL);
69243 khugepaged_enter_vma_merge(area);
69244 @@ -921,14 +1001,11 @@ none:
69245 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
69246 struct file *file, long pages)
69248 - const unsigned long stack_flags
69249 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
69252 mm->shared_vm += pages;
69253 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
69254 mm->exec_vm += pages;
69255 - } else if (flags & stack_flags)
69256 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
69257 mm->stack_vm += pages;
69258 if (flags & (VM_RESERVED|VM_IO))
69259 mm->reserved_vm += pages;
69260 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69261 * (the exception is when the underlying filesystem is noexec
69262 * mounted, in which case we dont add PROT_EXEC.)
69264 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
69265 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
69266 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
69269 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69270 /* Obtain the address to map to. we verify (or select) it and ensure
69271 * that it represents a valid section of the address space.
69273 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
69274 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
69275 if (addr & ~PAGE_MASK)
69278 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69279 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
69280 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
69282 +#ifdef CONFIG_PAX_MPROTECT
69283 + if (mm->pax_flags & MF_PAX_MPROTECT) {
69284 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
69285 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
69286 + gr_log_rwxmmap(file);
69288 +#ifdef CONFIG_PAX_EMUPLT
69289 + vm_flags &= ~VM_EXEC;
69296 + if (!(vm_flags & VM_EXEC))
69297 + vm_flags &= ~VM_MAYEXEC;
69299 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
69300 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
69303 + vm_flags &= ~VM_MAYWRITE;
69307 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69308 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
69309 + vm_flags &= ~VM_PAGEEXEC;
69312 if (flags & MAP_LOCKED)
69313 if (!can_do_mlock())
69315 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69316 locked += mm->locked_vm;
69317 lock_limit = rlimit(RLIMIT_MEMLOCK);
69318 lock_limit >>= PAGE_SHIFT;
69319 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69320 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
69323 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69327 + if (!gr_acl_handle_mmap(file, prot))
69330 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
69332 EXPORT_SYMBOL(do_mmap_pgoff);
69333 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
69334 vm_flags_t vm_flags = vma->vm_flags;
69336 /* If it was private or non-writable, the write bit is already clear */
69337 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
69338 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
69341 /* The backer wishes to know when pages are first written to? */
69342 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
69343 unsigned long charged = 0;
69344 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
69346 +#ifdef CONFIG_PAX_SEGMEXEC
69347 + struct vm_area_struct *vma_m = NULL;
69351 + * mm->mmap_sem is required to protect against another thread
69352 + * changing the mappings in case we sleep.
69354 + verify_mm_writelocked(mm);
69356 /* Clear old maps */
69359 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69360 if (vma && vma->vm_start < addr + len) {
69361 if (do_munmap(mm, addr, len))
69363 - goto munmap_back;
69364 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69365 + BUG_ON(vma && vma->vm_start < addr + len);
69368 /* Check against address space limit. */
69369 @@ -1258,6 +1379,16 @@ munmap_back:
69373 +#ifdef CONFIG_PAX_SEGMEXEC
69374 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
69375 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69384 vma->vm_start = addr;
69385 vma->vm_end = addr + len;
69386 @@ -1266,8 +1397,9 @@ munmap_back:
69387 vma->vm_pgoff = pgoff;
69388 INIT_LIST_HEAD(&vma->anon_vma_chain);
69390 + error = -EINVAL; /* when rejecting VM_GROWSDOWN|VM_GROWSUP */
69394 if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
69396 if (vm_flags & VM_DENYWRITE) {
69397 @@ -1281,6 +1413,19 @@ munmap_back:
69398 error = file->f_op->mmap(file, vma);
69400 goto unmap_and_free_vma;
69402 +#ifdef CONFIG_PAX_SEGMEXEC
69403 + if (vma_m && (vm_flags & VM_EXECUTABLE))
69404 + added_exe_file_vma(mm);
69407 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69408 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
69409 + vma->vm_flags |= VM_PAGEEXEC;
69410 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69414 if (vm_flags & VM_EXECUTABLE)
69415 added_exe_file_vma(mm);
69417 @@ -1293,6 +1438,8 @@ munmap_back:
69418 pgoff = vma->vm_pgoff;
69419 vm_flags = vma->vm_flags;
69420 } else if (vm_flags & VM_SHARED) {
69421 + if (unlikely(vm_flags & (VM_GROWSDOWN|VM_GROWSUP)))
69423 error = shmem_zero_setup(vma);
69426 @@ -1316,6 +1463,11 @@ munmap_back:
69427 vma_link(mm, vma, prev, rb_link, rb_parent);
69428 file = vma->vm_file;
69430 +#ifdef CONFIG_PAX_SEGMEXEC
69432 + BUG_ON(pax_mirror_vma(vma_m, vma));
69435 /* Once vma denies write, undo our temporary denial count */
69436 if (correct_wcount)
69437 atomic_inc(&inode->i_writecount);
69438 @@ -1324,6 +1476,7 @@ out:
69440 mm->total_vm += len >> PAGE_SHIFT;
69441 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
69442 + track_exec_limit(mm, addr, addr + len, vm_flags);
69443 if (vm_flags & VM_LOCKED) {
69444 if (!mlock_vma_pages_range(vma, addr, addr + len))
69445 mm->locked_vm += (len >> PAGE_SHIFT);
69446 @@ -1341,6 +1494,12 @@ unmap_and_free_vma:
69447 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
69451 +#ifdef CONFIG_PAX_SEGMEXEC
69453 + kmem_cache_free(vm_area_cachep, vma_m);
69456 kmem_cache_free(vm_area_cachep, vma);
69459 @@ -1348,6 +1507,44 @@ unacct_error:
69463 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
69466 +#ifdef CONFIG_STACK_GROWSUP
69467 + if (addr > sysctl_heap_stack_gap)
69468 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
69470 + vma = find_vma(current->mm, 0);
69471 + if (vma && (vma->vm_flags & VM_GROWSUP))
69477 + if (addr + len > vma->vm_start)
69480 + if (vma->vm_flags & VM_GROWSDOWN)
69481 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
69482 +#ifdef CONFIG_STACK_GROWSUP
69483 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
69484 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
69490 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
69492 + if (vma->vm_start < len)
69494 + if (!(vma->vm_flags & VM_GROWSDOWN))
69495 + return vma->vm_start - len;
69496 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
69497 + return vma->vm_start - len - sysctl_heap_stack_gap;
69501 /* Get an address range which is currently unmapped.
69502 * For shmat() with addr=0.
69504 @@ -1374,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
69505 if (flags & MAP_FIXED)
69508 +#ifdef CONFIG_PAX_RANDMMAP
69509 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69513 addr = PAGE_ALIGN(addr);
69514 - vma = find_vma(mm, addr);
69515 - if (TASK_SIZE - len >= addr &&
69516 - (!vma || addr + len <= vma->vm_start))
69518 + if (TASK_SIZE - len >= addr) {
69519 + vma = find_vma(mm, addr);
69520 + if (check_heap_stack_gap(vma, addr, len))
69524 if (len > mm->cached_hole_size) {
69525 - start_addr = addr = mm->free_area_cache;
69526 + start_addr = addr = mm->free_area_cache;
69528 - start_addr = addr = TASK_UNMAPPED_BASE;
69529 - mm->cached_hole_size = 0;
69530 + start_addr = addr = mm->mmap_base;
69531 + mm->cached_hole_size = 0;
69535 @@ -1396,34 +1598,40 @@ full_search:
69536 * Start a new search - just in case we missed
69539 - if (start_addr != TASK_UNMAPPED_BASE) {
69540 - addr = TASK_UNMAPPED_BASE;
69541 - start_addr = addr;
69542 + if (start_addr != mm->mmap_base) {
69543 + start_addr = addr = mm->mmap_base;
69544 mm->cached_hole_size = 0;
69549 - if (!vma || addr + len <= vma->vm_start) {
69551 - * Remember the place where we stopped the search:
69553 - mm->free_area_cache = addr + len;
69556 + if (check_heap_stack_gap(vma, addr, len))
69558 if (addr + mm->cached_hole_size < vma->vm_start)
69559 mm->cached_hole_size = vma->vm_start - addr;
69560 addr = vma->vm_end;
69564 + * Remember the place where we stopped the search:
69566 + mm->free_area_cache = addr + len;
69571 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
69574 +#ifdef CONFIG_PAX_SEGMEXEC
69575 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69580 * Is this a new hole at the lowest possible address?
69582 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
69583 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
69584 mm->free_area_cache = addr;
69585 mm->cached_hole_size = ~0UL;
69587 @@ -1441,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69589 struct vm_area_struct *vma;
69590 struct mm_struct *mm = current->mm;
69591 - unsigned long addr = addr0;
69592 + unsigned long base = mm->mmap_base, addr = addr0;
69594 /* requested length too big for entire address space */
69595 if (len > TASK_SIZE)
69596 @@ -1450,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69597 if (flags & MAP_FIXED)
69600 +#ifdef CONFIG_PAX_RANDMMAP
69601 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69604 /* requesting a specific address */
69606 addr = PAGE_ALIGN(addr);
69607 - vma = find_vma(mm, addr);
69608 - if (TASK_SIZE - len >= addr &&
69609 - (!vma || addr + len <= vma->vm_start))
69611 + if (TASK_SIZE - len >= addr) {
69612 + vma = find_vma(mm, addr);
69613 + if (check_heap_stack_gap(vma, addr, len))
69618 /* check if free_area_cache is useful for us */
69619 @@ -1471,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69620 /* make sure it can fit in the remaining address space */
69622 vma = find_vma(mm, addr-len);
69623 - if (!vma || addr <= vma->vm_start)
69624 + if (check_heap_stack_gap(vma, addr - len, len))
69625 /* remember the address as a hint for next time */
69626 return (mm->free_area_cache = addr-len);
69628 @@ -1488,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69629 * return with success:
69631 vma = find_vma(mm, addr);
69632 - if (!vma || addr+len <= vma->vm_start)
69633 + if (check_heap_stack_gap(vma, addr, len))
69634 /* remember the address as a hint for next time */
69635 return (mm->free_area_cache = addr);
69637 @@ -1497,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69638 mm->cached_hole_size = vma->vm_start - addr;
69640 /* try just below the current vma->vm_start */
69641 - addr = vma->vm_start-len;
69642 - } while (len < vma->vm_start);
69643 + addr = skip_heap_stack_gap(vma, len);
69644 + } while (!IS_ERR_VALUE(addr));
69648 @@ -1507,13 +1720,21 @@ bottomup:
69649 * can happen with large stack limits and large mmap()
69652 + mm->mmap_base = TASK_UNMAPPED_BASE;
69654 +#ifdef CONFIG_PAX_RANDMMAP
69655 + if (mm->pax_flags & MF_PAX_RANDMMAP)
69656 + mm->mmap_base += mm->delta_mmap;
69659 + mm->free_area_cache = mm->mmap_base;
69660 mm->cached_hole_size = ~0UL;
69661 - mm->free_area_cache = TASK_UNMAPPED_BASE;
69662 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
69664 * Restore the topdown base:
69666 - mm->free_area_cache = mm->mmap_base;
69667 + mm->mmap_base = base;
69668 + mm->free_area_cache = base;
69669 mm->cached_hole_size = ~0UL;
69672 @@ -1522,6 +1743,12 @@ bottomup:
69674 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69677 +#ifdef CONFIG_PAX_SEGMEXEC
69678 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69683 * Is this a new hole at the highest possible address?
69685 @@ -1529,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69686 mm->free_area_cache = addr;
69688 /* dont allow allocations above current base */
69689 - if (mm->free_area_cache > mm->mmap_base)
69690 + if (mm->free_area_cache > mm->mmap_base) {
69691 mm->free_area_cache = mm->mmap_base;
69692 + mm->cached_hole_size = ~0UL;
69697 @@ -1603,40 +1832,50 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
69699 EXPORT_SYMBOL(find_vma);
69701 -/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */
69703 + * Same as find_vma, but also return a pointer to the previous VMA in *pprev.
69705 struct vm_area_struct *
69706 find_vma_prev(struct mm_struct *mm, unsigned long addr,
69707 struct vm_area_struct **pprev)
69709 - struct vm_area_struct *vma = NULL, *prev = NULL;
69710 - struct rb_node *rb_node;
69714 - /* Guard against addr being lower than the first VMA */
69717 - /* Go through the RB tree quickly. */
69718 - rb_node = mm->mm_rb.rb_node;
69720 - while (rb_node) {
69721 - struct vm_area_struct *vma_tmp;
69722 - vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
69724 - if (addr < vma_tmp->vm_end) {
69725 - rb_node = rb_node->rb_left;
69728 - if (!prev->vm_next || (addr < prev->vm_next->vm_end))
69730 + struct vm_area_struct *vma;
69732 + vma = find_vma(mm, addr);
69734 + *pprev = vma->vm_prev;
69736 + struct rb_node *rb_node = mm->mm_rb.rb_node;
69738 + while (rb_node) {
69739 + *pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb);
69740 rb_node = rb_node->rb_right;
69746 +#ifdef CONFIG_PAX_SEGMEXEC
69747 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
69749 + struct vm_area_struct *vma_m;
69753 - return prev ? prev->vm_next : vma;
69754 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
69755 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
69756 + BUG_ON(vma->vm_mirror);
69759 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
69760 + vma_m = vma->vm_mirror;
69761 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
69762 + BUG_ON(vma->vm_file != vma_m->vm_file);
69763 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
69764 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
69765 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
69766 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
69772 * Verify that the stack growth is acceptable and
69773 @@ -1654,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69776 /* Stack limit test */
69777 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
69778 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
69781 @@ -1664,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69782 locked = mm->locked_vm + grow;
69783 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
69784 limit >>= PAGE_SHIFT;
69785 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69786 if (locked > limit && !capable(CAP_IPC_LOCK))
69789 @@ -1694,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69790 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
69791 * vma is the last one with address > vma->vm_end. Have to extend vma.
69793 +#ifndef CONFIG_IA64
69796 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69801 if (!(vma->vm_flags & VM_GROWSUP))
69804 + /* Also guard against wrapping around to address 0. */
69805 + if (address < PAGE_ALIGN(address+1))
69806 + address = PAGE_ALIGN(address+1);
69811 * We must make sure the anon_vma is allocated
69812 * so that the anon_vma locking is not a noop.
69814 if (unlikely(anon_vma_prepare(vma)))
69816 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
69817 + if (locknext && anon_vma_prepare(vma->vm_next))
69819 vma_lock_anon_vma(vma);
69821 + vma_lock_anon_vma(vma->vm_next);
69824 * vma->vm_start/vm_end cannot change under us because the caller
69825 * is required to hold the mmap_sem in read mode. We need the
69826 - * anon_vma lock to serialize against concurrent expand_stacks.
69827 - * Also guard against wrapping around to address 0.
69828 + * anon_vma locks to serialize against concurrent expand_stacks
69829 + * and expand_upwards.
69831 - if (address < PAGE_ALIGN(address+4))
69832 - address = PAGE_ALIGN(address+4);
69834 - vma_unlock_anon_vma(vma);
69839 /* Somebody else might have raced and expanded it already */
69840 - if (address > vma->vm_end) {
69841 + 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)
69843 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
69844 unsigned long size, grow;
69846 size = address - vma->vm_start;
69847 @@ -1739,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69852 + vma_unlock_anon_vma(vma->vm_next);
69853 vma_unlock_anon_vma(vma);
69854 khugepaged_enter_vma_merge(vma);
69856 @@ -1752,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
69857 unsigned long address)
69860 + bool lockprev = false;
69861 + struct vm_area_struct *prev;
69864 * We must make sure the anon_vma is allocated
69865 @@ -1765,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
69869 + prev = vma->vm_prev;
69870 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
69871 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
69873 + if (lockprev && anon_vma_prepare(prev))
69876 + vma_lock_anon_vma(prev);
69878 vma_lock_anon_vma(vma);
69881 @@ -1774,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
69884 /* Somebody else might have raced and expanded it already */
69885 - if (address < vma->vm_start) {
69886 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
69888 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
69889 unsigned long size, grow;
69891 +#ifdef CONFIG_PAX_SEGMEXEC
69892 + struct vm_area_struct *vma_m;
69894 + vma_m = pax_find_mirror_vma(vma);
69897 size = vma->vm_end - address;
69898 grow = (vma->vm_start - address) >> PAGE_SHIFT;
69900 @@ -1786,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
69902 vma->vm_start = address;
69903 vma->vm_pgoff -= grow;
69904 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
69906 +#ifdef CONFIG_PAX_SEGMEXEC
69908 + vma_m->vm_start -= grow << PAGE_SHIFT;
69909 + vma_m->vm_pgoff -= grow;
69913 perf_event_mmap(vma);
69917 vma_unlock_anon_vma(vma);
69919 + vma_unlock_anon_vma(prev);
69920 khugepaged_enter_vma_merge(vma);
69923 @@ -1860,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
69925 long nrpages = vma_pages(vma);
69927 +#ifdef CONFIG_PAX_SEGMEXEC
69928 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
69929 + vma = remove_vma(vma);
69934 mm->total_vm -= nrpages;
69935 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
69936 vma = remove_vma(vma);
69937 @@ -1905,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
69938 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
69939 vma->vm_prev = NULL;
69942 +#ifdef CONFIG_PAX_SEGMEXEC
69943 + if (vma->vm_mirror) {
69944 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
69945 + vma->vm_mirror->vm_mirror = NULL;
69946 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
69947 + vma->vm_mirror = NULL;
69951 rb_erase(&vma->vm_rb, &mm->mm_rb);
69954 @@ -1933,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69955 struct vm_area_struct *new;
69958 +#ifdef CONFIG_PAX_SEGMEXEC
69959 + struct vm_area_struct *vma_m, *new_m = NULL;
69960 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
69963 if (is_vm_hugetlb_page(vma) && (addr &
69964 ~(huge_page_mask(hstate_vma(vma)))))
69967 +#ifdef CONFIG_PAX_SEGMEXEC
69968 + vma_m = pax_find_mirror_vma(vma);
69971 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69975 +#ifdef CONFIG_PAX_SEGMEXEC
69977 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69979 + kmem_cache_free(vm_area_cachep, new);
69985 /* most fields are the same, copy all, and then fixup */
69988 @@ -1953,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69989 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
69992 +#ifdef CONFIG_PAX_SEGMEXEC
69995 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
69996 + new_m->vm_mirror = new;
69997 + new->vm_mirror = new_m;
70000 + new_m->vm_end = addr_m;
70002 + new_m->vm_start = addr_m;
70003 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
70008 pol = mpol_dup(vma_policy(vma));
70010 err = PTR_ERR(pol);
70011 @@ -1978,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70013 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
70015 +#ifdef CONFIG_PAX_SEGMEXEC
70016 + if (!err && vma_m) {
70017 + if (anon_vma_clone(new_m, vma_m))
70018 + goto out_free_mpol;
70021 + vma_set_policy(new_m, pol);
70023 + if (new_m->vm_file) {
70024 + get_file(new_m->vm_file);
70025 + if (vma_m->vm_flags & VM_EXECUTABLE)
70026 + added_exe_file_vma(mm);
70029 + if (new_m->vm_ops && new_m->vm_ops->open)
70030 + new_m->vm_ops->open(new_m);
70033 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
70034 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
70036 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
70039 + if (new_m->vm_ops && new_m->vm_ops->close)
70040 + new_m->vm_ops->close(new_m);
70041 + if (new_m->vm_file) {
70042 + if (vma_m->vm_flags & VM_EXECUTABLE)
70043 + removed_exe_file_vma(mm);
70044 + fput(new_m->vm_file);
70054 @@ -1990,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70055 removed_exe_file_vma(mm);
70056 fput(new->vm_file);
70058 - unlink_anon_vmas(new);
70063 +#ifdef CONFIG_PAX_SEGMEXEC
70065 + unlink_anon_vmas(new_m);
70066 + kmem_cache_free(vm_area_cachep, new_m);
70070 + unlink_anon_vmas(new);
70071 kmem_cache_free(vm_area_cachep, new);
70074 @@ -2006,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
70075 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
70076 unsigned long addr, int new_below)
70079 +#ifdef CONFIG_PAX_SEGMEXEC
70080 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70081 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
70082 + if (mm->map_count >= sysctl_max_map_count-1)
70087 if (mm->map_count >= sysctl_max_map_count)
70090 @@ -2017,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
70091 * work. This now handles partial unmappings.
70092 * Jeremy Fitzhardinge <jeremy@goop.org>
70094 +#ifdef CONFIG_PAX_SEGMEXEC
70095 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
70097 + int ret = __do_munmap(mm, start, len);
70098 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
70101 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
70104 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
70106 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
70110 struct vm_area_struct *vma, *prev, *last;
70113 + * mm->mmap_sem is required to protect against another thread
70114 + * changing the mappings in case we sleep.
70116 + verify_mm_writelocked(mm);
70118 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
70121 @@ -2096,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
70122 /* Fix up all other VM information */
70123 remove_vma_list(mm, vma);
70125 + track_exec_limit(mm, start, end, 0UL);
70130 @@ -2108,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
70132 profile_munmap(addr);
70134 +#ifdef CONFIG_PAX_SEGMEXEC
70135 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
70136 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
70140 down_write(&mm->mmap_sem);
70141 ret = do_munmap(mm, addr, len);
70142 up_write(&mm->mmap_sem);
70146 -static inline void verify_mm_writelocked(struct mm_struct *mm)
70148 -#ifdef CONFIG_DEBUG_VM
70149 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70151 - up_read(&mm->mmap_sem);
70157 * this is really a simplified "do_mmap". it only handles
70158 * anonymous maps. eventually we may be able to do some
70159 @@ -2137,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70160 struct rb_node ** rb_link, * rb_parent;
70161 pgoff_t pgoff = addr >> PAGE_SHIFT;
70163 + unsigned long charged;
70165 len = PAGE_ALIGN(len);
70167 @@ -2148,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70169 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
70171 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
70172 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
70173 + flags &= ~VM_EXEC;
70175 +#ifdef CONFIG_PAX_MPROTECT
70176 + if (mm->pax_flags & MF_PAX_MPROTECT)
70177 + flags &= ~VM_MAYEXEC;
70183 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
70184 if (error & ~PAGE_MASK)
70187 + charged = len >> PAGE_SHIFT;
70190 * mlock MCL_FUTURE?
70192 if (mm->def_flags & VM_LOCKED) {
70193 unsigned long locked, lock_limit;
70194 - locked = len >> PAGE_SHIFT;
70195 + locked = charged;
70196 locked += mm->locked_vm;
70197 lock_limit = rlimit(RLIMIT_MEMLOCK);
70198 lock_limit >>= PAGE_SHIFT;
70199 @@ -2174,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70201 * Clear old maps. this also does some error checking for us
70204 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70205 if (vma && vma->vm_start < addr + len) {
70206 if (do_munmap(mm, addr, len))
70208 - goto munmap_back;
70209 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70210 + BUG_ON(vma && vma->vm_start < addr + len);
70213 /* Check against address space limits *after* clearing old maps... */
70214 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
70215 + if (!may_expand_vm(mm, charged))
70218 if (mm->map_count > sysctl_max_map_count)
70221 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
70222 + if (security_vm_enough_memory(charged))
70225 /* Can we just expand an old private anonymous mapping? */
70226 @@ -2203,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70228 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70230 - vm_unacct_memory(len >> PAGE_SHIFT);
70231 + vm_unacct_memory(charged);
70235 @@ -2217,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70236 vma_link(mm, vma, prev, rb_link, rb_parent);
70238 perf_event_mmap(vma);
70239 - mm->total_vm += len >> PAGE_SHIFT;
70240 + mm->total_vm += charged;
70241 if (flags & VM_LOCKED) {
70242 if (!mlock_vma_pages_range(vma, addr, addr + len))
70243 - mm->locked_vm += (len >> PAGE_SHIFT);
70244 + mm->locked_vm += charged;
70246 + track_exec_limit(mm, addr, addr + len, flags);
70250 @@ -2268,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
70251 * Walk the list again, actually closing and freeing it,
70252 * with preemption enabled, without holding any MM locks.
70256 + vma->vm_mirror = NULL;
70257 vma = remove_vma(vma);
70260 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
70262 @@ -2283,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
70263 struct vm_area_struct * __vma, * prev;
70264 struct rb_node ** rb_link, * rb_parent;
70266 +#ifdef CONFIG_PAX_SEGMEXEC
70267 + struct vm_area_struct *vma_m = NULL;
70270 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
70274 * The vm_pgoff of a purely anonymous vma should be irrelevant
70275 * until its first write fault, when page's anon_vma and index
70276 @@ -2305,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
70277 if ((vma->vm_flags & VM_ACCOUNT) &&
70278 security_vm_enough_memory_mm(mm, vma_pages(vma)))
70281 +#ifdef CONFIG_PAX_SEGMEXEC
70282 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
70283 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70289 vma_link(mm, vma, prev, rb_link, rb_parent);
70291 +#ifdef CONFIG_PAX_SEGMEXEC
70293 + BUG_ON(pax_mirror_vma(vma_m, vma));
70299 @@ -2323,6 +2769,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
70300 struct rb_node **rb_link, *rb_parent;
70301 struct mempolicy *pol;
70303 + BUG_ON(vma->vm_mirror);
70306 * If anonymous vma has not yet been faulted, update new pgoff
70307 * to match new location, to increase its chance of merging.
70308 @@ -2373,6 +2821,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
70312 +#ifdef CONFIG_PAX_SEGMEXEC
70313 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
70315 + struct vm_area_struct *prev_m;
70316 + struct rb_node **rb_link_m, *rb_parent_m;
70317 + struct mempolicy *pol_m;
70319 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
70320 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
70321 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
70323 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
70324 + if (anon_vma_clone(vma_m, vma))
70326 + pol_m = vma_policy(vma_m);
70328 + vma_set_policy(vma_m, pol_m);
70329 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
70330 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
70331 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
70332 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
70333 + if (vma_m->vm_file)
70334 + get_file(vma_m->vm_file);
70335 + if (vma_m->vm_ops && vma_m->vm_ops->open)
70336 + vma_m->vm_ops->open(vma_m);
70337 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
70338 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
70339 + vma_m->vm_mirror = vma;
70340 + vma->vm_mirror = vma_m;
70346 * Return true if the calling process may expand its vm space by the passed
70348 @@ -2383,7 +2864,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
70351 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
70353 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
70354 if (cur + npages > lim)
70357 @@ -2454,6 +2935,22 @@ int install_special_mapping(struct mm_struct *mm,
70358 vma->vm_start = addr;
70359 vma->vm_end = addr + len;
70361 +#ifdef CONFIG_PAX_MPROTECT
70362 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70363 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70364 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
70366 + if (!(vm_flags & VM_EXEC))
70367 + vm_flags &= ~VM_MAYEXEC;
70369 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70370 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70373 + vm_flags &= ~VM_MAYWRITE;
70377 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
70378 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70380 diff --git a/mm/mprotect.c b/mm/mprotect.c
70381 index 5a688a2..27e031c 100644
70382 --- a/mm/mprotect.c
70383 +++ b/mm/mprotect.c
70384 @@ -23,10 +23,16 @@
70385 #include <linux/mmu_notifier.h>
70386 #include <linux/migrate.h>
70387 #include <linux/perf_event.h>
70389 +#ifdef CONFIG_PAX_MPROTECT
70390 +#include <linux/elf.h>
70393 #include <asm/uaccess.h>
70394 #include <asm/pgtable.h>
70395 #include <asm/cacheflush.h>
70396 #include <asm/tlbflush.h>
70397 +#include <asm/mmu_context.h>
70399 #ifndef pgprot_modify
70400 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
70401 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
70402 flush_tlb_range(vma, start, end);
70405 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70406 +/* called while holding the mmap semaphor for writing except stack expansion */
70407 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
70409 + unsigned long oldlimit, newlimit = 0UL;
70411 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
70414 + spin_lock(&mm->page_table_lock);
70415 + oldlimit = mm->context.user_cs_limit;
70416 + if ((prot & VM_EXEC) && oldlimit < end)
70417 + /* USER_CS limit moved up */
70419 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
70420 + /* USER_CS limit moved down */
70421 + newlimit = start;
70424 + mm->context.user_cs_limit = newlimit;
70428 + cpus_clear(mm->context.cpu_user_cs_mask);
70429 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
70432 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
70434 + spin_unlock(&mm->page_table_lock);
70435 + if (newlimit == end) {
70436 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
70438 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
70439 + if (is_vm_hugetlb_page(vma))
70440 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
70442 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
70448 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70449 unsigned long start, unsigned long end, unsigned long newflags)
70450 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70452 int dirty_accountable = 0;
70454 +#ifdef CONFIG_PAX_SEGMEXEC
70455 + struct vm_area_struct *vma_m = NULL;
70456 + unsigned long start_m, end_m;
70458 + start_m = start + SEGMEXEC_TASK_SIZE;
70459 + end_m = end + SEGMEXEC_TASK_SIZE;
70462 if (newflags == oldflags) {
70467 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
70468 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
70470 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
70473 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
70478 * If we make a private mapping writable we increase our commit;
70479 * but (without finer accounting) cannot reduce our commit if we
70480 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70484 +#ifdef CONFIG_PAX_SEGMEXEC
70485 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
70486 + if (start != vma->vm_start) {
70487 + error = split_vma(mm, vma, start, 1);
70490 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
70491 + *pprev = (*pprev)->vm_next;
70494 + if (end != vma->vm_end) {
70495 + error = split_vma(mm, vma, end, 0);
70500 + if (pax_find_mirror_vma(vma)) {
70501 + error = __do_munmap(mm, start_m, end_m - start_m);
70505 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70510 + vma->vm_flags = newflags;
70511 + error = pax_mirror_vma(vma_m, vma);
70513 + vma->vm_flags = oldflags;
70521 * First try to merge with previous and/or next vma.
70523 @@ -204,9 +306,21 @@ success:
70524 * vm_flags and vm_page_prot are protected by the mmap_sem
70525 * held in write mode.
70528 +#ifdef CONFIG_PAX_SEGMEXEC
70529 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
70530 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
70533 vma->vm_flags = newflags;
70535 +#ifdef CONFIG_PAX_MPROTECT
70536 + if (mm->binfmt && mm->binfmt->handle_mprotect)
70537 + mm->binfmt->handle_mprotect(vma, newflags);
70540 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
70541 - vm_get_page_prot(newflags));
70542 + vm_get_page_prot(vma->vm_flags));
70544 if (vma_wants_writenotify(vma)) {
70545 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
70546 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70551 +#ifdef CONFIG_PAX_SEGMEXEC
70552 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70553 + if (end > SEGMEXEC_TASK_SIZE)
70558 + if (end > TASK_SIZE)
70561 if (!arch_validate_prot(prot))
70564 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70566 * Does the application expect PROT_READ to imply PROT_EXEC:
70568 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70569 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70572 vm_flags = calc_vm_prot_bits(prot);
70573 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70574 if (start > vma->vm_start)
70577 +#ifdef CONFIG_PAX_MPROTECT
70578 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
70579 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
70582 for (nstart = start ; ; ) {
70583 unsigned long newflags;
70585 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70587 /* newflags >> 4 shift VM_MAY% in place of VM_% */
70588 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
70589 + if (prot & (PROT_WRITE | PROT_EXEC))
70590 + gr_log_rwxmprotect(vma->vm_file);
70596 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
70600 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70601 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
70605 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
70609 if (nstart < prev->vm_end)
70610 diff --git a/mm/mremap.c b/mm/mremap.c
70611 index d6959cb..18a402a 100644
70614 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
70616 pte = ptep_get_and_clear(mm, old_addr, old_pte);
70617 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
70619 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70620 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
70621 + pte = pte_exprotect(pte);
70624 set_pte_at(mm, new_addr, new_pte, pte);
70627 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
70628 if (is_vm_hugetlb_page(vma))
70631 +#ifdef CONFIG_PAX_SEGMEXEC
70632 + if (pax_find_mirror_vma(vma))
70636 /* We can't remap across vm area boundaries */
70637 if (old_len > vma->vm_end - addr)
70639 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
70640 unsigned long ret = -EINVAL;
70641 unsigned long charged = 0;
70642 unsigned long map_flags;
70643 + unsigned long pax_task_size = TASK_SIZE;
70645 if (new_addr & ~PAGE_MASK)
70648 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
70649 +#ifdef CONFIG_PAX_SEGMEXEC
70650 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70651 + pax_task_size = SEGMEXEC_TASK_SIZE;
70654 + pax_task_size -= PAGE_SIZE;
70656 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
70659 /* Check if the location we're moving into overlaps the
70660 * old location at all, and fail if it does.
70662 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
70665 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
70666 + if (addr + old_len > new_addr && new_addr + new_len > addr)
70669 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70670 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
70671 struct vm_area_struct *vma;
70672 unsigned long ret = -EINVAL;
70673 unsigned long charged = 0;
70674 + unsigned long pax_task_size = TASK_SIZE;
70676 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
70678 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
70682 +#ifdef CONFIG_PAX_SEGMEXEC
70683 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70684 + pax_task_size = SEGMEXEC_TASK_SIZE;
70687 + pax_task_size -= PAGE_SIZE;
70689 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
70690 + old_len > pax_task_size || addr > pax_task_size-old_len)
70693 if (flags & MREMAP_FIXED) {
70694 if (flags & MREMAP_MAYMOVE)
70695 ret = mremap_to(addr, old_len, new_addr, new_len);
70696 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
70700 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
70704 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
70705 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70709 + map_flags = vma->vm_flags;
70710 ret = move_vma(vma, addr, old_len, new_len, new_addr);
70711 + if (!(ret & ~PAGE_MASK)) {
70712 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
70713 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
70717 if (ret & ~PAGE_MASK)
70718 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
70719 index 7fa41b4..6087460 100644
70720 --- a/mm/nobootmem.c
70721 +++ b/mm/nobootmem.c
70722 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
70723 unsigned long __init free_all_memory_core_early(int nodeid)
70727 + u64 start, end, startrange, endrange;
70728 unsigned long count = 0;
70729 - struct range *range = NULL;
70730 + struct range *range = NULL, rangerange = { 0, 0 };
70733 nr_range = get_free_all_memory_range(&range, nodeid);
70734 + startrange = __pa(range) >> PAGE_SHIFT;
70735 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
70737 for (i = 0; i < nr_range; i++) {
70738 start = range[i].start;
70739 end = range[i].end;
70740 + if (start <= endrange && startrange < end) {
70741 + BUG_ON(rangerange.start | rangerange.end);
70742 + rangerange = range[i];
70745 count += end - start;
70746 __free_pages_memory(start, end);
70748 + start = rangerange.start;
70749 + end = rangerange.end;
70750 + count += end - start;
70751 + __free_pages_memory(start, end);
70755 diff --git a/mm/nommu.c b/mm/nommu.c
70756 index ee7e57e..cae4e40 100644
70759 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
70760 int sysctl_overcommit_ratio = 50; /* default is 50% */
70761 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
70762 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
70763 -int heap_stack_gap = 0;
70765 atomic_long_t mmap_pages_allocated;
70767 @@ -829,15 +828,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
70768 EXPORT_SYMBOL(find_vma);
70772 - * - we don't extend stack VMAs under NOMMU conditions
70774 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
70776 - return find_vma(mm, addr);
70780 * expand a stack to a given address
70781 * - not supported under NOMMU conditions
70783 @@ -1557,6 +1547,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
70785 /* most fields are the same, copy all, and then fixup */
70787 + INIT_LIST_HEAD(&new->anon_vma_chain);
70788 *region = *vma->vm_region;
70789 new->vm_region = region;
70791 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
70792 index 485be89..c059ad3 100644
70793 --- a/mm/page_alloc.c
70794 +++ b/mm/page_alloc.c
70795 @@ -341,7 +341,7 @@ out:
70796 * This usage means that zero-order pages may not be compound.
70799 -static void free_compound_page(struct page *page)
70800 +void free_compound_page(struct page *page)
70802 __free_pages_ok(page, compound_order(page));
70804 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70808 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70809 + unsigned long index = 1UL << order;
70812 trace_mm_page_free_direct(page, order);
70813 kmemcheck_free_shadow(page, order);
70815 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70816 debug_check_no_obj_freed(page_address(page),
70817 PAGE_SIZE << order);
70820 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70821 + for (; index; --index)
70822 + sanitize_highpage(page + index - 1);
70825 arch_free_page(page, order);
70826 kernel_map_pages(page, 1 << order, 0);
70828 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
70829 arch_alloc_page(page, order);
70830 kernel_map_pages(page, 1 << order, 1);
70832 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
70833 if (gfp_flags & __GFP_ZERO)
70834 prep_zero_page(page, order, gfp_flags);
70837 if (order && (gfp_flags & __GFP_COMP))
70838 prep_compound_page(page, order);
70839 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
70842 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
70843 +#ifdef CONFIG_X86_32
70844 + /* boot failures in VMware 8 on 32bit vanilla since
70846 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
70848 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
70853 diff --git a/mm/percpu.c b/mm/percpu.c
70854 index 716eb4a..8d10419 100644
70857 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
70858 static unsigned int pcpu_high_unit_cpu __read_mostly;
70860 /* the address of the first chunk which starts with the kernel static area */
70861 -void *pcpu_base_addr __read_mostly;
70862 +void *pcpu_base_addr __read_only;
70863 EXPORT_SYMBOL_GPL(pcpu_base_addr);
70865 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
70866 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
70867 index e920aa3..137702a 100644
70868 --- a/mm/process_vm_access.c
70869 +++ b/mm/process_vm_access.c
70871 #include <linux/uio.h>
70872 #include <linux/sched.h>
70873 #include <linux/highmem.h>
70874 +#include <linux/security.h>
70875 #include <linux/ptrace.h>
70876 #include <linux/slab.h>
70877 #include <linux/syscalls.h>
70878 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70879 size_t iov_l_curr_offset = 0;
70882 + return -ENOSYS; // PaX: until properly audited
70885 * Work out how many pages of struct pages we're going to need
70886 * when eventually calling get_user_pages
70888 for (i = 0; i < riovcnt; i++) {
70889 iov_len = rvec[i].iov_len;
70890 - if (iov_len > 0) {
70891 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
70893 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
70895 - nr_pages = max(nr_pages, nr_pages_iov);
70897 + if (iov_len <= 0)
70899 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
70900 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
70901 + nr_pages = max(nr_pages, nr_pages_iov);
70905 @@ -298,23 +299,23 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70906 goto free_proc_pages;
70910 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
70911 - task_unlock(task);
70912 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
70914 goto put_task_struct;
70918 - if (!mm || (task->flags & PF_KTHREAD)) {
70919 - task_unlock(task);
70921 + mm = mm_access(task, PTRACE_MODE_ATTACH);
70922 + if (!mm || IS_ERR(mm)) {
70923 + rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
70925 + * Explicitly map EACCES to EPERM as EPERM is a more a
70926 + * appropriate error code for process_vw_readv/writev
70928 + if (rc == -EACCES)
70930 goto put_task_struct;
70933 - atomic_inc(&mm->mm_users);
70934 - task_unlock(task);
70936 for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
70937 rc = process_vm_rw_single_vec(
70938 (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
70939 diff --git a/mm/rmap.c b/mm/rmap.c
70940 index a4fd368..e0ffec7 100644
70943 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70944 struct anon_vma *anon_vma = vma->anon_vma;
70945 struct anon_vma_chain *avc;
70947 +#ifdef CONFIG_PAX_SEGMEXEC
70948 + struct anon_vma_chain *avc_m = NULL;
70952 if (unlikely(!anon_vma)) {
70953 struct mm_struct *mm = vma->vm_mm;
70954 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70958 +#ifdef CONFIG_PAX_SEGMEXEC
70959 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
70961 + goto out_enomem_free_avc;
70964 anon_vma = find_mergeable_anon_vma(vma);
70967 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70968 /* page_table_lock to protect against threads */
70969 spin_lock(&mm->page_table_lock);
70970 if (likely(!vma->anon_vma)) {
70972 +#ifdef CONFIG_PAX_SEGMEXEC
70973 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
70976 + BUG_ON(vma_m->anon_vma);
70977 + vma_m->anon_vma = anon_vma;
70978 + avc_m->anon_vma = anon_vma;
70979 + avc_m->vma = vma;
70980 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
70981 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
70986 vma->anon_vma = anon_vma;
70987 avc->anon_vma = anon_vma;
70989 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70991 if (unlikely(allocated))
70992 put_anon_vma(allocated);
70994 +#ifdef CONFIG_PAX_SEGMEXEC
70995 + if (unlikely(avc_m))
70996 + anon_vma_chain_free(avc_m);
71000 anon_vma_chain_free(avc);
71004 out_enomem_free_avc:
71006 +#ifdef CONFIG_PAX_SEGMEXEC
71008 + anon_vma_chain_free(avc_m);
71011 anon_vma_chain_free(avc);
71014 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
71015 * Attach the anon_vmas from src to dst.
71016 * Returns 0 on success, -ENOMEM on failure.
71018 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
71019 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
71021 struct anon_vma_chain *avc, *pavc;
71022 struct anon_vma *root = NULL;
71023 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
71024 * the corresponding VMA in the parent process is attached to.
71025 * Returns 0 on success, non-zero on failure.
71027 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
71028 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
71030 struct anon_vma_chain *avc;
71031 struct anon_vma *anon_vma;
71032 diff --git a/mm/shmem.c b/mm/shmem.c
71033 index 6c253f7..367e20a 100644
71037 #include <linux/export.h>
71038 #include <linux/swap.h>
71040 -static struct vfsmount *shm_mnt;
71041 +struct vfsmount *shm_mnt;
71043 #ifdef CONFIG_SHMEM
71045 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
71046 #define BOGO_DIRENT_SIZE 20
71048 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
71049 -#define SHORT_SYMLINK_LEN 128
71050 +#define SHORT_SYMLINK_LEN 64
71052 struct shmem_xattr {
71053 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
71054 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
71057 /* Round up to L1_CACHE_BYTES to resist false sharing */
71058 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
71059 - L1_CACHE_BYTES), GFP_KERNEL);
71060 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
71064 diff --git a/mm/slab.c b/mm/slab.c
71065 index 83311c9a..fcf8f86 100644
71068 @@ -151,7 +151,7 @@
71070 /* Legal flag mask for kmem_cache_create(). */
71072 -# define CREATE_MASK (SLAB_RED_ZONE | \
71073 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
71074 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
71076 SLAB_STORE_USER | \
71077 @@ -159,7 +159,7 @@
71078 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
71079 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
71081 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
71082 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
71084 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
71085 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
71086 @@ -288,7 +288,7 @@ struct kmem_list3 {
71087 * Need this for bootstrapping a per node allocator.
71089 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
71090 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
71091 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
71092 #define CACHE_CACHE 0
71093 #define SIZE_AC MAX_NUMNODES
71094 #define SIZE_L3 (2 * MAX_NUMNODES)
71095 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
71096 if ((x)->max_freeable < i) \
71097 (x)->max_freeable = i; \
71099 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
71100 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
71101 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
71102 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
71103 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
71104 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
71105 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
71106 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
71108 #define STATS_INC_ACTIVE(x) do { } while (0)
71109 #define STATS_DEC_ACTIVE(x) do { } while (0)
71110 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
71111 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
71113 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
71114 - const struct slab *slab, void *obj)
71115 + const struct slab *slab, const void *obj)
71117 u32 offset = (obj - slab->s_mem);
71118 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
71119 @@ -564,7 +564,7 @@ struct cache_names {
71120 static struct cache_names __initdata cache_names[] = {
71121 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
71122 #include <linux/kmalloc_sizes.h>
71128 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
71129 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
71130 sizes[INDEX_AC].cs_size,
71131 ARCH_KMALLOC_MINALIGN,
71132 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
71133 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
71136 if (INDEX_AC != INDEX_L3) {
71137 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
71138 kmem_cache_create(names[INDEX_L3].name,
71139 sizes[INDEX_L3].cs_size,
71140 ARCH_KMALLOC_MINALIGN,
71141 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
71142 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
71146 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
71147 sizes->cs_cachep = kmem_cache_create(names->name,
71149 ARCH_KMALLOC_MINALIGN,
71150 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
71151 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
71154 #ifdef CONFIG_ZONE_DMA
71155 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
71159 - unsigned long allochit = atomic_read(&cachep->allochit);
71160 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
71161 - unsigned long freehit = atomic_read(&cachep->freehit);
71162 - unsigned long freemiss = atomic_read(&cachep->freemiss);
71163 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
71164 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
71165 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
71166 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
71168 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
71169 allochit, allocmiss, freehit, freemiss);
71170 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
71172 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
71173 #ifdef CONFIG_DEBUG_SLAB_LEAK
71174 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
71175 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
71179 module_init(slab_proc_init);
71182 +void check_object_size(const void *ptr, unsigned long n, bool to)
71185 +#ifdef CONFIG_PAX_USERCOPY
71186 + struct page *page;
71187 + struct kmem_cache *cachep = NULL;
71188 + struct slab *slabp;
71189 + unsigned int objnr;
71190 + unsigned long offset;
71191 + const char *type;
71197 + if (ZERO_OR_NULL_PTR(ptr))
71200 + if (!virt_addr_valid(ptr))
71203 + page = virt_to_head_page(ptr);
71205 + type = "<process stack>";
71206 + if (!PageSlab(page)) {
71207 + if (object_is_on_stack(ptr, n) == -1)
71212 + cachep = page_get_cache(page);
71213 + type = cachep->name;
71214 + if (!(cachep->flags & SLAB_USERCOPY))
71217 + slabp = page_get_slab(page);
71218 + objnr = obj_to_index(cachep, slabp, ptr);
71219 + BUG_ON(objnr >= cachep->num);
71220 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
71221 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
71225 + pax_report_usercopy(ptr, n, to, type);
71229 +EXPORT_SYMBOL(check_object_size);
71232 * ksize - get the actual amount of memory allocated for a given object
71233 * @objp: Pointer to the object
71234 diff --git a/mm/slob.c b/mm/slob.c
71235 index 8105be4..e045f96 100644
71239 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
71240 * alloc_pages() directly, allocating compound pages so the page order
71241 * does not have to be separately tracked, and also stores the exact
71242 - * allocation size in page->private so that it can be used to accurately
71243 + * allocation size in slob_page->size so that it can be used to accurately
71244 * provide ksize(). These objects are detected in kfree() because slob_page()
71245 * is false for them.
71250 #include <linux/kernel.h>
71251 +#include <linux/sched.h>
71252 #include <linux/slab.h>
71253 #include <linux/mm.h>
71254 #include <linux/swap.h> /* struct reclaim_state */
71255 @@ -102,7 +103,8 @@ struct slob_page {
71256 unsigned long flags; /* mandatory */
71257 atomic_t _count; /* mandatory */
71258 slobidx_t units; /* free units left in page */
71259 - unsigned long pad[2];
71260 + unsigned long pad[1];
71261 + unsigned long size; /* size when >=PAGE_SIZE */
71262 slob_t *free; /* first free slob_t in page */
71263 struct list_head list; /* linked list of free pages */
71265 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
71267 static inline int is_slob_page(struct slob_page *sp)
71269 - return PageSlab((struct page *)sp);
71270 + return PageSlab((struct page *)sp) && !sp->size;
71273 static inline void set_slob_page(struct slob_page *sp)
71274 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
71276 static inline struct slob_page *slob_page(const void *addr)
71278 - return (struct slob_page *)virt_to_page(addr);
71279 + return (struct slob_page *)virt_to_head_page(addr);
71283 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
71285 * Return the size of a slob block.
71287 -static slobidx_t slob_units(slob_t *s)
71288 +static slobidx_t slob_units(const slob_t *s)
71292 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
71294 * Return the next free slob block pointer after this one.
71296 -static slob_t *slob_next(slob_t *s)
71297 +static slob_t *slob_next(const slob_t *s)
71299 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
71301 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
71303 * Returns true if s is the last free block in its page.
71305 -static int slob_last(slob_t *s)
71306 +static int slob_last(const slob_t *s)
71308 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
71310 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
71314 + set_slob_page(page);
71315 return page_address(page);
71318 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
71322 - set_slob_page(sp);
71324 spin_lock_irqsave(&slob_lock, flags);
71325 sp->units = SLOB_UNITS(PAGE_SIZE);
71328 INIT_LIST_HEAD(&sp->list);
71329 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
71330 set_slob_page_free(sp, slob_list);
71331 @@ -476,10 +479,9 @@ out:
71332 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
71335 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71336 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
71339 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71343 gfp &= gfp_allowed_mask;
71344 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71349 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
71350 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
71351 + m[0].units = size;
71352 + m[1].units = align;
71353 ret = (void *)m + align;
71355 trace_kmalloc_node(_RET_IP_, ret,
71356 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71358 ret = slob_new_pages(gfp, order, node);
71360 - struct page *page;
71361 - page = virt_to_page(ret);
71362 - page->private = size;
71363 + struct slob_page *sp;
71364 + sp = slob_page(ret);
71368 trace_kmalloc_node(_RET_IP_, ret,
71369 size, PAGE_SIZE << order, gfp, node);
71372 - kmemleak_alloc(ret, size, 1, gfp);
71376 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71378 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71379 + void *ret = __kmalloc_node_align(size, gfp, node, align);
71381 + if (!ZERO_OR_NULL_PTR(ret))
71382 + kmemleak_alloc(ret, size, 1, gfp);
71385 EXPORT_SYMBOL(__kmalloc_node);
71386 @@ -533,13 +547,92 @@ void kfree(const void *block)
71387 sp = slob_page(block);
71388 if (is_slob_page(sp)) {
71389 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71390 - unsigned int *m = (unsigned int *)(block - align);
71391 - slob_free(m, *m + align);
71393 + slob_t *m = (slob_t *)(block - align);
71394 + slob_free(m, m[0].units + align);
71396 + clear_slob_page(sp);
71397 + free_slob_page(sp);
71399 put_page(&sp->page);
71402 EXPORT_SYMBOL(kfree);
71404 +void check_object_size(const void *ptr, unsigned long n, bool to)
71407 +#ifdef CONFIG_PAX_USERCOPY
71408 + struct slob_page *sp;
71409 + const slob_t *free;
71410 + const void *base;
71411 + unsigned long flags;
71412 + const char *type;
71418 + if (ZERO_OR_NULL_PTR(ptr))
71421 + if (!virt_addr_valid(ptr))
71424 + type = "<process stack>";
71425 + sp = slob_page(ptr);
71426 + if (!PageSlab((struct page *)sp)) {
71427 + if (object_is_on_stack(ptr, n) == -1)
71434 + base = page_address(&sp->page);
71435 + if (base <= ptr && n <= sp->size - (ptr - base))
71440 + /* some tricky double walking to find the chunk */
71441 + spin_lock_irqsave(&slob_lock, flags);
71442 + base = (void *)((unsigned long)ptr & PAGE_MASK);
71445 + while (!slob_last(free) && (void *)free <= ptr) {
71446 + base = free + slob_units(free);
71447 + free = slob_next(free);
71450 + while (base < (void *)free) {
71451 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
71452 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
71455 + if (ptr < base + align)
71458 + offset = ptr - base - align;
71459 + if (offset >= m) {
71464 + if (n > m - offset)
71467 + spin_unlock_irqrestore(&slob_lock, flags);
71471 + spin_unlock_irqrestore(&slob_lock, flags);
71473 + pax_report_usercopy(ptr, n, to, type);
71477 +EXPORT_SYMBOL(check_object_size);
71479 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
71480 size_t ksize(const void *block)
71482 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
71483 sp = slob_page(block);
71484 if (is_slob_page(sp)) {
71485 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71486 - unsigned int *m = (unsigned int *)(block - align);
71487 - return SLOB_UNITS(*m) * SLOB_UNIT;
71488 + slob_t *m = (slob_t *)(block - align);
71489 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
71491 - return sp->page.private;
71494 EXPORT_SYMBOL(ksize);
71496 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71498 struct kmem_cache *c;
71500 +#ifdef CONFIG_PAX_USERCOPY
71501 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
71502 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
71504 c = slob_alloc(sizeof(struct kmem_cache),
71505 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
71510 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
71512 lockdep_trace_alloc(flags);
71514 +#ifdef CONFIG_PAX_USERCOPY
71515 + b = __kmalloc_node_align(c->size, flags, node, c->align);
71517 if (c->size < PAGE_SIZE) {
71518 b = slob_alloc(c->size, flags, c->align, node);
71519 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71520 SLOB_UNITS(c->size) * SLOB_UNIT,
71523 + struct slob_page *sp;
71525 b = slob_new_pages(flags, get_order(c->size), node);
71526 + sp = slob_page(b);
71527 + sp->size = c->size;
71528 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71529 PAGE_SIZE << get_order(c->size),
71536 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
71538 static void __kmem_cache_free(void *b, int size)
71540 - if (size < PAGE_SIZE)
71541 + struct slob_page *sp = slob_page(b);
71543 + if (is_slob_page(sp))
71544 slob_free(b, size);
71547 + clear_slob_page(sp);
71548 + free_slob_page(sp);
71550 slob_free_pages(b, get_order(size));
71554 static void kmem_rcu_free(struct rcu_head *head)
71555 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
71557 void kmem_cache_free(struct kmem_cache *c, void *b)
71559 + int size = c->size;
71561 +#ifdef CONFIG_PAX_USERCOPY
71562 + if (size + c->align < PAGE_SIZE) {
71563 + size += c->align;
71568 kmemleak_free_recursive(b, c->flags);
71569 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
71570 struct slob_rcu *slob_rcu;
71571 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
71572 - slob_rcu->size = c->size;
71573 + slob_rcu = b + (size - sizeof(struct slob_rcu));
71574 + slob_rcu->size = size;
71575 call_rcu(&slob_rcu->head, kmem_rcu_free);
71577 - __kmem_cache_free(b, c->size);
71578 + __kmem_cache_free(b, size);
71581 +#ifdef CONFIG_PAX_USERCOPY
71582 + trace_kfree(_RET_IP_, b);
71584 trace_kmem_cache_free(_RET_IP_, b);
71588 EXPORT_SYMBOL(kmem_cache_free);
71590 diff --git a/mm/slub.c b/mm/slub.c
71591 index 1a919f0..1739c9b 100644
71594 @@ -208,7 +208,7 @@ struct track {
71596 enum track_item { TRACK_ALLOC, TRACK_FREE };
71598 -#ifdef CONFIG_SYSFS
71599 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71600 static int sysfs_slab_add(struct kmem_cache *);
71601 static int sysfs_slab_alias(struct kmem_cache *, const char *);
71602 static void sysfs_slab_remove(struct kmem_cache *);
71603 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
71607 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
71608 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
71609 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
71610 #ifdef CONFIG_STACKTRACE
71612 @@ -2559,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
71614 page = virt_to_head_page(x);
71616 + BUG_ON(!PageSlab(page));
71618 slab_free(s, page, x, _RET_IP_);
71620 trace_kmem_cache_free(_RET_IP_, x);
71621 @@ -2592,7 +2594,7 @@ static int slub_min_objects;
71622 * Merge control. If this is set then no merging of slab caches will occur.
71623 * (Could be removed. This was introduced to pacify the merge skeptics.)
71625 -static int slub_nomerge;
71626 +static int slub_nomerge = 1;
71629 * Calculate the order of allocation given an slab object size.
71630 @@ -3042,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
71632 s->cpu_partial = 30;
71635 + atomic_set(&s->refcount, 1);
71637 s->remote_node_defrag_ratio = 1000;
71639 @@ -3146,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
71640 void kmem_cache_destroy(struct kmem_cache *s)
71642 down_write(&slub_lock);
71644 - if (!s->refcount) {
71645 + if (atomic_dec_and_test(&s->refcount)) {
71646 list_del(&s->list);
71647 up_write(&slub_lock);
71648 if (kmem_cache_close(s)) {
71649 @@ -3358,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
71650 EXPORT_SYMBOL(__kmalloc_node);
71653 +void check_object_size(const void *ptr, unsigned long n, bool to)
71656 +#ifdef CONFIG_PAX_USERCOPY
71657 + struct page *page;
71658 + struct kmem_cache *s = NULL;
71659 + unsigned long offset;
71660 + const char *type;
71666 + if (ZERO_OR_NULL_PTR(ptr))
71669 + if (!virt_addr_valid(ptr))
71672 + page = virt_to_head_page(ptr);
71674 + type = "<process stack>";
71675 + if (!PageSlab(page)) {
71676 + if (object_is_on_stack(ptr, n) == -1)
71683 + if (!(s->flags & SLAB_USERCOPY))
71686 + offset = (ptr - page_address(page)) % s->size;
71687 + if (offset <= s->objsize && n <= s->objsize - offset)
71691 + pax_report_usercopy(ptr, n, to, type);
71695 +EXPORT_SYMBOL(check_object_size);
71697 size_t ksize(const void *object)
71700 @@ -3632,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
71703 list_add(&s->list, &slab_caches);
71704 - s->refcount = -1;
71705 + atomic_set(&s->refcount, -1);
71707 for_each_node_state(node, N_NORMAL_MEMORY) {
71708 struct kmem_cache_node *n = get_node(s, node);
71709 @@ -3749,17 +3794,17 @@ void __init kmem_cache_init(void)
71711 /* Caches that are not of the two-to-the-power-of size */
71712 if (KMALLOC_MIN_SIZE <= 32) {
71713 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
71714 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
71718 if (KMALLOC_MIN_SIZE <= 64) {
71719 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
71720 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
71724 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
71725 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
71726 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
71730 @@ -3827,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
71732 * We may have set a slab to be unmergeable during bootstrap.
71734 - if (s->refcount < 0)
71735 + if (atomic_read(&s->refcount) < 0)
71739 @@ -3886,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71740 down_write(&slub_lock);
71741 s = find_mergeable(size, align, flags, name, ctor);
71744 + atomic_inc(&s->refcount);
71746 * Adjust the object sizes so that we clear
71747 * the complete object on kzalloc.
71748 @@ -3895,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71749 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
71751 if (sysfs_slab_alias(s, name)) {
71753 + atomic_dec(&s->refcount);
71756 up_write(&slub_lock);
71757 @@ -4023,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
71761 -#ifdef CONFIG_SYSFS
71762 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71763 static int count_inuse(struct page *page)
71765 return page->inuse;
71766 @@ -4410,12 +4455,12 @@ static void resiliency_test(void)
71767 validate_slab_cache(kmalloc_caches[9]);
71770 -#ifdef CONFIG_SYSFS
71771 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71772 static void resiliency_test(void) {};
71776 -#ifdef CONFIG_SYSFS
71777 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71778 enum slab_stat_type {
71779 SL_ALL, /* All slabs */
71780 SL_PARTIAL, /* Only partially allocated slabs */
71781 @@ -4656,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
71783 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
71785 - return sprintf(buf, "%d\n", s->refcount - 1);
71786 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
71788 SLAB_ATTR_RO(aliases);
71790 @@ -5223,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
71794 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71795 static int sysfs_slab_add(struct kmem_cache *s)
71798 @@ -5285,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
71799 kobject_del(&s->kobj);
71800 kobject_put(&s->kobj);
71805 * Need to buffer aliases during bootup until sysfs becomes
71806 @@ -5298,6 +5345,7 @@ struct saved_alias {
71808 static struct saved_alias *alias_list;
71810 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71811 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71813 struct saved_alias *al;
71814 @@ -5320,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71820 static int __init slab_sysfs_init(void)
71822 diff --git a/mm/swap.c b/mm/swap.c
71823 index 55b266d..a532537 100644
71827 #include <linux/backing-dev.h>
71828 #include <linux/memcontrol.h>
71829 #include <linux/gfp.h>
71830 +#include <linux/hugetlb.h>
71832 #include "internal.h"
71834 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
71836 __page_cache_release(page);
71837 dtor = get_compound_page_dtor(page);
71838 + if (!PageHuge(page))
71839 + BUG_ON(dtor != free_compound_page);
71843 diff --git a/mm/swapfile.c b/mm/swapfile.c
71844 index b1cd120..aaae885 100644
71845 --- a/mm/swapfile.c
71846 +++ b/mm/swapfile.c
71847 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
71849 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
71850 /* Activity counter to indicate that a swapon or swapoff has occurred */
71851 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
71852 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
71854 static inline unsigned char swap_count(unsigned char ent)
71856 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
71858 filp_close(swap_file, NULL);
71860 - atomic_inc(&proc_poll_event);
71861 + atomic_inc_unchecked(&proc_poll_event);
71862 wake_up_interruptible(&proc_poll_wait);
71865 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
71867 poll_wait(file, &proc_poll_wait, wait);
71869 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
71870 - seq->poll_event = atomic_read(&proc_poll_event);
71871 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
71872 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71873 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
71876 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
71879 seq = file->private_data;
71880 - seq->poll_event = atomic_read(&proc_poll_event);
71881 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71885 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
71886 (p->flags & SWP_DISCARDABLE) ? "D" : "");
71888 mutex_unlock(&swapon_mutex);
71889 - atomic_inc(&proc_poll_event);
71890 + atomic_inc_unchecked(&proc_poll_event);
71891 wake_up_interruptible(&proc_poll_wait);
71893 if (S_ISREG(inode->i_mode))
71894 diff --git a/mm/util.c b/mm/util.c
71895 index 136ac4f..5117eef 100644
71898 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
71899 * allocated buffer. Use this if you don't want to free the buffer immediately
71900 * like, for example, with RCU.
71903 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
71906 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
71907 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
71908 * %NULL pointer, the object pointed to is freed.
71911 void *krealloc(const void *p, size_t new_size, gfp_t flags)
71914 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
71915 void arch_pick_mmap_layout(struct mm_struct *mm)
71917 mm->mmap_base = TASK_UNMAPPED_BASE;
71919 +#ifdef CONFIG_PAX_RANDMMAP
71920 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71921 + mm->mmap_base += mm->delta_mmap;
71924 mm->get_unmapped_area = arch_get_unmapped_area;
71925 mm->unmap_area = arch_unmap_area;
71927 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
71928 index 27be2f0..0aef2c2 100644
71931 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
71933 pte = pte_offset_kernel(pmd, addr);
71935 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71936 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71938 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71939 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
71940 + BUG_ON(!pte_exec(*pte));
71941 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
71947 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71948 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71950 } while (pte++, addr += PAGE_SIZE, addr != end);
71953 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71954 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
71957 + int ret = -ENOMEM;
71960 * nr is a running index into the array which helps higher level
71961 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71962 pte = pte_alloc_kernel(pmd, addr);
71966 + pax_open_kernel();
71968 struct page *page = pages[*nr];
71970 - if (WARN_ON(!pte_none(*pte)))
71972 - if (WARN_ON(!page))
71974 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71975 + if (pgprot_val(prot) & _PAGE_NX)
71978 + if (WARN_ON(!pte_none(*pte))) {
71982 + if (WARN_ON(!page)) {
71986 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
71988 } while (pte++, addr += PAGE_SIZE, addr != end);
71992 + pax_close_kernel();
71996 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
71997 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
71998 * and fall back on vmalloc() if that fails. Others
71999 * just put it in the vmalloc space.
72001 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
72002 +#ifdef CONFIG_MODULES
72003 +#ifdef MODULES_VADDR
72004 unsigned long addr = (unsigned long)x;
72005 if (addr >= MODULES_VADDR && addr < MODULES_END)
72009 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
72010 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
72016 return is_vmalloc_addr(x);
72019 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
72021 if (!pgd_none(*pgd)) {
72022 pud_t *pud = pud_offset(pgd, addr);
72024 + if (!pud_large(*pud))
72026 if (!pud_none(*pud)) {
72027 pmd_t *pmd = pmd_offset(pud, addr);
72029 + if (!pmd_large(*pmd))
72031 if (!pmd_none(*pmd)) {
72034 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
72035 struct vm_struct *area;
72037 BUG_ON(in_interrupt());
72039 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72040 + if (flags & VM_KERNEXEC) {
72041 + if (start != VMALLOC_START || end != VMALLOC_END)
72043 + start = (unsigned long)MODULES_EXEC_VADDR;
72044 + end = (unsigned long)MODULES_EXEC_END;
72048 if (flags & VM_IOREMAP) {
72049 int bit = fls(size);
72051 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
72052 if (count > totalram_pages)
72055 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72056 + if (!(pgprot_val(prot) & _PAGE_NX))
72057 + flags |= VM_KERNEXEC;
72060 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
72061 __builtin_return_address(0));
72063 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
72064 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
72067 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72068 + if (!(pgprot_val(prot) & _PAGE_NX))
72069 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
72070 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
72074 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
72075 start, end, node, gfp_mask, caller);
72077 @@ -1679,6 +1741,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
72078 gfp_mask, prot, node, caller);
72082 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
72084 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
72085 @@ -1702,6 +1765,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
72086 * For tight control over page level allocator and protection flags
72087 * use __vmalloc() instead.
72090 void *vmalloc(unsigned long size)
72092 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
72093 @@ -1718,6 +1782,7 @@ EXPORT_SYMBOL(vmalloc);
72094 * For tight control over page level allocator and protection flags
72095 * use __vmalloc() instead.
72098 void *vzalloc(unsigned long size)
72100 return __vmalloc_node_flags(size, -1,
72101 @@ -1732,6 +1797,7 @@ EXPORT_SYMBOL(vzalloc);
72102 * The resulting memory area is zeroed so it can be mapped to userspace
72103 * without leaking data.
72105 +#undef vmalloc_user
72106 void *vmalloc_user(unsigned long size)
72108 struct vm_struct *area;
72109 @@ -1759,6 +1825,7 @@ EXPORT_SYMBOL(vmalloc_user);
72110 * For tight control over page level allocator and protection flags
72111 * use __vmalloc() instead.
72113 +#undef vmalloc_node
72114 void *vmalloc_node(unsigned long size, int node)
72116 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
72117 @@ -1778,6 +1845,7 @@ EXPORT_SYMBOL(vmalloc_node);
72118 * For tight control over page level allocator and protection flags
72119 * use __vmalloc_node() instead.
72121 +#undef vzalloc_node
72122 void *vzalloc_node(unsigned long size, int node)
72124 return __vmalloc_node_flags(size, node,
72125 @@ -1800,10 +1868,10 @@ EXPORT_SYMBOL(vzalloc_node);
72126 * For tight control over page level allocator and protection flags
72127 * use __vmalloc() instead.
72130 +#undef vmalloc_exec
72131 void *vmalloc_exec(unsigned long size)
72133 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
72134 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
72135 -1, __builtin_return_address(0));
72138 @@ -1822,6 +1890,7 @@ void *vmalloc_exec(unsigned long size)
72139 * Allocate enough 32bit PA addressable pages to cover @size from the
72140 * page level allocator and map them into contiguous kernel virtual space.
72143 void *vmalloc_32(unsigned long size)
72145 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
72146 @@ -1836,6 +1905,7 @@ EXPORT_SYMBOL(vmalloc_32);
72147 * The resulting memory area is 32bit addressable and zeroed so it can be
72148 * mapped to userspace without leaking data.
72150 +#undef vmalloc_32_user
72151 void *vmalloc_32_user(unsigned long size)
72153 struct vm_struct *area;
72154 @@ -2098,6 +2168,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
72155 unsigned long uaddr = vma->vm_start;
72156 unsigned long usize = vma->vm_end - vma->vm_start;
72158 + BUG_ON(vma->vm_mirror);
72160 if ((PAGE_SIZE-1) & (unsigned long)addr)
72163 diff --git a/mm/vmstat.c b/mm/vmstat.c
72164 index 8fd603b..cf0d930 100644
72167 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
72169 * vm_stat contains the global counters
72171 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
72172 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
72173 EXPORT_SYMBOL(vm_stat);
72176 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
72177 v = p->vm_stat_diff[i];
72178 p->vm_stat_diff[i] = 0;
72179 local_irq_restore(flags);
72180 - atomic_long_add(v, &zone->vm_stat[i]);
72181 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
72182 global_diff[i] += v;
72184 /* 3 seconds idle till flush */
72185 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
72187 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
72188 if (global_diff[i])
72189 - atomic_long_add(global_diff[i], &vm_stat[i]);
72190 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
72194 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
72195 start_cpu_timer(cpu);
72197 #ifdef CONFIG_PROC_FS
72198 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
72199 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
72200 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
72201 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
72203 + mode_t gr_mode = S_IRUGO;
72204 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72205 + gr_mode = S_IRUSR;
72207 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
72208 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
72209 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72210 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
72212 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
72214 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
72219 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
72220 index 5471628..cef8398 100644
72221 --- a/net/8021q/vlan.c
72222 +++ b/net/8021q/vlan.c
72223 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
72225 if (!capable(CAP_NET_ADMIN))
72227 - if ((args.u.name_type >= 0) &&
72228 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
72229 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
72230 struct vlan_net *vn;
72232 vn = net_generic(net, vlan_net_id);
72233 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
72234 index fdfdb57..38d368c 100644
72235 --- a/net/9p/trans_fd.c
72236 +++ b/net/9p/trans_fd.c
72237 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
72240 /* The cast to a user pointer is valid due to the set_fs() */
72241 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
72242 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
72245 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
72246 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
72247 index f41f026..fe76ea8 100644
72248 --- a/net/atm/atm_misc.c
72249 +++ b/net/atm/atm_misc.c
72250 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
72251 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
72253 atm_return(vcc, truesize);
72254 - atomic_inc(&vcc->stats->rx_drop);
72255 + atomic_inc_unchecked(&vcc->stats->rx_drop);
72258 EXPORT_SYMBOL(atm_charge);
72259 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
72262 atm_return(vcc, guess);
72263 - atomic_inc(&vcc->stats->rx_drop);
72264 + atomic_inc_unchecked(&vcc->stats->rx_drop);
72267 EXPORT_SYMBOL(atm_alloc_charge);
72268 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
72270 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
72272 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
72273 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
72275 #undef __HANDLE_ITEM
72277 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
72279 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
72281 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
72282 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
72284 #undef __HANDLE_ITEM
72286 diff --git a/net/atm/lec.h b/net/atm/lec.h
72287 index dfc0719..47c5322 100644
72288 --- a/net/atm/lec.h
72289 +++ b/net/atm/lec.h
72290 @@ -48,7 +48,7 @@ struct lane2_ops {
72291 const u8 *tlvs, u32 sizeoftlvs);
72292 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
72293 const u8 *tlvs, u32 sizeoftlvs);
72298 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
72299 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
72300 index 0919a88..a23d54e 100644
72301 --- a/net/atm/mpc.h
72302 +++ b/net/atm/mpc.h
72303 @@ -33,7 +33,7 @@ struct mpoa_client {
72304 struct mpc_parameters parameters; /* parameters for this client */
72306 const struct net_device_ops *old_ops;
72307 - struct net_device_ops new_ops;
72308 + net_device_ops_no_const new_ops;
72312 diff --git a/net/atm/proc.c b/net/atm/proc.c
72313 index 0d020de..011c7bb 100644
72314 --- a/net/atm/proc.c
72315 +++ b/net/atm/proc.c
72316 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
72317 const struct k_atm_aal_stats *stats)
72319 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
72320 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
72321 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
72322 - atomic_read(&stats->rx_drop));
72323 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
72324 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
72325 + atomic_read_unchecked(&stats->rx_drop));
72328 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
72329 diff --git a/net/atm/resources.c b/net/atm/resources.c
72330 index 23f45ce..c748f1a 100644
72331 --- a/net/atm/resources.c
72332 +++ b/net/atm/resources.c
72333 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
72334 static void copy_aal_stats(struct k_atm_aal_stats *from,
72335 struct atm_aal_stats *to)
72337 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
72338 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
72340 #undef __HANDLE_ITEM
72342 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
72343 static void subtract_aal_stats(struct k_atm_aal_stats *from,
72344 struct atm_aal_stats *to)
72346 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
72347 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
72349 #undef __HANDLE_ITEM
72351 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
72352 index 3512e25..2b33401 100644
72353 --- a/net/batman-adv/bat_iv_ogm.c
72354 +++ b/net/batman-adv/bat_iv_ogm.c
72355 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
72357 /* change sequence number to network order */
72358 batman_ogm_packet->seqno =
72359 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
72360 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
72362 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
72363 batman_ogm_packet->tt_crc = htons((uint16_t)
72364 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
72366 batman_ogm_packet->gw_flags = NO_FLAGS;
72368 - atomic_inc(&hard_iface->seqno);
72369 + atomic_inc_unchecked(&hard_iface->seqno);
72371 slide_own_bcast_window(hard_iface);
72372 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
72373 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
72376 /* could be changed by schedule_own_packet() */
72377 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
72378 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
72380 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
72382 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
72383 index 7704df4..beb4e16 100644
72384 --- a/net/batman-adv/hard-interface.c
72385 +++ b/net/batman-adv/hard-interface.c
72386 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
72387 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
72388 dev_add_pack(&hard_iface->batman_adv_ptype);
72390 - atomic_set(&hard_iface->seqno, 1);
72391 - atomic_set(&hard_iface->frag_seqno, 1);
72392 + atomic_set_unchecked(&hard_iface->seqno, 1);
72393 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
72394 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
72395 hard_iface->net_dev->name);
72397 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
72398 index f9cc957..efd9dae 100644
72399 --- a/net/batman-adv/soft-interface.c
72400 +++ b/net/batman-adv/soft-interface.c
72401 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
72403 /* set broadcast sequence number */
72404 bcast_packet->seqno =
72405 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
72406 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
72408 add_bcast_packet_to_list(bat_priv, skb, 1);
72410 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
72411 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
72413 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
72414 - atomic_set(&bat_priv->bcast_seqno, 1);
72415 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
72416 atomic_set(&bat_priv->ttvn, 0);
72417 atomic_set(&bat_priv->tt_local_changes, 0);
72418 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
72419 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
72420 index ab8d0fe..ceba3fd 100644
72421 --- a/net/batman-adv/types.h
72422 +++ b/net/batman-adv/types.h
72423 @@ -38,8 +38,8 @@ struct hard_iface {
72426 struct net_device *net_dev;
72428 - atomic_t frag_seqno;
72429 + atomic_unchecked_t seqno;
72430 + atomic_unchecked_t frag_seqno;
72431 unsigned char *packet_buff;
72433 struct kobject *hardif_obj;
72434 @@ -154,7 +154,7 @@ struct bat_priv {
72435 atomic_t orig_interval; /* uint */
72436 atomic_t hop_penalty; /* uint */
72437 atomic_t log_level; /* uint */
72438 - atomic_t bcast_seqno;
72439 + atomic_unchecked_t bcast_seqno;
72440 atomic_t bcast_queue_left;
72441 atomic_t batman_queue_left;
72442 atomic_t ttvn; /* translation table version number */
72443 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
72444 index 07d1c1d..7e9bea9 100644
72445 --- a/net/batman-adv/unicast.c
72446 +++ b/net/batman-adv/unicast.c
72447 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
72448 frag1->flags = UNI_FRAG_HEAD | large_tail;
72449 frag2->flags = large_tail;
72451 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
72452 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
72453 frag1->seqno = htons(seqno - 1);
72454 frag2->seqno = htons(seqno);
72456 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
72457 index c1c597e..05ebb40 100644
72458 --- a/net/bluetooth/hci_conn.c
72459 +++ b/net/bluetooth/hci_conn.c
72460 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
72461 memset(&cp, 0, sizeof(cp));
72463 cp.handle = cpu_to_le16(conn->handle);
72464 - memcpy(cp.ltk, ltk, sizeof(ltk));
72465 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
72467 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
72469 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
72470 index 17b5b1c..826d872 100644
72471 --- a/net/bluetooth/l2cap_core.c
72472 +++ b/net/bluetooth/l2cap_core.c
72473 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
72476 case L2CAP_CONF_RFC:
72477 - if (olen == sizeof(rfc))
72478 - memcpy(&rfc, (void *)val, olen);
72479 + if (olen != sizeof(rfc))
72482 + memcpy(&rfc, (void *)val, olen);
72484 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
72485 rfc.mode != chan->mode)
72486 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
72489 case L2CAP_CONF_RFC:
72490 - if (olen == sizeof(rfc))
72491 - memcpy(&rfc, (void *)val, olen);
72492 + if (olen != sizeof(rfc))
72495 + memcpy(&rfc, (void *)val, olen);
72499 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
72500 index a5f4e57..910ee6d 100644
72501 --- a/net/bridge/br_multicast.c
72502 +++ b/net/bridge/br_multicast.c
72503 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
72504 nexthdr = ip6h->nexthdr;
72505 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
72507 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
72508 + if (nexthdr != IPPROTO_ICMPV6)
72511 /* Okay, we found ICMPv6 header */
72512 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
72513 index 5864cc4..121f3a3 100644
72514 --- a/net/bridge/netfilter/ebtables.c
72515 +++ b/net/bridge/netfilter/ebtables.c
72516 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
72517 tmp.valid_hooks = t->table->valid_hooks;
72519 mutex_unlock(&ebt_mutex);
72520 - if (copy_to_user(user, &tmp, *len) != 0){
72521 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
72522 BUGPRINT("c2u Didn't work\n");
72525 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
72526 index a986280..13444a1 100644
72527 --- a/net/caif/caif_socket.c
72528 +++ b/net/caif/caif_socket.c
72529 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
72530 #ifdef CONFIG_DEBUG_FS
72531 struct debug_fs_counter {
72532 atomic_t caif_nr_socks;
72533 - atomic_t caif_sock_create;
72534 - atomic_t num_connect_req;
72535 - atomic_t num_connect_resp;
72536 - atomic_t num_connect_fail_resp;
72537 - atomic_t num_disconnect;
72538 - atomic_t num_remote_shutdown_ind;
72539 - atomic_t num_tx_flow_off_ind;
72540 - atomic_t num_tx_flow_on_ind;
72541 - atomic_t num_rx_flow_off;
72542 - atomic_t num_rx_flow_on;
72543 + atomic_unchecked_t caif_sock_create;
72544 + atomic_unchecked_t num_connect_req;
72545 + atomic_unchecked_t num_connect_resp;
72546 + atomic_unchecked_t num_connect_fail_resp;
72547 + atomic_unchecked_t num_disconnect;
72548 + atomic_unchecked_t num_remote_shutdown_ind;
72549 + atomic_unchecked_t num_tx_flow_off_ind;
72550 + atomic_unchecked_t num_tx_flow_on_ind;
72551 + atomic_unchecked_t num_rx_flow_off;
72552 + atomic_unchecked_t num_rx_flow_on;
72554 static struct debug_fs_counter cnt;
72555 #define dbfs_atomic_inc(v) atomic_inc_return(v)
72556 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
72557 #define dbfs_atomic_dec(v) atomic_dec_return(v)
72559 #define dbfs_atomic_inc(v) 0
72560 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72561 atomic_read(&cf_sk->sk.sk_rmem_alloc),
72562 sk_rcvbuf_lowwater(cf_sk));
72563 set_rx_flow_off(cf_sk);
72564 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72565 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72566 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72569 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72570 set_rx_flow_off(cf_sk);
72571 if (net_ratelimit())
72572 pr_debug("sending flow OFF due to rmem_schedule\n");
72573 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72574 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72575 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72578 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
72580 case CAIF_CTRLCMD_FLOW_ON_IND:
72581 /* OK from modem to start sending again */
72582 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
72583 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
72584 set_tx_flow_on(cf_sk);
72585 cf_sk->sk.sk_state_change(&cf_sk->sk);
72588 case CAIF_CTRLCMD_FLOW_OFF_IND:
72589 /* Modem asks us to shut up */
72590 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
72591 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
72592 set_tx_flow_off(cf_sk);
72593 cf_sk->sk.sk_state_change(&cf_sk->sk);
72595 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72596 /* We're now connected */
72597 caif_client_register_refcnt(&cf_sk->layer,
72598 cfsk_hold, cfsk_put);
72599 - dbfs_atomic_inc(&cnt.num_connect_resp);
72600 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
72601 cf_sk->sk.sk_state = CAIF_CONNECTED;
72602 set_tx_flow_on(cf_sk);
72603 cf_sk->sk.sk_state_change(&cf_sk->sk);
72604 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72606 case CAIF_CTRLCMD_INIT_FAIL_RSP:
72607 /* Connect request failed */
72608 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
72609 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
72610 cf_sk->sk.sk_err = ECONNREFUSED;
72611 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
72612 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72613 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72615 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
72616 /* Modem has closed this connection, or device is down. */
72617 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
72618 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
72619 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72620 cf_sk->sk.sk_err = ECONNRESET;
72621 set_rx_flow_on(cf_sk);
72622 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
72625 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
72626 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
72627 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
72628 set_rx_flow_on(cf_sk);
72629 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
72631 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
72632 /*ifindex = id of the interface.*/
72633 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
72635 - dbfs_atomic_inc(&cnt.num_connect_req);
72636 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
72637 cf_sk->layer.receive = caif_sktrecv_cb;
72639 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
72640 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
72641 spin_unlock_bh(&sk->sk_receive_queue.lock);
72644 - dbfs_atomic_inc(&cnt.num_disconnect);
72645 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
72647 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
72648 if (cf_sk->debugfs_socket_dir != NULL)
72649 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
72650 cf_sk->conn_req.protocol = protocol;
72651 /* Increase the number of sockets created. */
72652 dbfs_atomic_inc(&cnt.caif_nr_socks);
72653 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
72654 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
72655 #ifdef CONFIG_DEBUG_FS
72656 if (!IS_ERR(debugfsdir)) {
72658 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
72659 index 5cf5222..6f704ad 100644
72660 --- a/net/caif/cfctrl.c
72661 +++ b/net/caif/cfctrl.c
72663 #include <linux/stddef.h>
72664 #include <linux/spinlock.h>
72665 #include <linux/slab.h>
72666 +#include <linux/sched.h>
72667 #include <net/caif/caif_layer.h>
72668 #include <net/caif/cfpkt.h>
72669 #include <net/caif/cfctrl.h>
72670 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
72671 memset(&dev_info, 0, sizeof(dev_info));
72672 dev_info.id = 0xff;
72673 cfsrvl_init(&this->serv, 0, &dev_info, false);
72674 - atomic_set(&this->req_seq_no, 1);
72675 - atomic_set(&this->rsp_seq_no, 1);
72676 + atomic_set_unchecked(&this->req_seq_no, 1);
72677 + atomic_set_unchecked(&this->rsp_seq_no, 1);
72678 this->serv.layer.receive = cfctrl_recv;
72679 sprintf(this->serv.layer.name, "ctrl");
72680 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
72681 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
72682 struct cfctrl_request_info *req)
72684 spin_lock_bh(&ctrl->info_list_lock);
72685 - atomic_inc(&ctrl->req_seq_no);
72686 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
72687 + atomic_inc_unchecked(&ctrl->req_seq_no);
72688 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
72689 list_add_tail(&req->list, &ctrl->list);
72690 spin_unlock_bh(&ctrl->info_list_lock);
72692 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
72694 pr_warn("Requests are not received in order\n");
72696 - atomic_set(&ctrl->rsp_seq_no,
72697 + atomic_set_unchecked(&ctrl->rsp_seq_no,
72699 list_del(&p->list);
72701 diff --git a/net/can/gw.c b/net/can/gw.c
72702 index 3d79b12..8de85fa 100644
72705 @@ -96,7 +96,7 @@ struct cf_mod {
72707 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
72708 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
72710 + } __no_const csumfunc;
72714 diff --git a/net/compat.c b/net/compat.c
72715 index 6def90e..c6992fa 100644
72718 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
72719 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
72720 __get_user(kmsg->msg_flags, &umsg->msg_flags))
72722 - kmsg->msg_name = compat_ptr(tmp1);
72723 - kmsg->msg_iov = compat_ptr(tmp2);
72724 - kmsg->msg_control = compat_ptr(tmp3);
72725 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
72726 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
72727 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
72731 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72733 if (kern_msg->msg_namelen) {
72734 if (mode == VERIFY_READ) {
72735 - int err = move_addr_to_kernel(kern_msg->msg_name,
72736 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
72737 kern_msg->msg_namelen,
72740 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72741 kern_msg->msg_name = NULL;
72743 tot_len = iov_from_user_compat_to_kern(kern_iov,
72744 - (struct compat_iovec __user *)kern_msg->msg_iov,
72745 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
72746 kern_msg->msg_iovlen);
72748 kern_msg->msg_iov = kern_iov;
72749 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72751 #define CMSG_COMPAT_FIRSTHDR(msg) \
72752 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
72753 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
72754 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
72755 (struct compat_cmsghdr __user *)NULL)
72757 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
72758 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
72759 (ucmlen) <= (unsigned long) \
72760 ((mhdr)->msg_controllen - \
72761 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
72762 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
72764 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
72765 struct compat_cmsghdr __user *cmsg, int cmsg_len)
72767 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
72768 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
72769 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
72770 msg->msg_controllen)
72772 return (struct compat_cmsghdr __user *)ptr;
72773 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72775 struct compat_timeval ctv;
72776 struct compat_timespec cts[3];
72777 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72778 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72779 struct compat_cmsghdr cmhdr;
72782 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72784 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
72786 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72787 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72788 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
72789 int fdnum = scm->fp->count;
72790 struct file **fp = scm->fp->fp;
72791 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
72795 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
72796 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
72800 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
72801 len = sizeof(ktime);
72804 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
72805 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
72809 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72810 case MCAST_JOIN_GROUP:
72811 case MCAST_LEAVE_GROUP:
72813 - struct compat_group_req __user *gr32 = (void *)optval;
72814 + struct compat_group_req __user *gr32 = (void __user *)optval;
72815 struct group_req __user *kgr =
72816 compat_alloc_user_space(sizeof(struct group_req));
72818 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72819 case MCAST_BLOCK_SOURCE:
72820 case MCAST_UNBLOCK_SOURCE:
72822 - struct compat_group_source_req __user *gsr32 = (void *)optval;
72823 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
72824 struct group_source_req __user *kgsr = compat_alloc_user_space(
72825 sizeof(struct group_source_req));
72827 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72829 case MCAST_MSFILTER:
72831 - struct compat_group_filter __user *gf32 = (void *)optval;
72832 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72833 struct group_filter __user *kgf;
72834 u32 interface, fmode, numsrc;
72836 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
72837 char __user *optval, int __user *optlen,
72838 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
72840 - struct compat_group_filter __user *gf32 = (void *)optval;
72841 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72842 struct group_filter __user *kgf;
72843 int __user *koptlen;
72844 u32 interface, fmode, numsrc;
72845 diff --git a/net/core/datagram.c b/net/core/datagram.c
72846 index 68bbf9f..5ef0d12 100644
72847 --- a/net/core/datagram.c
72848 +++ b/net/core/datagram.c
72849 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
72853 - atomic_inc(&sk->sk_drops);
72854 + atomic_inc_unchecked(&sk->sk_drops);
72855 sk_mem_reclaim_partial(sk);
72858 diff --git a/net/core/dev.c b/net/core/dev.c
72859 index c56cacf..b28e35f 100644
72860 --- a/net/core/dev.c
72861 +++ b/net/core/dev.c
72862 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
72863 if (no_module && capable(CAP_NET_ADMIN))
72864 no_module = request_module("netdev-%s", name);
72865 if (no_module && capable(CAP_SYS_MODULE)) {
72866 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
72867 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
72869 if (!request_module("%s", name))
72870 pr_err("Loading kernel module for a network device "
72871 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
72872 "instead\n", name);
72876 EXPORT_SYMBOL(dev_load);
72877 @@ -1573,7 +1577,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
72879 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
72880 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
72881 - atomic_long_inc(&dev->rx_dropped);
72882 + atomic_long_inc_unchecked(&dev->rx_dropped);
72884 return NET_RX_DROP;
72886 @@ -1583,7 +1587,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
72889 if (unlikely(!is_skb_forwardable(dev, skb))) {
72890 - atomic_long_inc(&dev->rx_dropped);
72891 + atomic_long_inc_unchecked(&dev->rx_dropped);
72893 return NET_RX_DROP;
72895 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
72897 struct dev_gso_cb {
72898 void (*destructor)(struct sk_buff *skb);
72902 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
72904 @@ -2970,7 +2974,7 @@ enqueue:
72906 local_irq_restore(flags);
72908 - atomic_long_inc(&skb->dev->rx_dropped);
72909 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
72911 return NET_RX_DROP;
72913 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
72915 EXPORT_SYMBOL(netif_rx_ni);
72917 -static void net_tx_action(struct softirq_action *h)
72918 +static void net_tx_action(void)
72920 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72922 @@ -3333,7 +3337,7 @@ ncls:
72924 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
72926 - atomic_long_inc(&skb->dev->rx_dropped);
72927 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
72929 /* Jamal, now you will not able to escape explaining
72930 * me how you were going to use this. :-)
72931 @@ -3897,7 +3901,7 @@ void netif_napi_del(struct napi_struct *napi)
72933 EXPORT_SYMBOL(netif_napi_del);
72935 -static void net_rx_action(struct softirq_action *h)
72936 +static void net_rx_action(void)
72938 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72939 unsigned long time_limit = jiffies + 2;
72940 @@ -5955,7 +5959,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
72942 netdev_stats_to_stats64(storage, &dev->stats);
72944 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
72945 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
72948 EXPORT_SYMBOL(dev_get_stats);
72949 diff --git a/net/core/flow.c b/net/core/flow.c
72950 index e318c7e..168b1d0 100644
72951 --- a/net/core/flow.c
72952 +++ b/net/core/flow.c
72953 @@ -61,7 +61,7 @@ struct flow_cache {
72954 struct timer_list rnd_timer;
72957 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
72958 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
72959 EXPORT_SYMBOL(flow_cache_genid);
72960 static struct flow_cache flow_cache_global;
72961 static struct kmem_cache *flow_cachep __read_mostly;
72962 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
72964 static int flow_entry_valid(struct flow_cache_entry *fle)
72966 - if (atomic_read(&flow_cache_genid) != fle->genid)
72967 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
72969 if (fle->object && !fle->object->ops->check(fle->object))
72971 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
72972 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
72975 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
72976 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
72980 @@ -280,7 +280,7 @@ nocache:
72982 flo = resolver(net, key, family, dir, flo, ctx);
72984 - fle->genid = atomic_read(&flow_cache_genid);
72985 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
72989 diff --git a/net/core/iovec.c b/net/core/iovec.c
72990 index c40f27e..7f49254 100644
72991 --- a/net/core/iovec.c
72992 +++ b/net/core/iovec.c
72993 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72994 if (m->msg_namelen) {
72995 if (mode == VERIFY_READ) {
72996 void __user *namep;
72997 - namep = (void __user __force *) m->msg_name;
72998 + namep = (void __force_user *) m->msg_name;
72999 err = move_addr_to_kernel(namep, m->msg_namelen,
73002 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
73005 size = m->msg_iovlen * sizeof(struct iovec);
73006 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
73007 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
73011 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
73012 index 9083e82..1673203 100644
73013 --- a/net/core/rtnetlink.c
73014 +++ b/net/core/rtnetlink.c
73015 @@ -57,7 +57,7 @@ struct rtnl_link {
73016 rtnl_doit_func doit;
73017 rtnl_dumpit_func dumpit;
73018 rtnl_calcit_func calcit;
73022 static DEFINE_MUTEX(rtnl_mutex);
73023 static u16 min_ifinfo_dump_size;
73024 diff --git a/net/core/scm.c b/net/core/scm.c
73025 index ff52ad0..aff1c0f 100644
73026 --- a/net/core/scm.c
73027 +++ b/net/core/scm.c
73028 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
73029 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
73031 struct cmsghdr __user *cm
73032 - = (__force struct cmsghdr __user *)msg->msg_control;
73033 + = (struct cmsghdr __force_user *)msg->msg_control;
73034 struct cmsghdr cmhdr;
73035 int cmlen = CMSG_LEN(len);
73037 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
73039 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
73041 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
73042 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
73044 cmlen = CMSG_SPACE(len);
73045 if (msg->msg_controllen < cmlen)
73046 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
73047 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
73049 struct cmsghdr __user *cm
73050 - = (__force struct cmsghdr __user*)msg->msg_control;
73051 + = (struct cmsghdr __force_user *)msg->msg_control;
73054 int fdnum = scm->fp->count;
73055 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
73059 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
73060 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
73064 diff --git a/net/core/sock.c b/net/core/sock.c
73065 index b23f174..b9a0d26 100644
73066 --- a/net/core/sock.c
73067 +++ b/net/core/sock.c
73068 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73069 struct sk_buff_head *list = &sk->sk_receive_queue;
73071 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
73072 - atomic_inc(&sk->sk_drops);
73073 + atomic_inc_unchecked(&sk->sk_drops);
73074 trace_sock_rcvqueue_full(sk, skb);
73077 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73080 if (!sk_rmem_schedule(sk, skb->truesize)) {
73081 - atomic_inc(&sk->sk_drops);
73082 + atomic_inc_unchecked(&sk->sk_drops);
73086 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73087 skb_dst_force(skb);
73089 spin_lock_irqsave(&list->lock, flags);
73090 - skb->dropcount = atomic_read(&sk->sk_drops);
73091 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
73092 __skb_queue_tail(list, skb);
73093 spin_unlock_irqrestore(&list->lock, flags);
73095 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
73098 if (sk_rcvqueues_full(sk, skb)) {
73099 - atomic_inc(&sk->sk_drops);
73100 + atomic_inc_unchecked(&sk->sk_drops);
73101 goto discard_and_relse;
73104 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
73105 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
73106 } else if (sk_add_backlog(sk, skb)) {
73107 bh_unlock_sock(sk);
73108 - atomic_inc(&sk->sk_drops);
73109 + atomic_inc_unchecked(&sk->sk_drops);
73110 goto discard_and_relse;
73113 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
73114 if (len > sizeof(peercred))
73115 len = sizeof(peercred);
73116 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
73117 - if (copy_to_user(optval, &peercred, len))
73118 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
73122 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
73126 - if (copy_to_user(optval, address, len))
73127 + if (len > sizeof(address) || copy_to_user(optval, address, len))
73131 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
73135 - if (copy_to_user(optval, &v, len))
73136 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
73139 if (put_user(len, optlen))
73140 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
73143 atomic_set(&sk->sk_refcnt, 1);
73144 - atomic_set(&sk->sk_drops, 0);
73145 + atomic_set_unchecked(&sk->sk_drops, 0);
73147 EXPORT_SYMBOL(sock_init_data);
73149 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
73150 index 02e75d1..9a57a7c 100644
73151 --- a/net/decnet/sysctl_net_decnet.c
73152 +++ b/net/decnet/sysctl_net_decnet.c
73153 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
73155 if (len > *lenp) len = *lenp;
73157 - if (copy_to_user(buffer, addr, len))
73158 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
73162 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
73164 if (len > *lenp) len = *lenp;
73166 - if (copy_to_user(buffer, devname, len))
73167 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
73171 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
73172 index 39a2d29..f39c0fe 100644
73173 --- a/net/econet/Kconfig
73174 +++ b/net/econet/Kconfig
73178 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
73179 - depends on EXPERIMENTAL && INET
73180 + depends on EXPERIMENTAL && INET && BROKEN
73182 Econet is a fairly old and slow networking protocol mainly used by
73183 Acorn computers to access file and print servers. It uses native
73184 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
73185 index 92fc5f6..b790d91 100644
73186 --- a/net/ipv4/fib_frontend.c
73187 +++ b/net/ipv4/fib_frontend.c
73188 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
73189 #ifdef CONFIG_IP_ROUTE_MULTIPATH
73192 - atomic_inc(&net->ipv4.dev_addr_genid);
73193 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
73194 rt_cache_flush(dev_net(dev), -1);
73197 fib_del_ifaddr(ifa, NULL);
73198 - atomic_inc(&net->ipv4.dev_addr_genid);
73199 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
73200 if (ifa->ifa_dev->ifa_list == NULL) {
73201 /* Last address was deleted from this interface.
73203 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
73204 #ifdef CONFIG_IP_ROUTE_MULTIPATH
73207 - atomic_inc(&net->ipv4.dev_addr_genid);
73208 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
73209 rt_cache_flush(dev_net(dev), -1);
73212 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
73213 index 80106d8..232e898 100644
73214 --- a/net/ipv4/fib_semantics.c
73215 +++ b/net/ipv4/fib_semantics.c
73216 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
73217 nh->nh_saddr = inet_select_addr(nh->nh_dev,
73219 nh->nh_parent->fib_scope);
73220 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
73221 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
73223 return nh->nh_saddr;
73225 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
73226 index ccee270..db23c3c 100644
73227 --- a/net/ipv4/inet_diag.c
73228 +++ b/net/ipv4/inet_diag.c
73229 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
73230 r->idiag_retrans = 0;
73232 r->id.idiag_if = sk->sk_bound_dev_if;
73234 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73235 + r->id.idiag_cookie[0] = 0;
73236 + r->id.idiag_cookie[1] = 0;
73238 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
73239 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
73242 r->id.idiag_sport = inet->inet_sport;
73243 r->id.idiag_dport = inet->inet_dport;
73244 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
73245 r->idiag_family = tw->tw_family;
73246 r->idiag_retrans = 0;
73247 r->id.idiag_if = tw->tw_bound_dev_if;
73249 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73250 + r->id.idiag_cookie[0] = 0;
73251 + r->id.idiag_cookie[1] = 0;
73253 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
73254 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
73257 r->id.idiag_sport = tw->tw_sport;
73258 r->id.idiag_dport = tw->tw_dport;
73259 r->id.idiag_src[0] = tw->tw_rcv_saddr;
73260 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
73264 +#ifndef CONFIG_GRKERNSEC_HIDESYM
73266 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
73267 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
73268 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
73269 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
73274 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
73275 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
73276 r->idiag_retrans = req->retrans;
73278 r->id.idiag_if = sk->sk_bound_dev_if;
73280 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73281 + r->id.idiag_cookie[0] = 0;
73282 + r->id.idiag_cookie[1] = 0;
73284 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
73285 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
73288 tmo = req->expires - jiffies;
73290 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
73291 index 984ec65..97ac518 100644
73292 --- a/net/ipv4/inet_hashtables.c
73293 +++ b/net/ipv4/inet_hashtables.c
73294 @@ -18,12 +18,15 @@
73295 #include <linux/sched.h>
73296 #include <linux/slab.h>
73297 #include <linux/wait.h>
73298 +#include <linux/security.h>
73300 #include <net/inet_connection_sock.h>
73301 #include <net/inet_hashtables.h>
73302 #include <net/secure_seq.h>
73303 #include <net/ip.h>
73305 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
73308 * Allocate and initialize a new local port bind bucket.
73309 * The bindhash mutex for snum's hash chain must be held here.
73310 @@ -530,6 +533,8 @@ ok:
73311 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
73312 spin_unlock(&head->lock);
73314 + gr_update_task_in_ip_table(current, inet_sk(sk));
73317 inet_twsk_deschedule(tw, death_row);
73319 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
73320 index 86f13c67..59a35b5 100644
73321 --- a/net/ipv4/inetpeer.c
73322 +++ b/net/ipv4/inetpeer.c
73323 @@ -436,8 +436,8 @@ relookup:
73326 atomic_set(&p->refcnt, 1);
73327 - atomic_set(&p->rid, 0);
73328 - atomic_set(&p->ip_id_count,
73329 + atomic_set_unchecked(&p->rid, 0);
73330 + atomic_set_unchecked(&p->ip_id_count,
73331 (daddr->family == AF_INET) ?
73332 secure_ip_id(daddr->addr.a4) :
73333 secure_ipv6_id(daddr->addr.a6));
73334 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
73335 index fdaabf2..0ec3205 100644
73336 --- a/net/ipv4/ip_fragment.c
73337 +++ b/net/ipv4/ip_fragment.c
73338 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
73342 - end = atomic_inc_return(&peer->rid);
73343 + end = atomic_inc_return_unchecked(&peer->rid);
73346 rc = qp->q.fragments && (end - start) > max;
73347 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
73348 index 09ff51b..d3968eb 100644
73349 --- a/net/ipv4/ip_sockglue.c
73350 +++ b/net/ipv4/ip_sockglue.c
73351 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
73352 len = min_t(unsigned int, len, opt->optlen);
73353 if (put_user(len, optlen))
73355 - if (copy_to_user(optval, opt->__data, len))
73356 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
73357 + copy_to_user(optval, opt->__data, len))
73361 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
73362 if (sk->sk_type != SOCK_STREAM)
73363 return -ENOPROTOOPT;
73365 - msg.msg_control = optval;
73366 + msg.msg_control = (void __force_kernel *)optval;
73367 msg.msg_controllen = len;
73368 msg.msg_flags = flags;
73370 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
73371 index 99ec116..c5628fe 100644
73372 --- a/net/ipv4/ipconfig.c
73373 +++ b/net/ipv4/ipconfig.c
73374 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
73376 mm_segment_t oldfs = get_fs();
73378 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
73379 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
73383 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
73385 mm_segment_t oldfs = get_fs();
73387 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
73388 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
73392 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
73394 mm_segment_t oldfs = get_fs();
73396 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
73397 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
73401 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
73402 index 2133c30..5c4b40b 100644
73403 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
73404 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
73405 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
73409 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
73410 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
73411 if (*octets == NULL)
73414 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
73415 index 43d4c3b..1914409 100644
73416 --- a/net/ipv4/ping.c
73417 +++ b/net/ipv4/ping.c
73418 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
73419 sk_rmem_alloc_get(sp),
73420 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73421 atomic_read(&sp->sk_refcnt), sp,
73422 - atomic_read(&sp->sk_drops), len);
73423 + atomic_read_unchecked(&sp->sk_drops), len);
73426 static int ping_seq_show(struct seq_file *seq, void *v)
73427 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
73428 index 007e2eb..85a18a0 100644
73429 --- a/net/ipv4/raw.c
73430 +++ b/net/ipv4/raw.c
73431 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
73432 int raw_rcv(struct sock *sk, struct sk_buff *skb)
73434 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
73435 - atomic_inc(&sk->sk_drops);
73436 + atomic_inc_unchecked(&sk->sk_drops);
73438 return NET_RX_DROP;
73440 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
73442 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
73444 + struct icmp_filter filter;
73446 if (optlen > sizeof(struct icmp_filter))
73447 optlen = sizeof(struct icmp_filter);
73448 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
73449 + if (copy_from_user(&filter, optval, optlen))
73451 + raw_sk(sk)->filter = filter;
73455 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
73457 int len, ret = -EFAULT;
73458 + struct icmp_filter filter;
73460 if (get_user(len, optlen))
73462 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
73463 if (len > sizeof(struct icmp_filter))
73464 len = sizeof(struct icmp_filter);
73466 - if (put_user(len, optlen) ||
73467 - copy_to_user(optval, &raw_sk(sk)->filter, len))
73468 + filter = raw_sk(sk)->filter;
73469 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
73473 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73474 sk_wmem_alloc_get(sp),
73475 sk_rmem_alloc_get(sp),
73476 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73477 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73478 + atomic_read(&sp->sk_refcnt),
73479 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73484 + atomic_read_unchecked(&sp->sk_drops));
73487 static int raw_seq_show(struct seq_file *seq, void *v)
73488 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
73489 index 94cdbc5..0cb0063 100644
73490 --- a/net/ipv4/route.c
73491 +++ b/net/ipv4/route.c
73492 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
73494 static inline int rt_genid(struct net *net)
73496 - return atomic_read(&net->ipv4.rt_genid);
73497 + return atomic_read_unchecked(&net->ipv4.rt_genid);
73500 #ifdef CONFIG_PROC_FS
73501 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
73502 unsigned char shuffle;
73504 get_random_bytes(&shuffle, sizeof(shuffle));
73505 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
73506 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
73510 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
73511 error = rt->dst.error;
73513 inet_peer_refcheck(rt->peer);
73514 - id = atomic_read(&peer->ip_id_count) & 0xffff;
73515 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
73516 if (peer->tcp_ts_stamp) {
73518 tsage = get_seconds() - peer->tcp_ts_stamp;
73519 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
73520 index eb90aa8..22bf114 100644
73521 --- a/net/ipv4/tcp_ipv4.c
73522 +++ b/net/ipv4/tcp_ipv4.c
73523 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
73524 int sysctl_tcp_low_latency __read_mostly;
73525 EXPORT_SYMBOL(sysctl_tcp_low_latency);
73527 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73528 +extern int grsec_enable_blackhole;
73531 #ifdef CONFIG_TCP_MD5SIG
73532 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
73533 @@ -1632,6 +1635,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
73537 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73538 + if (!grsec_enable_blackhole)
73540 tcp_v4_send_reset(rsk, skb);
73543 @@ -1694,12 +1700,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
73544 TCP_SKB_CB(skb)->sacked = 0;
73546 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73549 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73552 goto no_tcp_socket;
73556 - if (sk->sk_state == TCP_TIME_WAIT)
73557 + if (sk->sk_state == TCP_TIME_WAIT) {
73558 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73564 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
73565 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73566 @@ -1749,6 +1762,10 @@ no_tcp_socket:
73568 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73570 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73571 + if (!grsec_enable_blackhole || (ret == 1 &&
73572 + (skb->dev->flags & IFF_LOOPBACK)))
73574 tcp_v4_send_reset(NULL, skb);
73577 @@ -2409,7 +2426,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
73578 0, /* non standard timer */
73579 0, /* open_requests have no inode */
73580 atomic_read(&sk->sk_refcnt),
73581 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73589 @@ -2459,7 +2480,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
73591 icsk->icsk_probes_out,
73593 - atomic_read(&sk->sk_refcnt), sk,
73594 + atomic_read(&sk->sk_refcnt),
73595 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73600 jiffies_to_clock_t(icsk->icsk_rto),
73601 jiffies_to_clock_t(icsk->icsk_ack.ato),
73602 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
73603 @@ -2487,7 +2513,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
73604 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
73605 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
73606 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73607 - atomic_read(&tw->tw_refcnt), tw, len);
73608 + atomic_read(&tw->tw_refcnt),
73609 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73618 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
73619 index 66363b6..b0654a3 100644
73620 --- a/net/ipv4/tcp_minisocks.c
73621 +++ b/net/ipv4/tcp_minisocks.c
73623 #include <net/inet_common.h>
73624 #include <net/xfrm.h>
73626 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73627 +extern int grsec_enable_blackhole;
73630 int sysctl_tcp_syncookies __read_mostly = 1;
73631 EXPORT_SYMBOL(sysctl_tcp_syncookies);
73633 @@ -751,6 +755,10 @@ listen_overflow:
73636 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
73638 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73639 + if (!grsec_enable_blackhole)
73641 if (!(flg & TCP_FLAG_RST))
73642 req->rsk_ops->send_reset(sk, skb);
73644 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
73645 index 85ee7eb..53277ab 100644
73646 --- a/net/ipv4/tcp_probe.c
73647 +++ b/net/ipv4/tcp_probe.c
73648 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
73649 if (cnt + width >= len)
73652 - if (copy_to_user(buf + cnt, tbuf, width))
73653 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
73657 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
73658 index 2e0f0af..e2948bf 100644
73659 --- a/net/ipv4/tcp_timer.c
73660 +++ b/net/ipv4/tcp_timer.c
73662 #include <linux/gfp.h>
73663 #include <net/tcp.h>
73665 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73666 +extern int grsec_lastack_retries;
73669 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
73670 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
73671 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
73672 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
73676 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73677 + if ((sk->sk_state == TCP_LAST_ACK) &&
73678 + (grsec_lastack_retries > 0) &&
73679 + (grsec_lastack_retries < retry_until))
73680 + retry_until = grsec_lastack_retries;
73683 if (retransmits_timed_out(sk, retry_until,
73684 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
73685 /* Has it gone just too far? */
73686 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
73687 index 5a65eea..bd913a1 100644
73688 --- a/net/ipv4/udp.c
73689 +++ b/net/ipv4/udp.c
73691 #include <linux/types.h>
73692 #include <linux/fcntl.h>
73693 #include <linux/module.h>
73694 +#include <linux/security.h>
73695 #include <linux/socket.h>
73696 #include <linux/sockios.h>
73697 #include <linux/igmp.h>
73698 @@ -108,6 +109,10 @@
73699 #include <trace/events/udp.h>
73700 #include "udp_impl.h"
73702 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73703 +extern int grsec_enable_blackhole;
73706 struct udp_table udp_table __read_mostly;
73707 EXPORT_SYMBOL(udp_table);
73709 @@ -565,6 +570,9 @@ found:
73713 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
73714 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
73717 * This routine is called by the ICMP module when it gets some
73718 * sort of error condition. If err < 0 then the socket should
73719 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
73720 dport = usin->sin_port;
73724 + err = gr_search_udp_sendmsg(sk, usin);
73728 if (sk->sk_state != TCP_ESTABLISHED)
73729 return -EDESTADDRREQ;
73731 + err = gr_search_udp_sendmsg(sk, NULL);
73735 daddr = inet->inet_daddr;
73736 dport = inet->inet_dport;
73737 /* Open fast path for connected socket.
73738 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
73739 udp_lib_checksum_complete(skb)) {
73740 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73742 - atomic_inc(&sk->sk_drops);
73743 + atomic_inc_unchecked(&sk->sk_drops);
73744 __skb_unlink(skb, rcvq);
73745 __skb_queue_tail(&list_kill, skb);
73747 @@ -1185,6 +1202,10 @@ try_again:
73751 + err = gr_search_udp_recvmsg(sk, skb);
73755 ulen = skb->len - sizeof(struct udphdr);
73758 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73761 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73762 - atomic_inc(&sk->sk_drops);
73763 + atomic_inc_unchecked(&sk->sk_drops);
73767 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73768 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
73771 - atomic_inc(&sk->sk_drops);
73772 + atomic_inc_unchecked(&sk->sk_drops);
73773 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
73775 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73776 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73779 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
73780 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73781 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73783 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
73786 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
73787 sk_wmem_alloc_get(sp),
73788 sk_rmem_alloc_get(sp),
73789 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73790 - atomic_read(&sp->sk_refcnt), sp,
73791 - atomic_read(&sp->sk_drops), len);
73792 + atomic_read(&sp->sk_refcnt),
73793 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73798 + atomic_read_unchecked(&sp->sk_drops), len);
73801 int udp4_seq_show(struct seq_file *seq, void *v)
73802 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
73803 index 836c4ea..cbb74dc 100644
73804 --- a/net/ipv6/addrconf.c
73805 +++ b/net/ipv6/addrconf.c
73806 @@ -2149,7 +2149,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
73808 p.iph.protocol = IPPROTO_IPV6;
73810 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
73811 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
73813 if (ops->ndo_do_ioctl) {
73814 mm_segment_t oldfs = get_fs();
73815 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
73816 index 1567fb1..29af910 100644
73817 --- a/net/ipv6/inet6_connection_sock.c
73818 +++ b/net/ipv6/inet6_connection_sock.c
73819 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
73822 struct rt6_info *rt = (struct rt6_info *)dst;
73823 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
73824 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
73828 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
73831 struct rt6_info *rt = (struct rt6_info *)dst;
73832 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
73833 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
73834 __sk_dst_reset(sk);
73837 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
73838 index 26cb08c..8af9877 100644
73839 --- a/net/ipv6/ipv6_sockglue.c
73840 +++ b/net/ipv6/ipv6_sockglue.c
73841 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
73842 if (sk->sk_type != SOCK_STREAM)
73843 return -ENOPROTOOPT;
73845 - msg.msg_control = optval;
73846 + msg.msg_control = (void __force_kernel *)optval;
73847 msg.msg_controllen = len;
73848 msg.msg_flags = flags;
73850 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
73851 index 361ebf3..d5628fb 100644
73852 --- a/net/ipv6/raw.c
73853 +++ b/net/ipv6/raw.c
73854 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
73856 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
73857 skb_checksum_complete(skb)) {
73858 - atomic_inc(&sk->sk_drops);
73859 + atomic_inc_unchecked(&sk->sk_drops);
73861 return NET_RX_DROP;
73863 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73864 struct raw6_sock *rp = raw6_sk(sk);
73866 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
73867 - atomic_inc(&sk->sk_drops);
73868 + atomic_inc_unchecked(&sk->sk_drops);
73870 return NET_RX_DROP;
73872 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73874 if (inet->hdrincl) {
73875 if (skb_checksum_complete(skb)) {
73876 - atomic_inc(&sk->sk_drops);
73877 + atomic_inc_unchecked(&sk->sk_drops);
73879 return NET_RX_DROP;
73881 @@ -601,7 +601,7 @@ out:
73885 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
73886 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
73887 struct flowi6 *fl6, struct dst_entry **dstp,
73888 unsigned int flags)
73890 @@ -909,12 +909,15 @@ do_confirm:
73891 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
73892 char __user *optval, int optlen)
73894 + struct icmp6_filter filter;
73897 case ICMPV6_FILTER:
73898 if (optlen > sizeof(struct icmp6_filter))
73899 optlen = sizeof(struct icmp6_filter);
73900 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
73901 + if (copy_from_user(&filter, optval, optlen))
73903 + raw6_sk(sk)->filter = filter;
73906 return -ENOPROTOOPT;
73907 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73908 char __user *optval, int __user *optlen)
73911 + struct icmp6_filter filter;
73914 case ICMPV6_FILTER:
73915 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73916 len = sizeof(struct icmp6_filter);
73917 if (put_user(len, optlen))
73919 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
73920 + filter = raw6_sk(sk)->filter;
73921 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
73925 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73929 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73930 + atomic_read(&sp->sk_refcnt),
73931 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73936 + atomic_read_unchecked(&sp->sk_drops));
73939 static int raw6_seq_show(struct seq_file *seq, void *v)
73940 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
73941 index b859e4a..f9d1589 100644
73942 --- a/net/ipv6/tcp_ipv6.c
73943 +++ b/net/ipv6/tcp_ipv6.c
73944 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
73948 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73949 +extern int grsec_enable_blackhole;
73952 static void tcp_v6_hash(struct sock *sk)
73954 if (sk->sk_state != TCP_CLOSE) {
73955 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
73959 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73960 + if (!grsec_enable_blackhole)
73962 tcp_v6_send_reset(sk, skb);
73965 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
73966 TCP_SKB_CB(skb)->sacked = 0;
73968 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73971 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73974 goto no_tcp_socket;
73978 - if (sk->sk_state == TCP_TIME_WAIT)
73979 + if (sk->sk_state == TCP_TIME_WAIT) {
73980 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73986 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
73987 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73988 @@ -1783,6 +1798,10 @@ no_tcp_socket:
73990 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73992 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73993 + if (!grsec_enable_blackhole || (ret == 1 &&
73994 + (skb->dev->flags & IFF_LOOPBACK)))
73996 tcp_v6_send_reset(NULL, skb);
73999 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
74001 0, /* non standard timer */
74002 0, /* open_requests have no inode */
74005 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74013 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
74014 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
74016 icsk->icsk_probes_out,
74018 - atomic_read(&sp->sk_refcnt), sp,
74019 + atomic_read(&sp->sk_refcnt),
74020 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74025 jiffies_to_clock_t(icsk->icsk_rto),
74026 jiffies_to_clock_t(icsk->icsk_ack.ato),
74027 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
74028 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
74029 dest->s6_addr32[2], dest->s6_addr32[3], destp,
74030 tw->tw_substate, 0, 0,
74031 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74032 - atomic_read(&tw->tw_refcnt), tw);
74033 + atomic_read(&tw->tw_refcnt),
74034 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74042 static int tcp6_seq_show(struct seq_file *seq, void *v)
74043 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
74044 index 8c25419..47a51ae 100644
74045 --- a/net/ipv6/udp.c
74046 +++ b/net/ipv6/udp.c
74048 #include <linux/seq_file.h>
74049 #include "udp_impl.h"
74051 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74052 +extern int grsec_enable_blackhole;
74055 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
74057 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
74058 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
74062 - atomic_inc(&sk->sk_drops);
74063 + atomic_inc_unchecked(&sk->sk_drops);
74064 drop_no_sk_drops_inc:
74065 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
74067 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
74071 - atomic_inc(&sk->sk_drops);
74072 + atomic_inc_unchecked(&sk->sk_drops);
74073 UDP6_INC_STATS_BH(sock_net(sk),
74074 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
74075 UDP6_INC_STATS_BH(sock_net(sk),
74076 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74077 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
74078 proto == IPPROTO_UDPLITE);
74080 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74081 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
74083 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
74086 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
74087 if (!sock_owned_by_user(sk))
74088 udpv6_queue_rcv_skb(sk, skb);
74089 else if (sk_add_backlog(sk, skb)) {
74090 - atomic_inc(&sk->sk_drops);
74091 + atomic_inc_unchecked(&sk->sk_drops);
74092 bh_unlock_sock(sk);
74095 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
74099 - atomic_read(&sp->sk_refcnt), sp,
74100 - atomic_read(&sp->sk_drops));
74101 + atomic_read(&sp->sk_refcnt),
74102 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74107 + atomic_read_unchecked(&sp->sk_drops));
74110 int udp6_seq_show(struct seq_file *seq, void *v)
74111 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
74112 index 253695d..9481ce8 100644
74113 --- a/net/irda/ircomm/ircomm_tty.c
74114 +++ b/net/irda/ircomm/ircomm_tty.c
74115 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
74116 add_wait_queue(&self->open_wait, &wait);
74118 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
74119 - __FILE__,__LINE__, tty->driver->name, self->open_count );
74120 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
74122 /* As far as I can see, we protect open_count - Jean II */
74123 spin_lock_irqsave(&self->spinlock, flags);
74124 if (!tty_hung_up_p(filp)) {
74126 - self->open_count--;
74127 + local_dec(&self->open_count);
74129 spin_unlock_irqrestore(&self->spinlock, flags);
74130 - self->blocked_open++;
74131 + local_inc(&self->blocked_open);
74134 if (tty->termios->c_cflag & CBAUD) {
74135 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
74138 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
74139 - __FILE__,__LINE__, tty->driver->name, self->open_count );
74140 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
74144 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
74146 /* ++ is not atomic, so this should be protected - Jean II */
74147 spin_lock_irqsave(&self->spinlock, flags);
74148 - self->open_count++;
74149 + local_inc(&self->open_count);
74150 spin_unlock_irqrestore(&self->spinlock, flags);
74152 - self->blocked_open--;
74153 + local_dec(&self->blocked_open);
74155 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
74156 - __FILE__,__LINE__, tty->driver->name, self->open_count);
74157 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
74160 self->flags |= ASYNC_NORMAL_ACTIVE;
74161 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
74163 /* ++ is not atomic, so this should be protected - Jean II */
74164 spin_lock_irqsave(&self->spinlock, flags);
74165 - self->open_count++;
74166 + local_inc(&self->open_count);
74168 tty->driver_data = self;
74170 spin_unlock_irqrestore(&self->spinlock, flags);
74172 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
74173 - self->line, self->open_count);
74174 + self->line, local_read(&self->open_count));
74176 /* Not really used by us, but lets do it anyway */
74177 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
74178 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
74182 - if ((tty->count == 1) && (self->open_count != 1)) {
74183 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
74185 * Uh, oh. tty->count is 1, which means that the tty
74186 * structure will be freed. state->count should always
74187 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
74189 IRDA_DEBUG(0, "%s(), bad serial port count; "
74190 "tty->count is 1, state->count is %d\n", __func__ ,
74191 - self->open_count);
74192 - self->open_count = 1;
74193 + local_read(&self->open_count));
74194 + local_set(&self->open_count, 1);
74197 - if (--self->open_count < 0) {
74198 + if (local_dec_return(&self->open_count) < 0) {
74199 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
74200 - __func__, self->line, self->open_count);
74201 - self->open_count = 0;
74202 + __func__, self->line, local_read(&self->open_count));
74203 + local_set(&self->open_count, 0);
74205 - if (self->open_count) {
74206 + if (local_read(&self->open_count)) {
74207 spin_unlock_irqrestore(&self->spinlock, flags);
74209 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
74210 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
74214 - if (self->blocked_open) {
74215 + if (local_read(&self->blocked_open)) {
74216 if (self->close_delay)
74217 schedule_timeout_interruptible(self->close_delay);
74218 wake_up_interruptible(&self->open_wait);
74219 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
74220 spin_lock_irqsave(&self->spinlock, flags);
74221 self->flags &= ~ASYNC_NORMAL_ACTIVE;
74223 - self->open_count = 0;
74224 + local_set(&self->open_count, 0);
74225 spin_unlock_irqrestore(&self->spinlock, flags);
74227 wake_up_interruptible(&self->open_wait);
74228 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
74231 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
74232 - seq_printf(m, "Open count: %d\n", self->open_count);
74233 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
74234 seq_printf(m, "Max data size: %d\n", self->max_data_size);
74235 seq_printf(m, "Max header size: %d\n", self->max_header_size);
74237 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
74238 index 274d150..656a144 100644
74239 --- a/net/iucv/af_iucv.c
74240 +++ b/net/iucv/af_iucv.c
74241 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
74243 write_lock_bh(&iucv_sk_list.lock);
74245 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
74246 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
74247 while (__iucv_get_sock_by_name(name)) {
74248 sprintf(name, "%08x",
74249 - atomic_inc_return(&iucv_sk_list.autobind_name));
74250 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
74253 write_unlock_bh(&iucv_sk_list.lock);
74254 diff --git a/net/key/af_key.c b/net/key/af_key.c
74255 index 1e733e9..3d73c9f 100644
74256 --- a/net/key/af_key.c
74257 +++ b/net/key/af_key.c
74258 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
74259 static u32 get_acqseq(void)
74262 - static atomic_t acqseq;
74263 + static atomic_unchecked_t acqseq;
74266 - res = atomic_inc_return(&acqseq);
74267 + res = atomic_inc_return_unchecked(&acqseq);
74271 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
74272 index 73495f1..ad51356 100644
74273 --- a/net/mac80211/ieee80211_i.h
74274 +++ b/net/mac80211/ieee80211_i.h
74276 #include <net/ieee80211_radiotap.h>
74277 #include <net/cfg80211.h>
74278 #include <net/mac80211.h>
74279 +#include <asm/local.h>
74281 #include "sta_info.h"
74283 @@ -764,7 +765,7 @@ struct ieee80211_local {
74284 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
74285 spinlock_t queue_stop_reason_lock;
74288 + local_t open_count;
74289 int monitors, cooked_mntrs;
74290 /* number of interfaces with corresponding FIF_ flags */
74291 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
74292 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
74293 index 30d7355..e260095 100644
74294 --- a/net/mac80211/iface.c
74295 +++ b/net/mac80211/iface.c
74296 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74300 - if (local->open_count == 0) {
74301 + if (local_read(&local->open_count) == 0) {
74302 res = drv_start(local);
74305 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74306 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
74308 if (!is_valid_ether_addr(dev->dev_addr)) {
74309 - if (!local->open_count)
74310 + if (!local_read(&local->open_count))
74312 return -EADDRNOTAVAIL;
74314 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74315 mutex_unlock(&local->mtx);
74318 - local->open_count++;
74319 + local_inc(&local->open_count);
74321 if (hw_reconf_flags) {
74322 ieee80211_hw_config(local, hw_reconf_flags);
74323 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74325 drv_remove_interface(local, &sdata->vif);
74327 - if (!local->open_count)
74328 + if (!local_read(&local->open_count))
74332 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
74336 - local->open_count--;
74337 + local_dec(&local->open_count);
74339 switch (sdata->vif.type) {
74340 case NL80211_IFTYPE_AP_VLAN:
74341 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
74343 ieee80211_recalc_ps(local, -1);
74345 - if (local->open_count == 0) {
74346 + if (local_read(&local->open_count) == 0) {
74347 if (local->ops->napi_poll)
74348 napi_disable(&local->napi);
74349 ieee80211_clear_tx_pending(local);
74350 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
74351 index 7d9b21d..0687004 100644
74352 --- a/net/mac80211/main.c
74353 +++ b/net/mac80211/main.c
74354 @@ -163,7 +163,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
74355 local->hw.conf.power_level = power;
74358 - if (changed && local->open_count) {
74359 + if (changed && local_read(&local->open_count)) {
74360 ret = drv_config(local, changed);
74363 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
74364 index 9ee7164..56c5061 100644
74365 --- a/net/mac80211/pm.c
74366 +++ b/net/mac80211/pm.c
74367 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
74368 struct ieee80211_sub_if_data *sdata;
74369 struct sta_info *sta;
74371 - if (!local->open_count)
74372 + if (!local_read(&local->open_count))
74375 ieee80211_scan_cancel(local);
74376 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
74377 cancel_work_sync(&local->dynamic_ps_enable_work);
74378 del_timer_sync(&local->dynamic_ps_timer);
74380 - local->wowlan = wowlan && local->open_count;
74381 + local->wowlan = wowlan && local_read(&local->open_count);
74382 if (local->wowlan) {
74383 int err = drv_suspend(local, wowlan);
74385 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
74388 /* stop hardware - this must stop RX */
74389 - if (local->open_count)
74390 + if (local_read(&local->open_count))
74391 ieee80211_stop_device(local);
74394 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
74395 index 5a5a776..9600b11 100644
74396 --- a/net/mac80211/rate.c
74397 +++ b/net/mac80211/rate.c
74398 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
74402 - if (local->open_count)
74403 + if (local_read(&local->open_count))
74406 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
74407 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
74408 index c97a065..ff61928 100644
74409 --- a/net/mac80211/rc80211_pid_debugfs.c
74410 +++ b/net/mac80211/rc80211_pid_debugfs.c
74411 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
74413 spin_unlock_irqrestore(&events->lock, status);
74415 - if (copy_to_user(buf, pb, p))
74416 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
74420 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
74421 index d5230ec..c604b21 100644
74422 --- a/net/mac80211/util.c
74423 +++ b/net/mac80211/util.c
74424 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
74425 drv_set_coverage_class(local, hw->wiphy->coverage_class);
74427 /* everything else happens only if HW was up & running */
74428 - if (!local->open_count)
74429 + if (!local_read(&local->open_count))
74433 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
74434 index d5597b7..ab6d39c 100644
74435 --- a/net/netfilter/Kconfig
74436 +++ b/net/netfilter/Kconfig
74437 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
74439 To compile it as a module, choose M here. If unsure, say N.
74441 +config NETFILTER_XT_MATCH_GRADM
74442 + tristate '"gradm" match support'
74443 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
74444 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
74446 + The gradm match allows to match on grsecurity RBAC being enabled.
74447 + It is useful when iptables rules are applied early on bootup to
74448 + prevent connections to the machine (except from a trusted host)
74449 + while the RBAC system is disabled.
74451 config NETFILTER_XT_MATCH_HASHLIMIT
74452 tristate '"hashlimit" match support'
74453 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
74454 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
74455 index 1a02853..5d8c22e 100644
74456 --- a/net/netfilter/Makefile
74457 +++ b/net/netfilter/Makefile
74458 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
74459 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
74460 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
74461 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
74462 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
74463 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
74464 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
74465 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
74466 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
74467 index 29fa5ba..8debc79 100644
74468 --- a/net/netfilter/ipvs/ip_vs_conn.c
74469 +++ b/net/netfilter/ipvs/ip_vs_conn.c
74470 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
74471 /* Increase the refcnt counter of the dest */
74472 atomic_inc(&dest->refcnt);
74474 - conn_flags = atomic_read(&dest->conn_flags);
74475 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
74476 if (cp->protocol != IPPROTO_UDP)
74477 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
74478 /* Bind with the destination and its corresponding transmitter */
74479 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
74480 atomic_set(&cp->refcnt, 1);
74482 atomic_set(&cp->n_control, 0);
74483 - atomic_set(&cp->in_pkts, 0);
74484 + atomic_set_unchecked(&cp->in_pkts, 0);
74486 atomic_inc(&ipvs->conn_count);
74487 if (flags & IP_VS_CONN_F_NO_CPORT)
74488 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
74490 /* Don't drop the entry if its number of incoming packets is not
74491 located in [0, 8] */
74492 - i = atomic_read(&cp->in_pkts);
74493 + i = atomic_read_unchecked(&cp->in_pkts);
74494 if (i > 8 || i < 0) return 0;
74496 if (!todrop_rate[i]) return 0;
74497 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
74498 index 6dc7d7d..e45913a 100644
74499 --- a/net/netfilter/ipvs/ip_vs_core.c
74500 +++ b/net/netfilter/ipvs/ip_vs_core.c
74501 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
74502 ret = cp->packet_xmit(skb, cp, pd->pp);
74503 /* do not touch skb anymore */
74505 - atomic_inc(&cp->in_pkts);
74506 + atomic_inc_unchecked(&cp->in_pkts);
74507 ip_vs_conn_put(cp);
74510 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
74511 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
74512 pkts = sysctl_sync_threshold(ipvs);
74514 - pkts = atomic_add_return(1, &cp->in_pkts);
74515 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74517 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
74518 cp->protocol == IPPROTO_SCTP) {
74519 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
74520 index e1a66cf..0910076 100644
74521 --- a/net/netfilter/ipvs/ip_vs_ctl.c
74522 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
74523 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
74524 ip_vs_rs_hash(ipvs, dest);
74525 write_unlock_bh(&ipvs->rs_lock);
74527 - atomic_set(&dest->conn_flags, conn_flags);
74528 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
74530 /* bind the service */
74532 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74533 " %-7s %-6d %-10d %-10d\n",
74536 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74537 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74538 atomic_read(&dest->weight),
74539 atomic_read(&dest->activeconns),
74540 atomic_read(&dest->inactconns));
74541 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74542 "%-7s %-6d %-10d %-10d\n",
74543 ntohl(dest->addr.ip),
74545 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74546 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74547 atomic_read(&dest->weight),
74548 atomic_read(&dest->activeconns),
74549 atomic_read(&dest->inactconns));
74550 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
74552 entry.addr = dest->addr.ip;
74553 entry.port = dest->port;
74554 - entry.conn_flags = atomic_read(&dest->conn_flags);
74555 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
74556 entry.weight = atomic_read(&dest->weight);
74557 entry.u_threshold = dest->u_threshold;
74558 entry.l_threshold = dest->l_threshold;
74559 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
74560 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
74562 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
74563 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74564 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74565 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
74566 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
74567 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
74568 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
74569 index 2b6678c0..aaa41fc 100644
74570 --- a/net/netfilter/ipvs/ip_vs_sync.c
74571 +++ b/net/netfilter/ipvs/ip_vs_sync.c
74572 @@ -649,7 +649,7 @@ control:
74573 * i.e only increment in_pkts for Templates.
74575 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
74576 - int pkts = atomic_add_return(1, &cp->in_pkts);
74577 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74579 if (pkts % sysctl_sync_period(ipvs) != 1)
74581 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
74584 memcpy(&cp->in_seq, opt, sizeof(*opt));
74585 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74586 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74588 cp->old_state = cp->state;
74590 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
74591 index aa2d720..d8aa111 100644
74592 --- a/net/netfilter/ipvs/ip_vs_xmit.c
74593 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
74594 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
74597 /* do not touch skb anymore */
74598 - atomic_inc(&cp->in_pkts);
74599 + atomic_inc_unchecked(&cp->in_pkts);
74603 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
74606 /* do not touch skb anymore */
74607 - atomic_inc(&cp->in_pkts);
74608 + atomic_inc_unchecked(&cp->in_pkts);
74612 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
74613 index 66b2c54..c7884e3 100644
74614 --- a/net/netfilter/nfnetlink_log.c
74615 +++ b/net/netfilter/nfnetlink_log.c
74616 @@ -70,7 +70,7 @@ struct nfulnl_instance {
74619 static DEFINE_SPINLOCK(instances_lock);
74620 -static atomic_t global_seq;
74621 +static atomic_unchecked_t global_seq;
74623 #define INSTANCE_BUCKETS 16
74624 static struct hlist_head instance_table[INSTANCE_BUCKETS];
74625 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
74626 /* global sequence number */
74627 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
74628 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
74629 - htonl(atomic_inc_return(&global_seq)));
74630 + htonl(atomic_inc_return_unchecked(&global_seq)));
74633 struct nlattr *nla;
74634 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
74635 new file mode 100644
74636 index 0000000..6905327
74638 +++ b/net/netfilter/xt_gradm.c
74641 + * gradm match for netfilter
74642 + * Copyright © Zbigniew Krzystolik, 2010
74644 + * This program is free software; you can redistribute it and/or modify
74645 + * it under the terms of the GNU General Public License; either version
74646 + * 2 or 3 as published by the Free Software Foundation.
74648 +#include <linux/module.h>
74649 +#include <linux/moduleparam.h>
74650 +#include <linux/skbuff.h>
74651 +#include <linux/netfilter/x_tables.h>
74652 +#include <linux/grsecurity.h>
74653 +#include <linux/netfilter/xt_gradm.h>
74656 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
74658 + const struct xt_gradm_mtinfo *info = par->matchinfo;
74659 + bool retval = false;
74660 + if (gr_acl_is_enabled())
74662 + return retval ^ info->invflags;
74665 +static struct xt_match gradm_mt_reg __read_mostly = {
74668 + .family = NFPROTO_UNSPEC,
74669 + .match = gradm_mt,
74670 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
74671 + .me = THIS_MODULE,
74674 +static int __init gradm_mt_init(void)
74676 + return xt_register_match(&gradm_mt_reg);
74679 +static void __exit gradm_mt_exit(void)
74681 + xt_unregister_match(&gradm_mt_reg);
74684 +module_init(gradm_mt_init);
74685 +module_exit(gradm_mt_exit);
74686 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
74687 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
74688 +MODULE_LICENSE("GPL");
74689 +MODULE_ALIAS("ipt_gradm");
74690 +MODULE_ALIAS("ip6t_gradm");
74691 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
74692 index 4fe4fb4..87a89e5 100644
74693 --- a/net/netfilter/xt_statistic.c
74694 +++ b/net/netfilter/xt_statistic.c
74696 #include <linux/module.h>
74698 struct xt_statistic_priv {
74700 + atomic_unchecked_t count;
74701 } ____cacheline_aligned_in_smp;
74703 MODULE_LICENSE("GPL");
74704 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
74706 case XT_STATISTIC_MODE_NTH:
74708 - oval = atomic_read(&info->master->count);
74709 + oval = atomic_read_unchecked(&info->master->count);
74710 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
74711 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
74712 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
74716 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
74717 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
74718 if (info->master == NULL)
74720 - atomic_set(&info->master->count, info->u.nth.count);
74721 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
74725 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
74726 index 1201b6d..bcff8c6 100644
74727 --- a/net/netlink/af_netlink.c
74728 +++ b/net/netlink/af_netlink.c
74729 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
74730 sk->sk_error_report(sk);
74733 - atomic_inc(&sk->sk_drops);
74734 + atomic_inc_unchecked(&sk->sk_drops);
74737 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
74738 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
74739 sk_wmem_alloc_get(s),
74741 atomic_read(&s->sk_refcnt),
74742 - atomic_read(&s->sk_drops),
74743 + atomic_read_unchecked(&s->sk_drops),
74747 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
74748 index 732152f..60bb09e 100644
74749 --- a/net/netrom/af_netrom.c
74750 +++ b/net/netrom/af_netrom.c
74751 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74752 struct sock *sk = sock->sk;
74753 struct nr_sock *nr = nr_sk(sk);
74755 + memset(sax, 0, sizeof(*sax));
74758 if (sk->sk_state != TCP_ESTABLISHED) {
74759 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74760 *uaddr_len = sizeof(struct full_sockaddr_ax25);
74762 sax->fsa_ax25.sax25_family = AF_NETROM;
74763 - sax->fsa_ax25.sax25_ndigis = 0;
74764 sax->fsa_ax25.sax25_call = nr->source_addr;
74765 *uaddr_len = sizeof(struct sockaddr_ax25);
74767 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
74768 index d9d4970..d5a6a68 100644
74769 --- a/net/packet/af_packet.c
74770 +++ b/net/packet/af_packet.c
74771 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74773 spin_lock(&sk->sk_receive_queue.lock);
74774 po->stats.tp_packets++;
74775 - skb->dropcount = atomic_read(&sk->sk_drops);
74776 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74777 __skb_queue_tail(&sk->sk_receive_queue, skb);
74778 spin_unlock(&sk->sk_receive_queue.lock);
74779 sk->sk_data_ready(sk, skb->len);
74780 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74782 spin_lock(&sk->sk_receive_queue.lock);
74783 po->stats.tp_drops++;
74784 - atomic_inc(&sk->sk_drops);
74785 + atomic_inc_unchecked(&sk->sk_drops);
74786 spin_unlock(&sk->sk_receive_queue.lock);
74789 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74790 case PACKET_HDRLEN:
74791 if (len > sizeof(int))
74793 - if (copy_from_user(&val, optval, len))
74794 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
74798 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74800 if (put_user(len, optlen))
74802 - if (copy_to_user(optval, data, len))
74803 + if (len > sizeof(st) || copy_to_user(optval, data, len))
74807 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
74808 index d65f699..05aa6ce 100644
74809 --- a/net/phonet/af_phonet.c
74810 +++ b/net/phonet/af_phonet.c
74811 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
74813 struct phonet_protocol *pp;
74815 - if (protocol >= PHONET_NPROTO)
74816 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74820 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
74824 - if (protocol >= PHONET_NPROTO)
74825 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74828 err = proto_register(pp->prot, 1);
74829 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
74830 index 2ba6e9f..409573f 100644
74831 --- a/net/phonet/pep.c
74832 +++ b/net/phonet/pep.c
74833 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74835 case PNS_PEP_CTRL_REQ:
74836 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
74837 - atomic_inc(&sk->sk_drops);
74838 + atomic_inc_unchecked(&sk->sk_drops);
74841 __skb_pull(skb, 4);
74842 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74845 if (pn->rx_credits == 0) {
74846 - atomic_inc(&sk->sk_drops);
74847 + atomic_inc_unchecked(&sk->sk_drops);
74851 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
74854 if (pn->rx_credits == 0) {
74855 - atomic_inc(&sk->sk_drops);
74856 + atomic_inc_unchecked(&sk->sk_drops);
74860 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
74861 index 4c7eff3..59c727f 100644
74862 --- a/net/phonet/socket.c
74863 +++ b/net/phonet/socket.c
74864 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
74865 pn->resource, sk->sk_state,
74866 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
74867 sock_i_uid(sk), sock_i_ino(sk),
74868 - atomic_read(&sk->sk_refcnt), sk,
74869 - atomic_read(&sk->sk_drops), &len);
74870 + atomic_read(&sk->sk_refcnt),
74871 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74876 + atomic_read_unchecked(&sk->sk_drops), &len);
74878 seq_printf(seq, "%*s\n", 127 - len, "");
74880 diff --git a/net/rds/cong.c b/net/rds/cong.c
74881 index e5b65ac..f3b6fb7 100644
74882 --- a/net/rds/cong.c
74883 +++ b/net/rds/cong.c
74885 * finds that the saved generation number is smaller than the global generation
74886 * number, it wakes up the process.
74888 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
74889 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
74892 * Congestion monitoring
74893 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
74894 rdsdebug("waking map %p for %pI4\n",
74895 map, &map->m_addr);
74896 rds_stats_inc(s_cong_update_received);
74897 - atomic_inc(&rds_cong_generation);
74898 + atomic_inc_unchecked(&rds_cong_generation);
74899 if (waitqueue_active(&map->m_waitq))
74900 wake_up(&map->m_waitq);
74901 if (waitqueue_active(&rds_poll_waitq))
74902 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
74904 int rds_cong_updated_since(unsigned long *recent)
74906 - unsigned long gen = atomic_read(&rds_cong_generation);
74907 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
74909 if (likely(*recent == gen))
74911 diff --git a/net/rds/ib.h b/net/rds/ib.h
74912 index edfaaaf..8c89879 100644
74915 @@ -128,7 +128,7 @@ struct rds_ib_connection {
74917 unsigned long i_ack_flags;
74918 #ifdef KERNEL_HAS_ATOMIC64
74919 - atomic64_t i_ack_next; /* next ACK to send */
74920 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74922 spinlock_t i_ack_lock; /* protect i_ack_next */
74923 u64 i_ack_next; /* next ACK to send */
74924 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
74925 index 51c8689..36c555f 100644
74926 --- a/net/rds/ib_cm.c
74927 +++ b/net/rds/ib_cm.c
74928 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
74929 /* Clear the ACK state */
74930 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74931 #ifdef KERNEL_HAS_ATOMIC64
74932 - atomic64_set(&ic->i_ack_next, 0);
74933 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74935 ic->i_ack_next = 0;
74937 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
74938 index e29e0ca..fa3a6a3 100644
74939 --- a/net/rds/ib_recv.c
74940 +++ b/net/rds/ib_recv.c
74941 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74942 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
74945 - atomic64_set(&ic->i_ack_next, seq);
74946 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74947 if (ack_required) {
74948 smp_mb__before_clear_bit();
74949 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74950 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74951 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74952 smp_mb__after_clear_bit();
74954 - return atomic64_read(&ic->i_ack_next);
74955 + return atomic64_read_unchecked(&ic->i_ack_next);
74959 diff --git a/net/rds/iw.h b/net/rds/iw.h
74960 index 04ce3b1..48119a6 100644
74963 @@ -134,7 +134,7 @@ struct rds_iw_connection {
74965 unsigned long i_ack_flags;
74966 #ifdef KERNEL_HAS_ATOMIC64
74967 - atomic64_t i_ack_next; /* next ACK to send */
74968 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74970 spinlock_t i_ack_lock; /* protect i_ack_next */
74971 u64 i_ack_next; /* next ACK to send */
74972 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
74973 index 9556d28..f046d0e 100644
74974 --- a/net/rds/iw_cm.c
74975 +++ b/net/rds/iw_cm.c
74976 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
74977 /* Clear the ACK state */
74978 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74979 #ifdef KERNEL_HAS_ATOMIC64
74980 - atomic64_set(&ic->i_ack_next, 0);
74981 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74983 ic->i_ack_next = 0;
74985 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
74986 index 5e57347..3916042 100644
74987 --- a/net/rds/iw_recv.c
74988 +++ b/net/rds/iw_recv.c
74989 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74990 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
74993 - atomic64_set(&ic->i_ack_next, seq);
74994 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74995 if (ack_required) {
74996 smp_mb__before_clear_bit();
74997 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74998 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74999 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
75000 smp_mb__after_clear_bit();
75002 - return atomic64_read(&ic->i_ack_next);
75003 + return atomic64_read_unchecked(&ic->i_ack_next);
75007 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
75008 index edac9ef..16bcb98 100644
75009 --- a/net/rds/tcp.c
75010 +++ b/net/rds/tcp.c
75011 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
75015 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
75016 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
75020 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
75021 index 1b4fd68..2234175 100644
75022 --- a/net/rds/tcp_send.c
75023 +++ b/net/rds/tcp_send.c
75024 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
75028 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
75029 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
75033 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
75034 index 74c064c..fdec26f 100644
75035 --- a/net/rxrpc/af_rxrpc.c
75036 +++ b/net/rxrpc/af_rxrpc.c
75037 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
75038 __be32 rxrpc_epoch;
75040 /* current debugging ID */
75041 -atomic_t rxrpc_debug_id;
75042 +atomic_unchecked_t rxrpc_debug_id;
75044 /* count of skbs currently in use */
75045 atomic_t rxrpc_n_skbs;
75046 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
75047 index f99cfce..cc529dd 100644
75048 --- a/net/rxrpc/ar-ack.c
75049 +++ b/net/rxrpc/ar-ack.c
75050 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
75052 _enter("{%d,%d,%d,%d},",
75053 call->acks_hard, call->acks_unacked,
75054 - atomic_read(&call->sequence),
75055 + atomic_read_unchecked(&call->sequence),
75056 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
75059 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
75061 /* each Tx packet has a new serial number */
75063 - htonl(atomic_inc_return(&call->conn->serial));
75064 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
75066 hdr = (struct rxrpc_header *) txb->head;
75067 hdr->serial = sp->hdr.serial;
75068 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
75070 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
75072 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
75073 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
75077 @@ -629,7 +629,7 @@ process_further:
75079 latest = ntohl(sp->hdr.serial);
75080 hard = ntohl(ack.firstPacket);
75081 - tx = atomic_read(&call->sequence);
75082 + tx = atomic_read_unchecked(&call->sequence);
75084 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
75086 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
75087 goto maybe_reschedule;
75089 send_ACK_with_skew:
75090 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
75091 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
75092 ntohl(ack.serial));
75094 mtu = call->conn->trans->peer->if_mtu;
75095 @@ -1173,7 +1173,7 @@ send_ACK:
75096 ackinfo.rxMTU = htonl(5692);
75097 ackinfo.jumbo_max = htonl(4);
75099 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
75100 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
75101 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
75103 ntohs(ack.maxSkew),
75104 @@ -1191,7 +1191,7 @@ send_ACK:
75106 _debug("send message");
75108 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
75109 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
75110 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
75113 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
75114 index bf656c2..48f9d27 100644
75115 --- a/net/rxrpc/ar-call.c
75116 +++ b/net/rxrpc/ar-call.c
75117 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
75118 spin_lock_init(&call->lock);
75119 rwlock_init(&call->state_lock);
75120 atomic_set(&call->usage, 1);
75121 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
75122 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75123 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
75125 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
75126 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
75127 index 4106ca9..a338d7a 100644
75128 --- a/net/rxrpc/ar-connection.c
75129 +++ b/net/rxrpc/ar-connection.c
75130 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
75131 rwlock_init(&conn->lock);
75132 spin_lock_init(&conn->state_lock);
75133 atomic_set(&conn->usage, 1);
75134 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
75135 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75136 conn->avail_calls = RXRPC_MAXCALLS;
75137 conn->size_align = 4;
75138 conn->header_size = sizeof(struct rxrpc_header);
75139 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
75140 index e7ed43a..6afa140 100644
75141 --- a/net/rxrpc/ar-connevent.c
75142 +++ b/net/rxrpc/ar-connevent.c
75143 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
75145 len = iov[0].iov_len + iov[1].iov_len;
75147 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
75148 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
75149 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
75151 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
75152 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
75153 index 1a2b0633..e8d1382 100644
75154 --- a/net/rxrpc/ar-input.c
75155 +++ b/net/rxrpc/ar-input.c
75156 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
75157 /* track the latest serial number on this connection for ACK packet
75159 serial = ntohl(sp->hdr.serial);
75160 - hi_serial = atomic_read(&call->conn->hi_serial);
75161 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
75162 while (serial > hi_serial)
75163 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
75164 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
75167 /* request ACK generation for any ACK or DATA packet that requests
75168 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
75169 index 8e22bd3..f66d1c0 100644
75170 --- a/net/rxrpc/ar-internal.h
75171 +++ b/net/rxrpc/ar-internal.h
75172 @@ -272,8 +272,8 @@ struct rxrpc_connection {
75173 int error; /* error code for local abort */
75174 int debug_id; /* debug ID for printks */
75175 unsigned call_counter; /* call ID counter */
75176 - atomic_t serial; /* packet serial number counter */
75177 - atomic_t hi_serial; /* highest serial number received */
75178 + atomic_unchecked_t serial; /* packet serial number counter */
75179 + atomic_unchecked_t hi_serial; /* highest serial number received */
75180 u8 avail_calls; /* number of calls available */
75181 u8 size_align; /* data size alignment (for security) */
75182 u8 header_size; /* rxrpc + security header size */
75183 @@ -346,7 +346,7 @@ struct rxrpc_call {
75185 rwlock_t state_lock; /* lock for state transition */
75187 - atomic_t sequence; /* Tx data packet sequence counter */
75188 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
75189 u32 abort_code; /* local/remote abort code */
75190 enum { /* current state of call */
75191 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
75192 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
75194 extern atomic_t rxrpc_n_skbs;
75195 extern __be32 rxrpc_epoch;
75196 -extern atomic_t rxrpc_debug_id;
75197 +extern atomic_unchecked_t rxrpc_debug_id;
75198 extern struct workqueue_struct *rxrpc_workqueue;
75201 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
75202 index 87f7135..74d3703 100644
75203 --- a/net/rxrpc/ar-local.c
75204 +++ b/net/rxrpc/ar-local.c
75205 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
75206 spin_lock_init(&local->lock);
75207 rwlock_init(&local->services_lock);
75208 atomic_set(&local->usage, 1);
75209 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
75210 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75211 memcpy(&local->srx, srx, sizeof(*srx));
75214 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
75215 index 338d793..47391d0 100644
75216 --- a/net/rxrpc/ar-output.c
75217 +++ b/net/rxrpc/ar-output.c
75218 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
75219 sp->hdr.cid = call->cid;
75220 sp->hdr.callNumber = call->call_id;
75222 - htonl(atomic_inc_return(&call->sequence));
75223 + htonl(atomic_inc_return_unchecked(&call->sequence));
75225 - htonl(atomic_inc_return(&conn->serial));
75226 + htonl(atomic_inc_return_unchecked(&conn->serial));
75227 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
75228 sp->hdr.userStatus = 0;
75229 sp->hdr.securityIndex = conn->security_ix;
75230 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
75231 index 2754f09..b20e38f 100644
75232 --- a/net/rxrpc/ar-peer.c
75233 +++ b/net/rxrpc/ar-peer.c
75234 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
75235 INIT_LIST_HEAD(&peer->error_targets);
75236 spin_lock_init(&peer->lock);
75237 atomic_set(&peer->usage, 1);
75238 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
75239 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75240 memcpy(&peer->srx, srx, sizeof(*srx));
75242 rxrpc_assess_MTU_size(peer);
75243 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
75244 index 38047f7..9f48511 100644
75245 --- a/net/rxrpc/ar-proc.c
75246 +++ b/net/rxrpc/ar-proc.c
75247 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
75248 atomic_read(&conn->usage),
75249 rxrpc_conn_states[conn->state],
75250 key_serial(conn->key),
75251 - atomic_read(&conn->serial),
75252 - atomic_read(&conn->hi_serial));
75253 + atomic_read_unchecked(&conn->serial),
75254 + atomic_read_unchecked(&conn->hi_serial));
75258 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
75259 index 92df566..87ec1bf 100644
75260 --- a/net/rxrpc/ar-transport.c
75261 +++ b/net/rxrpc/ar-transport.c
75262 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
75263 spin_lock_init(&trans->client_lock);
75264 rwlock_init(&trans->conn_lock);
75265 atomic_set(&trans->usage, 1);
75266 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
75267 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75269 if (peer->srx.transport.family == AF_INET) {
75270 switch (peer->srx.transport_type) {
75271 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
75272 index 7635107..4670276 100644
75273 --- a/net/rxrpc/rxkad.c
75274 +++ b/net/rxrpc/rxkad.c
75275 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
75277 len = iov[0].iov_len + iov[1].iov_len;
75279 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
75280 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
75281 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
75283 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
75284 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
75286 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
75288 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
75289 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
75290 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
75292 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
75293 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
75294 index 1e2eee8..ce3967e 100644
75295 --- a/net/sctp/proc.c
75296 +++ b/net/sctp/proc.c
75297 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
75299 "%8pK %8pK %-3d %-3d %-2d %-4d "
75300 "%4d %8d %8d %7d %5lu %-5d %5d ",
75301 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
75303 + sctp_sk(sk)->type, sk->sk_state,
75304 assoc->state, hash,
75306 assoc->sndbuf_used,
75307 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
75308 index 54a7cd2..944edae 100644
75309 --- a/net/sctp/socket.c
75310 +++ b/net/sctp/socket.c
75311 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
75312 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
75313 if (space_left < addrlen)
75315 - if (copy_to_user(to, &temp, addrlen))
75316 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
75320 diff --git a/net/socket.c b/net/socket.c
75321 index 2dce67a..1e91168 100644
75325 #include <linux/nsproxy.h>
75326 #include <linux/magic.h>
75327 #include <linux/slab.h>
75328 +#include <linux/in.h>
75330 #include <asm/uaccess.h>
75331 #include <asm/unistd.h>
75332 @@ -105,6 +106,8 @@
75333 #include <linux/sockios.h>
75334 #include <linux/atalk.h>
75336 +#include <linux/grsock.h>
75338 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
75339 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
75340 unsigned long nr_segs, loff_t pos);
75341 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
75342 &sockfs_dentry_operations, SOCKFS_MAGIC);
75345 -static struct vfsmount *sock_mnt __read_mostly;
75346 +struct vfsmount *sock_mnt __read_mostly;
75348 static struct file_system_type sock_fs_type = {
75350 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
75351 return -EAFNOSUPPORT;
75352 if (type < 0 || type >= SOCK_MAX)
75354 + if (protocol < 0)
75359 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
75360 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
75361 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
75363 + if(!gr_search_socket(family, type, protocol)) {
75364 + retval = -EACCES;
75368 + if (gr_handle_sock_all(family, type, protocol)) {
75369 + retval = -EACCES;
75373 retval = sock_create(family, type, protocol, &sock);
75376 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
75378 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
75380 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
75384 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
75388 err = security_socket_bind(sock,
75389 (struct sockaddr *)&address,
75391 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
75392 (struct sockaddr *)
75393 &address, addrlen);
75396 fput_light(sock->file, fput_needed);
75399 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
75400 if ((unsigned)backlog > somaxconn)
75401 backlog = somaxconn;
75403 + if (gr_handle_sock_server_other(sock->sk)) {
75408 + err = gr_search_listen(sock);
75412 err = security_socket_listen(sock, backlog);
75414 err = sock->ops->listen(sock, backlog);
75417 fput_light(sock->file, fput_needed);
75420 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
75421 newsock->type = sock->type;
75422 newsock->ops = sock->ops;
75424 + if (gr_handle_sock_server_other(sock->sk)) {
75426 + sock_release(newsock);
75430 + err = gr_search_accept(sock);
75432 + sock_release(newsock);
75437 * We don't need try_module_get here, as the listening socket (sock)
75438 * has the protocol module (sock->ops->owner) held.
75439 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
75440 fd_install(newfd, newfile);
75443 + gr_attach_curr_ip(newsock->sk);
75446 fput_light(sock->file, fput_needed);
75448 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
75451 struct socket *sock;
75452 + struct sockaddr *sck;
75453 struct sockaddr_storage address;
75454 int err, fput_needed;
75456 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
75460 + sck = (struct sockaddr *)&address;
75462 + if (gr_handle_sock_client(sck)) {
75467 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
75472 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
75474 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
75475 * checking falls down on this.
75477 if (copy_from_user(ctl_buf,
75478 - (void __user __force *)msg_sys->msg_control,
75479 + (void __force_user *)msg_sys->msg_control,
75482 msg_sys->msg_control = ctl_buf;
75483 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
75484 * kernel msghdr to use the kernel address space)
75487 - uaddr = (__force void __user *)msg_sys->msg_name;
75488 + uaddr = (void __force_user *)msg_sys->msg_name;
75489 uaddr_len = COMPAT_NAMELEN(msg);
75490 if (MSG_CMSG_COMPAT & flags) {
75491 err = verify_compat_iovec(msg_sys, iov,
75492 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75495 ifr = compat_alloc_user_space(buf_size);
75496 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
75497 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
75499 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
75501 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75502 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
75504 if (copy_in_user(rxnfc, compat_rxnfc,
75505 - (void *)(&rxnfc->fs.m_ext + 1) -
75506 - (void *)rxnfc) ||
75507 + (void __user *)(&rxnfc->fs.m_ext + 1) -
75508 + (void __user *)rxnfc) ||
75509 copy_in_user(&rxnfc->fs.ring_cookie,
75510 &compat_rxnfc->fs.ring_cookie,
75511 - (void *)(&rxnfc->fs.location + 1) -
75512 - (void *)&rxnfc->fs.ring_cookie) ||
75513 + (void __user *)(&rxnfc->fs.location + 1) -
75514 + (void __user *)&rxnfc->fs.ring_cookie) ||
75515 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
75516 sizeof(rxnfc->rule_cnt)))
75518 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75521 if (copy_in_user(compat_rxnfc, rxnfc,
75522 - (const void *)(&rxnfc->fs.m_ext + 1) -
75523 - (const void *)rxnfc) ||
75524 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
75525 + (const void __user *)rxnfc) ||
75526 copy_in_user(&compat_rxnfc->fs.ring_cookie,
75527 &rxnfc->fs.ring_cookie,
75528 - (const void *)(&rxnfc->fs.location + 1) -
75529 - (const void *)&rxnfc->fs.ring_cookie) ||
75530 + (const void __user *)(&rxnfc->fs.location + 1) -
75531 + (const void __user *)&rxnfc->fs.ring_cookie) ||
75532 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
75533 sizeof(rxnfc->rule_cnt)))
75535 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
75538 err = dev_ioctl(net, cmd,
75539 - (struct ifreq __user __force *) &kifr);
75540 + (struct ifreq __force_user *) &kifr);
75544 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
75548 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
75549 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
75552 if (cmd == SIOCGIFMAP && !err) {
75553 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
75554 ret |= __get_user(rtdev, &(ur4->rt_dev));
75556 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
75557 - r4.rt_dev = (char __user __force *)devname;
75558 + r4.rt_dev = (char __force_user *)devname;
75562 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
75563 int __user *uoptlen;
75566 - uoptval = (char __user __force *) optval;
75567 - uoptlen = (int __user __force *) optlen;
75568 + uoptval = (char __force_user *) optval;
75569 + uoptlen = (int __force_user *) optlen;
75572 if (level == SOL_SOCKET)
75573 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
75574 char __user *uoptval;
75577 - uoptval = (char __user __force *) optval;
75578 + uoptval = (char __force_user *) optval;
75581 if (level == SOL_SOCKET)
75582 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
75583 index 00a1a2a..6a0138a 100644
75584 --- a/net/sunrpc/sched.c
75585 +++ b/net/sunrpc/sched.c
75586 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
75588 static void rpc_task_set_debuginfo(struct rpc_task *task)
75590 - static atomic_t rpc_pid;
75591 + static atomic_unchecked_t rpc_pid;
75593 - task->tk_pid = atomic_inc_return(&rpc_pid);
75594 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
75597 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
75598 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
75599 index 71bed1c..5dff36d 100644
75600 --- a/net/sunrpc/svcsock.c
75601 +++ b/net/sunrpc/svcsock.c
75602 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
75603 int buflen, unsigned int base)
75605 size_t save_iovlen;
75606 - void __user *save_iovbase;
75607 + void *save_iovbase;
75611 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
75612 index 09af4fa..77110a9 100644
75613 --- a/net/sunrpc/xprtrdma/svc_rdma.c
75614 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
75615 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
75616 static unsigned int min_max_inline = 4096;
75617 static unsigned int max_max_inline = 65536;
75619 -atomic_t rdma_stat_recv;
75620 -atomic_t rdma_stat_read;
75621 -atomic_t rdma_stat_write;
75622 -atomic_t rdma_stat_sq_starve;
75623 -atomic_t rdma_stat_rq_starve;
75624 -atomic_t rdma_stat_rq_poll;
75625 -atomic_t rdma_stat_rq_prod;
75626 -atomic_t rdma_stat_sq_poll;
75627 -atomic_t rdma_stat_sq_prod;
75628 +atomic_unchecked_t rdma_stat_recv;
75629 +atomic_unchecked_t rdma_stat_read;
75630 +atomic_unchecked_t rdma_stat_write;
75631 +atomic_unchecked_t rdma_stat_sq_starve;
75632 +atomic_unchecked_t rdma_stat_rq_starve;
75633 +atomic_unchecked_t rdma_stat_rq_poll;
75634 +atomic_unchecked_t rdma_stat_rq_prod;
75635 +atomic_unchecked_t rdma_stat_sq_poll;
75636 +atomic_unchecked_t rdma_stat_sq_prod;
75638 /* Temporary NFS request map and context caches */
75639 struct kmem_cache *svc_rdma_map_cachep;
75640 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
75644 - if (len && copy_to_user(buffer, str_buf, len))
75645 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
75649 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
75651 .procname = "rdma_stat_read",
75652 .data = &rdma_stat_read,
75653 - .maxlen = sizeof(atomic_t),
75654 + .maxlen = sizeof(atomic_unchecked_t),
75656 .proc_handler = read_reset_stat,
75659 .procname = "rdma_stat_recv",
75660 .data = &rdma_stat_recv,
75661 - .maxlen = sizeof(atomic_t),
75662 + .maxlen = sizeof(atomic_unchecked_t),
75664 .proc_handler = read_reset_stat,
75667 .procname = "rdma_stat_write",
75668 .data = &rdma_stat_write,
75669 - .maxlen = sizeof(atomic_t),
75670 + .maxlen = sizeof(atomic_unchecked_t),
75672 .proc_handler = read_reset_stat,
75675 .procname = "rdma_stat_sq_starve",
75676 .data = &rdma_stat_sq_starve,
75677 - .maxlen = sizeof(atomic_t),
75678 + .maxlen = sizeof(atomic_unchecked_t),
75680 .proc_handler = read_reset_stat,
75683 .procname = "rdma_stat_rq_starve",
75684 .data = &rdma_stat_rq_starve,
75685 - .maxlen = sizeof(atomic_t),
75686 + .maxlen = sizeof(atomic_unchecked_t),
75688 .proc_handler = read_reset_stat,
75691 .procname = "rdma_stat_rq_poll",
75692 .data = &rdma_stat_rq_poll,
75693 - .maxlen = sizeof(atomic_t),
75694 + .maxlen = sizeof(atomic_unchecked_t),
75696 .proc_handler = read_reset_stat,
75699 .procname = "rdma_stat_rq_prod",
75700 .data = &rdma_stat_rq_prod,
75701 - .maxlen = sizeof(atomic_t),
75702 + .maxlen = sizeof(atomic_unchecked_t),
75704 .proc_handler = read_reset_stat,
75707 .procname = "rdma_stat_sq_poll",
75708 .data = &rdma_stat_sq_poll,
75709 - .maxlen = sizeof(atomic_t),
75710 + .maxlen = sizeof(atomic_unchecked_t),
75712 .proc_handler = read_reset_stat,
75715 .procname = "rdma_stat_sq_prod",
75716 .data = &rdma_stat_sq_prod,
75717 - .maxlen = sizeof(atomic_t),
75718 + .maxlen = sizeof(atomic_unchecked_t),
75720 .proc_handler = read_reset_stat,
75722 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75723 index df67211..c354b13 100644
75724 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75725 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75726 @@ -499,7 +499,7 @@ next_sge:
75727 svc_rdma_put_context(ctxt, 0);
75730 - atomic_inc(&rdma_stat_read);
75731 + atomic_inc_unchecked(&rdma_stat_read);
75733 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
75734 chl_map->ch[ch_no].count -= read_wr.num_sge;
75735 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75737 list_del_init(&ctxt->dto_q);
75739 - atomic_inc(&rdma_stat_rq_starve);
75740 + atomic_inc_unchecked(&rdma_stat_rq_starve);
75741 clear_bit(XPT_DATA, &xprt->xpt_flags);
75744 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75745 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
75746 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
75747 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
75748 - atomic_inc(&rdma_stat_recv);
75749 + atomic_inc_unchecked(&rdma_stat_recv);
75751 /* Build up the XDR from the receive buffers. */
75752 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
75753 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75754 index 249a835..fb2794b 100644
75755 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75756 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75757 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
75758 write_wr.wr.rdma.remote_addr = to;
75761 - atomic_inc(&rdma_stat_write);
75762 + atomic_inc_unchecked(&rdma_stat_write);
75763 if (svc_rdma_send(xprt, &write_wr))
75766 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75767 index ba1296d..0fec1a5 100644
75768 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
75769 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75770 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75773 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
75774 - atomic_inc(&rdma_stat_rq_poll);
75775 + atomic_inc_unchecked(&rdma_stat_rq_poll);
75777 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
75778 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
75779 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75783 - atomic_inc(&rdma_stat_rq_prod);
75784 + atomic_inc_unchecked(&rdma_stat_rq_prod);
75786 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
75788 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75791 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
75792 - atomic_inc(&rdma_stat_sq_poll);
75793 + atomic_inc_unchecked(&rdma_stat_sq_poll);
75794 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
75795 if (wc.status != IB_WC_SUCCESS)
75796 /* Close the transport */
75797 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75801 - atomic_inc(&rdma_stat_sq_prod);
75802 + atomic_inc_unchecked(&rdma_stat_sq_prod);
75805 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
75806 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
75807 spin_lock_bh(&xprt->sc_lock);
75808 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
75809 spin_unlock_bh(&xprt->sc_lock);
75810 - atomic_inc(&rdma_stat_sq_starve);
75811 + atomic_inc_unchecked(&rdma_stat_sq_starve);
75813 /* See if we can opportunistically reap SQ WR to make room */
75815 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
75816 index e758139..d29ea47 100644
75817 --- a/net/sysctl_net.c
75818 +++ b/net/sysctl_net.c
75819 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
75820 struct ctl_table *table)
75822 /* Allow network administrator to have same access as root. */
75823 - if (capable(CAP_NET_ADMIN)) {
75824 + if (capable_nolog(CAP_NET_ADMIN)) {
75825 int mode = (table->mode >> 6) & 7;
75826 return (mode << 6) | (mode << 3) | mode;
75828 diff --git a/net/tipc/link.c b/net/tipc/link.c
75829 index ae98a72..7bb6056 100644
75830 --- a/net/tipc/link.c
75831 +++ b/net/tipc/link.c
75832 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
75833 struct tipc_msg fragm_hdr;
75834 struct sk_buff *buf, *buf_chain, *prev;
75835 u32 fragm_crs, fragm_rest, hsz, sect_rest;
75836 - const unchar *sect_crs;
75837 + const unchar __user *sect_crs;
75841 @@ -1247,7 +1247,7 @@ again:
75844 sect_rest = msg_sect[++curr_sect].iov_len;
75845 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
75846 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
75849 if (sect_rest < fragm_rest)
75850 @@ -1266,7 +1266,7 @@ error:
75853 skb_copy_to_linear_data_offset(buf, fragm_crs,
75855 + (const void __force_kernel *)sect_crs, sz);
75859 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
75860 index 83d5096..dcba497 100644
75861 --- a/net/tipc/msg.c
75862 +++ b/net/tipc/msg.c
75863 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
75864 msg_sect[cnt].iov_len);
75866 skb_copy_to_linear_data_offset(*buf, pos,
75867 - msg_sect[cnt].iov_base,
75868 + (const void __force_kernel *)msg_sect[cnt].iov_base,
75869 msg_sect[cnt].iov_len);
75870 pos += msg_sect[cnt].iov_len;
75872 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
75873 index 1983717..4d6102c 100644
75874 --- a/net/tipc/subscr.c
75875 +++ b/net/tipc/subscr.c
75876 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
75878 struct iovec msg_sect;
75880 - msg_sect.iov_base = (void *)&sub->evt;
75881 + msg_sect.iov_base = (void __force_user *)&sub->evt;
75882 msg_sect.iov_len = sizeof(struct tipc_event);
75884 sub->evt.event = htohl(event, sub->swap);
75885 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
75886 index d99678a..3514a21 100644
75887 --- a/net/unix/af_unix.c
75888 +++ b/net/unix/af_unix.c
75889 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
75890 err = -ECONNREFUSED;
75891 if (!S_ISSOCK(inode->i_mode))
75894 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
75899 u = unix_find_socket_byinode(inode);
75902 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
75904 struct dentry *dentry;
75905 dentry = unix_sk(u)->dentry;
75907 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
75914 touch_atime(unix_sk(u)->mnt, dentry);
75916 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
75917 err = security_path_mknod(&path, dentry, mode, 0);
75919 goto out_mknod_drop_write;
75920 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
75922 + goto out_mknod_drop_write;
75924 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
75925 out_mknod_drop_write:
75926 mnt_drop_write(path.mnt);
75928 goto out_mknod_dput;
75930 + gr_handle_create(dentry, path.mnt);
75932 mutex_unlock(&path.dentry->d_inode->i_mutex);
75934 path.dentry = dentry;
75935 diff --git a/net/wireless/core.h b/net/wireless/core.h
75936 index b9ec306..b4a563e 100644
75937 --- a/net/wireless/core.h
75938 +++ b/net/wireless/core.h
75939 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
75942 /* rfkill support */
75943 - struct rfkill_ops rfkill_ops;
75944 + rfkill_ops_no_const rfkill_ops;
75945 struct rfkill *rfkill;
75946 struct work_struct rfkill_sync;
75948 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
75949 index 0af7f54..c916d2f 100644
75950 --- a/net/wireless/wext-core.c
75951 +++ b/net/wireless/wext-core.c
75952 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75955 /* Support for very large requests */
75956 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
75957 - (user_length > descr->max_tokens)) {
75958 + if (user_length > descr->max_tokens) {
75959 /* Allow userspace to GET more than max so
75960 * we can support any size GET requests.
75961 * There is still a limit : -ENOMEM.
75962 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75966 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
75968 - * If this is a GET, but not NOMAX, it means that the extra
75969 - * data is not bounded by userspace, but by max_tokens. Thus
75970 - * set the length to max_tokens. This matches the extra data
75972 - * The driver should fill it with the number of tokens it
75973 - * provided, and it may check iwp->length rather than having
75974 - * knowledge of max_tokens. If the driver doesn't change the
75975 - * iwp->length, this ioctl just copies back max_token tokens
75976 - * filled with zeroes. Hopefully the driver isn't claiming
75977 - * them to be valid data.
75979 - iwp->length = descr->max_tokens;
75982 err = handler(dev, info, (union iwreq_data *) iwp, extra);
75984 iwp->length += essid_compat;
75985 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
75986 index 9049a5c..cfa6f5c 100644
75987 --- a/net/xfrm/xfrm_policy.c
75988 +++ b/net/xfrm/xfrm_policy.c
75989 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
75991 policy->walk.dead = 1;
75993 - atomic_inc(&policy->genid);
75994 + atomic_inc_unchecked(&policy->genid);
75996 if (del_timer(&policy->timer))
75997 xfrm_pol_put(policy);
75998 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
75999 hlist_add_head(&policy->bydst, chain);
76000 xfrm_pol_hold(policy);
76001 net->xfrm.policy_count[dir]++;
76002 - atomic_inc(&flow_cache_genid);
76003 + atomic_inc_unchecked(&flow_cache_genid);
76005 __xfrm_policy_unlink(delpol, dir);
76006 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
76007 @@ -1530,7 +1530,7 @@ free_dst:
76013 xfrm_dst_alloc_copy(void **target, const void *src, int size)
76016 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
76022 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
76024 #ifdef CONFIG_XFRM_SUB_POLICY
76025 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
76031 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
76033 #ifdef CONFIG_XFRM_SUB_POLICY
76034 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
76036 xdst->num_pols = num_pols;
76037 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
76038 - xdst->policy_genid = atomic_read(&pols[0]->genid);
76039 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
76043 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
76044 if (xdst->xfrm_genid != dst->xfrm->genid)
76046 if (xdst->num_pols > 0 &&
76047 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
76048 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
76051 mtu = dst_mtu(dst->child);
76052 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
76053 sizeof(pol->xfrm_vec[i].saddr));
76054 pol->xfrm_vec[i].encap_family = mp->new_family;
76055 /* flush bundles */
76056 - atomic_inc(&pol->genid);
76057 + atomic_inc_unchecked(&pol->genid);
76061 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
76062 index d2b366c..51ff91ebc 100644
76063 --- a/scripts/Makefile.build
76064 +++ b/scripts/Makefile.build
76065 @@ -109,7 +109,7 @@ endif
76068 # Do not include host rules unless needed
76069 -ifneq ($(hostprogs-y)$(hostprogs-m),)
76070 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
76071 include scripts/Makefile.host
76074 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
76075 index 686cb0d..9d653bf 100644
76076 --- a/scripts/Makefile.clean
76077 +++ b/scripts/Makefile.clean
76078 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
76079 __clean-files := $(extra-y) $(always) \
76080 $(targets) $(clean-files) \
76082 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
76083 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
76084 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
76086 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
76088 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
76089 index 1ac414f..a1c1451 100644
76090 --- a/scripts/Makefile.host
76091 +++ b/scripts/Makefile.host
76093 # Note: Shared libraries consisting of C++ files are not supported
76095 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
76096 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
76099 # Executables compiled from a single .c file
76100 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
76101 # Shared libaries (only .c supported)
76102 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
76103 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
76104 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
76105 # Remove .so files from "xxx-objs"
76106 host-cobjs := $(filter-out %.so,$(host-cobjs))
76108 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
76109 index cb1f50c..cef2a7c 100644
76110 --- a/scripts/basic/fixdep.c
76111 +++ b/scripts/basic/fixdep.c
76112 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
76114 * Lookup a value in the configuration string.
76116 -static int is_defined_config(const char *name, int len, unsigned int hash)
76117 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
76121 @@ -211,10 +211,10 @@ static void clear_config(void)
76123 * Record the use of a CONFIG_* word.
76125 -static void use_config(const char *m, int slen)
76126 +static void use_config(const char *m, unsigned int slen)
76128 unsigned int hash = strhash(m, slen);
76130 + unsigned int c, i;
76132 if (is_defined_config(m, slen, hash))
76134 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
76136 static void parse_config_file(const char *map, size_t len)
76138 - const int *end = (const int *) (map + len);
76139 + const unsigned int *end = (const unsigned int *) (map + len);
76140 /* start at +1, so that p can never be < map */
76141 - const int *m = (const int *) map + 1;
76142 + const unsigned int *m = (const unsigned int *) map + 1;
76145 for (; m < end; m++) {
76146 @@ -406,7 +406,7 @@ static void print_deps(void)
76147 static void traps(void)
76149 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
76150 - int *p = (int *)test;
76151 + unsigned int *p = (unsigned int *)test;
76153 if (*p != INT_CONF) {
76154 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
76155 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
76156 new file mode 100644
76157 index 0000000..8729101
76159 +++ b/scripts/gcc-plugin.sh
76162 +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"
76163 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
76164 index f936d1f..a66d95f 100644
76165 --- a/scripts/mod/file2alias.c
76166 +++ b/scripts/mod/file2alias.c
76167 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
76168 unsigned long size, unsigned long id_size,
76174 if (size % id_size || size < id_size) {
76175 if (cross_build != 0)
76176 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
76177 /* USB is special because the bcdDevice can be matched against a numeric range */
76178 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
76179 static void do_usb_entry(struct usb_device_id *id,
76180 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
76181 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
76182 unsigned char range_lo, unsigned char range_hi,
76183 unsigned char max, struct module *mod)
76185 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
76187 unsigned int devlo, devhi;
76188 unsigned char chi, clo, max;
76190 + unsigned int ndigits;
76192 id->match_flags = TO_NATIVE(id->match_flags);
76193 id->idVendor = TO_NATIVE(id->idVendor);
76194 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
76195 for (i = 0; i < count; i++) {
76196 const char *id = (char *)devs[i].id;
76197 char acpi_id[sizeof(devs[0].id)];
76201 buf_printf(&mod->dev_table_buf,
76202 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
76203 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
76205 for (j = 0; j < PNP_MAX_DEVICES; j++) {
76206 const char *id = (char *)card->devs[j].id;
76208 + unsigned int i2, j2;
76212 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
76213 /* add an individual alias for every device entry */
76215 char acpi_id[sizeof(card->devs[0].id)];
76219 buf_printf(&mod->dev_table_buf,
76220 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
76221 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
76222 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
76226 + unsigned int i, j;
76228 sprintf(alias, "dmi*");
76230 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
76231 index 2bd594e..d43245e 100644
76232 --- a/scripts/mod/modpost.c
76233 +++ b/scripts/mod/modpost.c
76234 @@ -919,6 +919,7 @@ enum mismatch {
76235 ANY_INIT_TO_ANY_EXIT,
76236 ANY_EXIT_TO_ANY_INIT,
76237 EXPORT_TO_INIT_EXIT,
76241 struct sectioncheck {
76242 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
76243 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
76244 .mismatch = EXPORT_TO_INIT_EXIT,
76245 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
76247 +/* Do not reference code from writable data */
76249 + .fromsec = { DATA_SECTIONS, NULL },
76250 + .tosec = { TEXT_SECTIONS, NULL },
76251 + .mismatch = DATA_TO_TEXT
76255 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
76257 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
76259 - if (sym->st_value == addr)
76261 /* Find a symbol nearby - addr are maybe negative */
76262 d = sym->st_value - addr;
76266 d = addr - sym->st_value;
76267 if (d < distance) {
76268 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
76269 tosym, prl_to, prl_to, tosym);
76272 + case DATA_TO_TEXT:
76275 + "The variable %s references\n"
76276 + "the %s %s%s%s\n",
76277 + fromsym, to, sec2annotation(tosec), tosym, to_p);
76281 fprintf(stderr, "\n");
76283 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
76284 static void check_sec_ref(struct module *mod, const char *modname,
76285 struct elf_info *elf)
76289 Elf_Shdr *sechdrs = elf->sechdrs;
76291 /* Walk through all sections */
76292 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
76296 -void buf_write(struct buffer *buf, const char *s, int len)
76297 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
76299 if (buf->size - buf->pos < len) {
76300 buf->size += len + SZ;
76301 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
76302 if (fstat(fileno(file), &st) < 0)
76305 - if (st.st_size != b->pos)
76306 + if (st.st_size != (off_t)b->pos)
76309 tmp = NOFAIL(malloc(b->pos));
76310 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
76311 index 2031119..b5433af 100644
76312 --- a/scripts/mod/modpost.h
76313 +++ b/scripts/mod/modpost.h
76314 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
76320 + unsigned int pos;
76321 + unsigned int size;
76324 void __attribute__((format(printf, 2, 3)))
76325 buf_printf(struct buffer *buf, const char *fmt, ...);
76328 -buf_write(struct buffer *buf, const char *s, int len);
76329 +buf_write(struct buffer *buf, const char *s, unsigned int len);
76332 struct module *next;
76333 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
76334 index 9dfcd6d..099068e 100644
76335 --- a/scripts/mod/sumversion.c
76336 +++ b/scripts/mod/sumversion.c
76337 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
76341 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
76342 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
76343 warn("writing sum in %s failed: %s\n",
76344 filename, strerror(errno));
76346 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
76347 index 5c11312..72742b5 100644
76348 --- a/scripts/pnmtologo.c
76349 +++ b/scripts/pnmtologo.c
76350 @@ -237,14 +237,14 @@ static void write_header(void)
76351 fprintf(out, " * Linux logo %s\n", logoname);
76352 fputs(" */\n\n", out);
76353 fputs("#include <linux/linux_logo.h>\n\n", out);
76354 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
76355 + fprintf(out, "static unsigned char %s_data[] = {\n",
76359 static void write_footer(void)
76361 fputs("\n};\n\n", out);
76362 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
76363 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
76364 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
76365 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
76366 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
76367 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
76368 fputs("\n};\n\n", out);
76370 /* write logo clut */
76371 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
76372 + fprintf(out, "static unsigned char %s_clut[] = {\n",
76375 for (i = 0; i < logo_clutsize; i++) {
76376 diff --git a/security/Kconfig b/security/Kconfig
76377 index 51bd5a0..eeabc9f 100644
76378 --- a/security/Kconfig
76379 +++ b/security/Kconfig
76382 menu "Security options"
76384 +source grsecurity/Kconfig
76388 + config ARCH_TRACK_EXEC_LIMIT
76391 + config PAX_KERNEXEC_PLUGIN
76394 + config PAX_PER_CPU_PGD
76397 + config TASK_SIZE_MAX_SHIFT
76399 + depends on X86_64
76400 + default 47 if !PAX_PER_CPU_PGD
76401 + default 42 if PAX_PER_CPU_PGD
76403 + config PAX_ENABLE_PAE
76405 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
76408 + bool "Enable various PaX features"
76409 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
76411 + This allows you to enable various PaX features. PaX adds
76412 + intrusion prevention mechanisms to the kernel that reduce
76413 + the risks posed by exploitable memory corruption bugs.
76415 +menu "PaX Control"
76418 +config PAX_SOFTMODE
76419 + bool 'Support soft mode'
76421 + Enabling this option will allow you to run PaX in soft mode, that
76422 + is, PaX features will not be enforced by default, only on executables
76423 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
76424 + support as they are the only way to mark executables for soft mode use.
76426 + Soft mode can be activated by using the "pax_softmode=1" kernel command
76427 + line option on boot. Furthermore you can control various PaX features
76428 + at runtime via the entries in /proc/sys/kernel/pax.
76431 + bool 'Use legacy ELF header marking'
76433 + Enabling this option will allow you to control PaX features on
76434 + a per executable basis via the 'chpax' utility available at
76435 + http://pax.grsecurity.net/. The control flags will be read from
76436 + an otherwise reserved part of the ELF header. This marking has
76437 + numerous drawbacks (no support for soft-mode, toolchain does not
76438 + know about the non-standard use of the ELF header) therefore it
76439 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
76442 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76443 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
76444 + option otherwise they will not get any protection.
76446 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
76447 + support as well, they will override the legacy EI_PAX marks.
76449 +config PAX_PT_PAX_FLAGS
76450 + bool 'Use ELF program header marking'
76452 + Enabling this option will allow you to control PaX features on
76453 + a per executable basis via the 'paxctl' utility available at
76454 + http://pax.grsecurity.net/. The control flags will be read from
76455 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
76456 + has the benefits of supporting both soft mode and being fully
76457 + integrated into the toolchain (the binutils patch is available
76458 + from http://pax.grsecurity.net).
76460 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76461 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
76462 + support otherwise they will not get any protection.
76464 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
76465 + must make sure that the marks are the same if a binary has both marks.
76467 + Note that if you enable the legacy EI_PAX marking support as well,
76468 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
76470 +config PAX_XATTR_PAX_FLAGS
76471 + bool 'Use filesystem extended attributes marking'
76472 + depends on EXPERT
76473 + select CIFS_XATTR if CIFS
76474 + select EXT2_FS_XATTR if EXT2_FS
76475 + select EXT3_FS_XATTR if EXT3_FS
76476 + select EXT4_FS_XATTR if EXT4_FS
76477 + select JFFS2_FS_XATTR if JFFS2_FS
76478 + select REISERFS_FS_XATTR if REISERFS_FS
76479 + select SQUASHFS_XATTR if SQUASHFS
76480 + select TMPFS_XATTR if TMPFS
76481 + select UBIFS_FS_XATTR if UBIFS_FS
76483 + Enabling this option will allow you to control PaX features on
76484 + a per executable basis via the 'setfattr' utility. The control
76485 + flags will be read from the user.pax.flags extended attribute of
76486 + the file. This marking has the benefit of supporting binary-only
76487 + applications that self-check themselves (e.g., skype) and would
76488 + not tolerate chpax/paxctl changes. The main drawback is that
76489 + extended attributes are not supported by some filesystems (e.g.,
76490 + isofs, udf, vfat) so copying files through such filesystems will
76491 + lose the extended attributes and these PaX markings.
76493 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76494 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
76495 + support otherwise they will not get any protection.
76497 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
76498 + must make sure that the marks are the same if a binary has both marks.
76500 + Note that if you enable the legacy EI_PAX marking support as well,
76501 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
76504 + prompt 'MAC system integration'
76505 + default PAX_HAVE_ACL_FLAGS
76507 + Mandatory Access Control systems have the option of controlling
76508 + PaX flags on a per executable basis, choose the method supported
76509 + by your particular system.
76511 + - "none": if your MAC system does not interact with PaX,
76512 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
76513 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
76515 + NOTE: this option is for developers/integrators only.
76517 + config PAX_NO_ACL_FLAGS
76520 + config PAX_HAVE_ACL_FLAGS
76523 + config PAX_HOOK_ACL_FLAGS
76529 +menu "Non-executable pages"
76533 + bool "Enforce non-executable pages"
76534 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
76536 + By design some architectures do not allow for protecting memory
76537 + pages against execution or even if they do, Linux does not make
76538 + use of this feature. In practice this means that if a page is
76539 + readable (such as the stack or heap) it is also executable.
76541 + There is a well known exploit technique that makes use of this
76542 + fact and a common programming mistake where an attacker can
76543 + introduce code of his choice somewhere in the attacked program's
76544 + memory (typically the stack or the heap) and then execute it.
76546 + If the attacked program was running with different (typically
76547 + higher) privileges than that of the attacker, then he can elevate
76548 + his own privilege level (e.g. get a root shell, write to files for
76549 + which he does not have write access to, etc).
76551 + Enabling this option will let you choose from various features
76552 + that prevent the injection and execution of 'foreign' code in
76555 + This will also break programs that rely on the old behaviour and
76556 + expect that dynamically allocated memory via the malloc() family
76557 + of functions is executable (which it is not). Notable examples
76558 + are the XFree86 4.x server, the java runtime and wine.
76560 +config PAX_PAGEEXEC
76561 + bool "Paging based non-executable pages"
76562 + 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)
76563 + select S390_SWITCH_AMODE if S390
76564 + select S390_EXEC_PROTECT if S390
76565 + select ARCH_TRACK_EXEC_LIMIT if X86_32
76567 + This implementation is based on the paging feature of the CPU.
76568 + On i386 without hardware non-executable bit support there is a
76569 + variable but usually low performance impact, however on Intel's
76570 + P4 core based CPUs it is very high so you should not enable this
76571 + for kernels meant to be used on such CPUs.
76573 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
76574 + with hardware non-executable bit support there is no performance
76575 + impact, on ppc the impact is negligible.
76577 + Note that several architectures require various emulations due to
76578 + badly designed userland ABIs, this will cause a performance impact
76579 + but will disappear as soon as userland is fixed. For example, ppc
76580 + userland MUST have been built with secure-plt by a recent toolchain.
76582 +config PAX_SEGMEXEC
76583 + bool "Segmentation based non-executable pages"
76584 + depends on PAX_NOEXEC && X86_32
76586 + This implementation is based on the segmentation feature of the
76587 + CPU and has a very small performance impact, however applications
76588 + will be limited to a 1.5 GB address space instead of the normal
76591 +config PAX_EMUTRAMP
76592 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
76593 + default y if PARISC
76595 + There are some programs and libraries that for one reason or
76596 + another attempt to execute special small code snippets from
76597 + non-executable memory pages. Most notable examples are the
76598 + signal handler return code generated by the kernel itself and
76599 + the GCC trampolines.
76601 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
76602 + such programs will no longer work under your kernel.
76604 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
76605 + utilities to enable trampoline emulation for the affected programs
76606 + yet still have the protection provided by the non-executable pages.
76608 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
76609 + your system will not even boot.
76611 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
76612 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
76613 + for the affected files.
76615 + NOTE: enabling this feature *may* open up a loophole in the
76616 + protection provided by non-executable pages that an attacker
76617 + could abuse. Therefore the best solution is to not have any
76618 + files on your system that would require this option. This can
76619 + be achieved by not using libc5 (which relies on the kernel
76620 + signal handler return code) and not using or rewriting programs
76621 + that make use of the nested function implementation of GCC.
76622 + Skilled users can just fix GCC itself so that it implements
76623 + nested function calls in a way that does not interfere with PaX.
76625 +config PAX_EMUSIGRT
76626 + bool "Automatically emulate sigreturn trampolines"
76627 + depends on PAX_EMUTRAMP && PARISC
76630 + Enabling this option will have the kernel automatically detect
76631 + and emulate signal return trampolines executing on the stack
76632 + that would otherwise lead to task termination.
76634 + This solution is intended as a temporary one for users with
76635 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
76636 + Modula-3 runtime, etc) or executables linked to such, basically
76637 + everything that does not specify its own SA_RESTORER function in
76638 + normal executable memory like glibc 2.1+ does.
76640 + On parisc you MUST enable this option, otherwise your system will
76643 + NOTE: this feature cannot be disabled on a per executable basis
76644 + and since it *does* open up a loophole in the protection provided
76645 + by non-executable pages, the best solution is to not have any
76646 + files on your system that would require this option.
76648 +config PAX_MPROTECT
76649 + bool "Restrict mprotect()"
76650 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
76652 + Enabling this option will prevent programs from
76653 + - changing the executable status of memory pages that were
76654 + not originally created as executable,
76655 + - making read-only executable pages writable again,
76656 + - creating executable pages from anonymous memory,
76657 + - making read-only-after-relocations (RELRO) data pages writable again.
76659 + You should say Y here to complete the protection provided by
76660 + the enforcement of non-executable pages.
76662 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76663 + this feature on a per file basis.
76665 +config PAX_MPROTECT_COMPAT
76666 + bool "Use legacy/compat protection demoting (read help)"
76667 + depends on PAX_MPROTECT
76670 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
76671 + by sending the proper error code to the application. For some broken
76672 + userland, this can cause problems with Python or other applications. The
76673 + current implementation however allows for applications like clamav to
76674 + detect if JIT compilation/execution is allowed and to fall back gracefully
76675 + to an interpreter-based mode if it does not. While we encourage everyone
76676 + to use the current implementation as-is and push upstream to fix broken
76677 + userland (note that the RWX logging option can assist with this), in some
76678 + environments this may not be possible. Having to disable MPROTECT
76679 + completely on certain binaries reduces the security benefit of PaX,
76680 + so this option is provided for those environments to revert to the old
76683 +config PAX_ELFRELOCS
76684 + bool "Allow ELF text relocations (read help)"
76685 + depends on PAX_MPROTECT
76688 + Non-executable pages and mprotect() restrictions are effective
76689 + in preventing the introduction of new executable code into an
76690 + attacked task's address space. There remain only two venues
76691 + for this kind of attack: if the attacker can execute already
76692 + existing code in the attacked task then he can either have it
76693 + create and mmap() a file containing his code or have it mmap()
76694 + an already existing ELF library that does not have position
76695 + independent code in it and use mprotect() on it to make it
76696 + writable and copy his code there. While protecting against
76697 + the former approach is beyond PaX, the latter can be prevented
76698 + by having only PIC ELF libraries on one's system (which do not
76699 + need to relocate their code). If you are sure this is your case,
76700 + as is the case with all modern Linux distributions, then leave
76701 + this option disabled. You should say 'n' here.
76703 +config PAX_ETEXECRELOCS
76704 + bool "Allow ELF ET_EXEC text relocations"
76705 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
76706 + select PAX_ELFRELOCS
76709 + On some architectures there are incorrectly created applications
76710 + that require text relocations and would not work without enabling
76711 + this option. If you are an alpha, ia64 or parisc user, you should
76712 + enable this option and disable it once you have made sure that
76713 + none of your applications need it.
76716 + bool "Automatically emulate ELF PLT"
76717 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
76720 + Enabling this option will have the kernel automatically detect
76721 + and emulate the Procedure Linkage Table entries in ELF files.
76722 + On some architectures such entries are in writable memory, and
76723 + become non-executable leading to task termination. Therefore
76724 + it is mandatory that you enable this option on alpha, parisc,
76725 + sparc and sparc64, otherwise your system would not even boot.
76727 + NOTE: this feature *does* open up a loophole in the protection
76728 + provided by the non-executable pages, therefore the proper
76729 + solution is to modify the toolchain to produce a PLT that does
76730 + not need to be writable.
76732 +config PAX_DLRESOLVE
76733 + bool 'Emulate old glibc resolver stub'
76734 + depends on PAX_EMUPLT && SPARC
76737 + This option is needed if userland has an old glibc (before 2.4)
76738 + that puts a 'save' instruction into the runtime generated resolver
76739 + stub that needs special emulation.
76741 +config PAX_KERNEXEC
76742 + bool "Enforce non-executable kernel pages"
76743 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
76744 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
76745 + select PAX_KERNEXEC_PLUGIN if X86_64
76747 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
76748 + that is, enabling this option will make it harder to inject
76749 + and execute 'foreign' code in kernel memory itself.
76751 + Note that on x86_64 kernels there is a known regression when
76752 + this feature and KVM/VMX are both enabled in the host kernel.
76755 + prompt "Return Address Instrumentation Method"
76756 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
76757 + depends on PAX_KERNEXEC_PLUGIN
76759 + Select the method used to instrument function pointer dereferences.
76760 + Note that binary modules cannot be instrumented by this approach.
76762 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
76765 + This method is compatible with binary only modules but has
76766 + a higher runtime overhead.
76768 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
76770 + depends on !PARAVIRT
76772 + This method is incompatible with binary only modules but has
76773 + a lower runtime overhead.
76776 +config PAX_KERNEXEC_PLUGIN_METHOD
76778 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
76779 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
76782 +config PAX_KERNEXEC_MODULE_TEXT
76783 + int "Minimum amount of memory reserved for module code"
76785 + depends on PAX_KERNEXEC && X86_32 && MODULES
76787 + Due to implementation details the kernel must reserve a fixed
76788 + amount of memory for module code at compile time that cannot be
76789 + changed at runtime. Here you can specify the minimum amount
76790 + in MB that will be reserved. Due to the same implementation
76791 + details this size will always be rounded up to the next 2/4 MB
76792 + boundary (depends on PAE) so the actually available memory for
76793 + module code will usually be more than this minimum.
76795 + The default 4 MB should be enough for most users but if you have
76796 + an excessive number of modules (e.g., most distribution configs
76797 + compile many drivers as modules) or use huge modules such as
76798 + nvidia's kernel driver, you will need to adjust this amount.
76799 + A good rule of thumb is to look at your currently loaded kernel
76800 + modules and add up their sizes.
76804 +menu "Address Space Layout Randomization"
76808 + bool "Address Space Layout Randomization"
76810 + Many if not most exploit techniques rely on the knowledge of
76811 + certain addresses in the attacked program. The following options
76812 + will allow the kernel to apply a certain amount of randomization
76813 + to specific parts of the program thereby forcing an attacker to
76814 + guess them in most cases. Any failed guess will most likely crash
76815 + the attacked program which allows the kernel to detect such attempts
76816 + and react on them. PaX itself provides no reaction mechanisms,
76817 + instead it is strongly encouraged that you make use of Nergal's
76818 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
76819 + (http://www.grsecurity.net/) built-in crash detection features or
76820 + develop one yourself.
76822 + By saying Y here you can choose to randomize the following areas:
76823 + - top of the task's kernel stack
76824 + - top of the task's userland stack
76825 + - base address for mmap() requests that do not specify one
76826 + (this includes all libraries)
76827 + - base address of the main executable
76829 + It is strongly recommended to say Y here as address space layout
76830 + randomization has negligible impact on performance yet it provides
76831 + a very effective protection.
76833 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76834 + this feature on a per file basis.
76836 +config PAX_RANDKSTACK
76837 + bool "Randomize kernel stack base"
76838 + depends on X86_TSC && X86
76840 + By saying Y here the kernel will randomize every task's kernel
76841 + stack on every system call. This will not only force an attacker
76842 + to guess it but also prevent him from making use of possible
76843 + leaked information about it.
76845 + Since the kernel stack is a rather scarce resource, randomization
76846 + may cause unexpected stack overflows, therefore you should very
76847 + carefully test your system. Note that once enabled in the kernel
76848 + configuration, this feature cannot be disabled on a per file basis.
76850 +config PAX_RANDUSTACK
76851 + bool "Randomize user stack base"
76852 + depends on PAX_ASLR
76854 + By saying Y here the kernel will randomize every task's userland
76855 + stack. The randomization is done in two steps where the second
76856 + one may apply a big amount of shift to the top of the stack and
76857 + cause problems for programs that want to use lots of memory (more
76858 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
76859 + For this reason the second step can be controlled by 'chpax' or
76860 + 'paxctl' on a per file basis.
76862 +config PAX_RANDMMAP
76863 + bool "Randomize mmap() base"
76864 + depends on PAX_ASLR
76866 + By saying Y here the kernel will use a randomized base address for
76867 + mmap() requests that do not specify one themselves. As a result
76868 + all dynamically loaded libraries will appear at random addresses
76869 + and therefore be harder to exploit by a technique where an attacker
76870 + attempts to execute library code for his purposes (e.g. spawn a
76871 + shell from an exploited program that is running at an elevated
76872 + privilege level).
76874 + Furthermore, if a program is relinked as a dynamic ELF file, its
76875 + base address will be randomized as well, completing the full
76876 + randomization of the address space layout. Attacking such programs
76877 + becomes a guess game. You can find an example of doing this at
76878 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
76879 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
76881 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
76882 + feature on a per file basis.
76886 +menu "Miscellaneous hardening features"
76888 +config PAX_MEMORY_SANITIZE
76889 + bool "Sanitize all freed memory"
76890 + depends on !HIBERNATION
76892 + By saying Y here the kernel will erase memory pages as soon as they
76893 + are freed. This in turn reduces the lifetime of data stored in the
76894 + pages, making it less likely that sensitive information such as
76895 + passwords, cryptographic secrets, etc stay in memory for too long.
76897 + This is especially useful for programs whose runtime is short, long
76898 + lived processes and the kernel itself benefit from this as long as
76899 + they operate on whole memory pages and ensure timely freeing of pages
76900 + that may hold sensitive information.
76902 + The tradeoff is performance impact, on a single CPU system kernel
76903 + compilation sees a 3% slowdown, other systems and workloads may vary
76904 + and you are advised to test this feature on your expected workload
76905 + before deploying it.
76907 + Note that this feature does not protect data stored in live pages,
76908 + e.g., process memory swapped to disk may stay there for a long time.
76910 +config PAX_MEMORY_STACKLEAK
76911 + bool "Sanitize kernel stack"
76914 + By saying Y here the kernel will erase the kernel stack before it
76915 + returns from a system call. This in turn reduces the information
76916 + that a kernel stack leak bug can reveal.
76918 + Note that such a bug can still leak information that was put on
76919 + the stack by the current system call (the one eventually triggering
76920 + the bug) but traces of earlier system calls on the kernel stack
76921 + cannot leak anymore.
76923 + The tradeoff is performance impact: on a single CPU system kernel
76924 + compilation sees a 1% slowdown, other systems and workloads may vary
76925 + and you are advised to test this feature on your expected workload
76926 + before deploying it.
76928 + Note: full support for this feature requires gcc with plugin support
76929 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
76930 + versions means that functions with large enough stack frames may
76931 + leave uninitialized memory behind that may be exposed to a later
76932 + syscall leaking the stack.
76934 +config PAX_MEMORY_UDEREF
76935 + bool "Prevent invalid userland pointer dereference"
76936 + depends on X86 && !UML_X86 && !XEN
76937 + select PAX_PER_CPU_PGD if X86_64
76939 + By saying Y here the kernel will be prevented from dereferencing
76940 + userland pointers in contexts where the kernel expects only kernel
76941 + pointers. This is both a useful runtime debugging feature and a
76942 + security measure that prevents exploiting a class of kernel bugs.
76944 + The tradeoff is that some virtualization solutions may experience
76945 + a huge slowdown and therefore you should not enable this feature
76946 + for kernels meant to run in such environments. Whether a given VM
76947 + solution is affected or not is best determined by simply trying it
76948 + out, the performance impact will be obvious right on boot as this
76949 + mechanism engages from very early on. A good rule of thumb is that
76950 + VMs running on CPUs without hardware virtualization support (i.e.,
76951 + the majority of IA-32 CPUs) will likely experience the slowdown.
76953 +config PAX_REFCOUNT
76954 + bool "Prevent various kernel object reference counter overflows"
76955 + depends on GRKERNSEC && (X86 || SPARC64)
76957 + By saying Y here the kernel will detect and prevent overflowing
76958 + various (but not all) kinds of object reference counters. Such
76959 + overflows can normally occur due to bugs only and are often, if
76960 + not always, exploitable.
76962 + The tradeoff is that data structures protected by an overflowed
76963 + refcount will never be freed and therefore will leak memory. Note
76964 + that this leak also happens even without this protection but in
76965 + that case the overflow can eventually trigger the freeing of the
76966 + data structure while it is still being used elsewhere, resulting
76967 + in the exploitable situation that this feature prevents.
76969 + Since this has a negligible performance impact, you should enable
76972 +config PAX_USERCOPY
76973 + bool "Harden heap object copies between kernel and userland"
76974 + depends on X86 || PPC || SPARC || ARM
76975 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
76977 + By saying Y here the kernel will enforce the size of heap objects
76978 + when they are copied in either direction between the kernel and
76979 + userland, even if only a part of the heap object is copied.
76981 + Specifically, this checking prevents information leaking from the
76982 + kernel heap during kernel to userland copies (if the kernel heap
76983 + object is otherwise fully initialized) and prevents kernel heap
76984 + overflows during userland to kernel copies.
76986 + Note that the current implementation provides the strictest bounds
76987 + checks for the SLUB allocator.
76989 + Enabling this option also enables per-slab cache protection against
76990 + data in a given cache being copied into/out of via userland
76991 + accessors. Though the whitelist of regions will be reduced over
76992 + time, it notably protects important data structures like task structs.
76994 + If frame pointers are enabled on x86, this option will also restrict
76995 + copies into and out of the kernel stack to local variables within a
76998 + Since this has a negligible performance impact, you should enable
77006 bool "Enable access key retention support"
77008 @@ -169,7 +790,7 @@ config INTEL_TXT
77009 config LSM_MMAP_MIN_ADDR
77010 int "Low address space for LSM to protect from user allocation"
77011 depends on SECURITY && SECURITY_SELINUX
77012 - default 32768 if ARM
77013 + default 32768 if ALPHA || ARM || PARISC || SPARC32
77016 This is the portion of low virtual memory which should be protected
77017 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
77018 index 3783202..1852837 100644
77019 --- a/security/apparmor/lsm.c
77020 +++ b/security/apparmor/lsm.c
77021 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
77025 -static struct security_operations apparmor_ops = {
77026 +static struct security_operations apparmor_ops __read_only = {
77027 .name = "apparmor",
77029 .ptrace_access_check = apparmor_ptrace_access_check,
77030 diff --git a/security/commoncap.c b/security/commoncap.c
77031 index ee4f848..a320c64 100644
77032 --- a/security/commoncap.c
77033 +++ b/security/commoncap.c
77035 #include <linux/prctl.h>
77036 #include <linux/securebits.h>
77037 #include <linux/user_namespace.h>
77038 +#include <net/sock.h>
77041 * If a non-root user executes a setuid-root binary in
77042 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
77044 int cap_netlink_recv(struct sk_buff *skb, int cap)
77046 - if (!cap_raised(current_cap(), cap))
77047 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
77051 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
77053 const struct cred *cred = current_cred();
77055 + if (gr_acl_enable_at_secure())
77058 if (cred->uid != 0) {
77059 if (bprm->cap_effective)
77061 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
77062 index 3ccf7ac..d73ad64 100644
77063 --- a/security/integrity/ima/ima.h
77064 +++ b/security/integrity/ima/ima.h
77065 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
77066 extern spinlock_t ima_queue_lock;
77068 struct ima_h_table {
77069 - atomic_long_t len; /* number of stored measurements in the list */
77070 - atomic_long_t violations;
77071 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
77072 + atomic_long_unchecked_t violations;
77073 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
77075 extern struct ima_h_table ima_htable;
77076 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
77077 index 88a2788..581ab92 100644
77078 --- a/security/integrity/ima/ima_api.c
77079 +++ b/security/integrity/ima/ima_api.c
77080 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
77083 /* can overflow, only indicator */
77084 - atomic_long_inc(&ima_htable.violations);
77085 + atomic_long_inc_unchecked(&ima_htable.violations);
77087 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
77089 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
77090 index c5c5a72..2ad942f 100644
77091 --- a/security/integrity/ima/ima_audit.c
77092 +++ b/security/integrity/ima/ima_audit.c
77093 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
77094 audit_log_format(ab, " name=");
77095 audit_log_untrustedstring(ab, fname);
77098 - audit_log_format(ab, " dev=%s ino=%lu",
77099 - inode->i_sb->s_id, inode->i_ino);
77101 + audit_log_format(ab, " dev=");
77102 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77103 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77105 audit_log_format(ab, " res=%d", !result ? 0 : 1);
77108 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
77109 index e1aa2b4..52027bf 100644
77110 --- a/security/integrity/ima/ima_fs.c
77111 +++ b/security/integrity/ima/ima_fs.c
77112 @@ -28,12 +28,12 @@
77113 static int valid_policy = 1;
77114 #define TMPBUFLEN 12
77115 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
77116 - loff_t *ppos, atomic_long_t *val)
77117 + loff_t *ppos, atomic_long_unchecked_t *val)
77119 char tmpbuf[TMPBUFLEN];
77122 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
77123 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
77124 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
77127 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
77128 index 55a6271..ad829c3 100644
77129 --- a/security/integrity/ima/ima_queue.c
77130 +++ b/security/integrity/ima/ima_queue.c
77131 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
77132 INIT_LIST_HEAD(&qe->later);
77133 list_add_tail_rcu(&qe->later, &ima_measurements);
77135 - atomic_long_inc(&ima_htable.len);
77136 + atomic_long_inc_unchecked(&ima_htable.len);
77137 key = ima_hash_key(entry->digest);
77138 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
77140 diff --git a/security/keys/compat.c b/security/keys/compat.c
77141 index 4c48e13..7abdac9 100644
77142 --- a/security/keys/compat.c
77143 +++ b/security/keys/compat.c
77144 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
77146 goto no_payload_free;
77148 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
77149 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
77151 if (iov != iovstack)
77153 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
77154 index 0b3f5d7..892c8a6 100644
77155 --- a/security/keys/keyctl.c
77156 +++ b/security/keys/keyctl.c
77157 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
77159 * Copy the iovec data from userspace
77161 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
77162 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
77165 for (; ioc > 0; ioc--) {
77166 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
77167 * If successful, 0 will be returned.
77169 long keyctl_instantiate_key_common(key_serial_t id,
77170 - const struct iovec *payload_iov,
77171 + const struct iovec __user *payload_iov,
77174 key_serial_t ringid)
77175 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
77179 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
77180 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
77183 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
77184 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
77186 goto no_payload_free;
77188 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
77189 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
77191 if (iov != iovstack)
77193 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
77194 index 37a7f3b..86dc19f 100644
77195 --- a/security/keys/keyring.c
77196 +++ b/security/keys/keyring.c
77197 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
77200 for (loop = 0; loop < klist->nkeys; loop++) {
77201 + key_serial_t serial;
77202 key = klist->keys[loop];
77203 + serial = key->serial;
77205 tmp = sizeof(key_serial_t);
77209 - if (copy_to_user(buffer,
77212 + if (copy_to_user(buffer, &serial, tmp))
77216 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
77217 index 893af8a..ba9237c 100644
77218 --- a/security/lsm_audit.c
77219 +++ b/security/lsm_audit.c
77220 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
77221 audit_log_d_path(ab, "path=", &a->u.path);
77223 inode = a->u.path.dentry->d_inode;
77225 - audit_log_format(ab, " dev=%s ino=%lu",
77226 - inode->i_sb->s_id,
77229 + audit_log_format(ab, " dev=");
77230 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77231 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77235 case LSM_AUDIT_DATA_DENTRY: {
77236 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
77237 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
77239 inode = a->u.dentry->d_inode;
77241 - audit_log_format(ab, " dev=%s ino=%lu",
77242 - inode->i_sb->s_id,
77245 + audit_log_format(ab, " dev=");
77246 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77247 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77251 case LSM_AUDIT_DATA_INODE: {
77252 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
77253 dentry->d_name.name);
77256 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
77258 + audit_log_format(ab, " dev=");
77259 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77260 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77263 case LSM_AUDIT_DATA_TASK:
77264 diff --git a/security/min_addr.c b/security/min_addr.c
77265 index f728728..6457a0c 100644
77266 --- a/security/min_addr.c
77267 +++ b/security/min_addr.c
77268 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
77270 static void update_mmap_min_addr(void)
77273 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
77274 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
77275 mmap_min_addr = dac_mmap_min_addr;
77276 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
77278 mmap_min_addr = dac_mmap_min_addr;
77284 diff --git a/security/security.c b/security/security.c
77285 index e2f684a..8d62ef5 100644
77286 --- a/security/security.c
77287 +++ b/security/security.c
77289 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
77290 CONFIG_DEFAULT_SECURITY;
77292 -static struct security_operations *security_ops;
77293 -static struct security_operations default_security_ops = {
77294 +static struct security_operations *security_ops __read_only;
77295 +static struct security_operations default_security_ops __read_only = {
77299 @@ -68,7 +68,9 @@ int __init security_init(void)
77301 void reset_security_ops(void)
77303 + pax_open_kernel();
77304 security_ops = &default_security_ops;
77305 + pax_close_kernel();
77308 /* Save user chosen LSM */
77309 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
77310 index 1126c10..effb32b 100644
77311 --- a/security/selinux/hooks.c
77312 +++ b/security/selinux/hooks.c
77315 #define NUM_SEL_MNT_OPTS 5
77317 -extern struct security_operations *security_ops;
77319 /* SECMARK reference count */
77320 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
77322 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
77326 -static struct security_operations selinux_ops = {
77327 +static struct security_operations selinux_ops __read_only = {
77330 .ptrace_access_check = selinux_ptrace_access_check,
77331 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
77332 index b43813c..74be837 100644
77333 --- a/security/selinux/include/xfrm.h
77334 +++ b/security/selinux/include/xfrm.h
77335 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
77337 static inline void selinux_xfrm_notify_policyload(void)
77339 - atomic_inc(&flow_cache_genid);
77340 + atomic_inc_unchecked(&flow_cache_genid);
77343 static inline int selinux_xfrm_enabled(void)
77344 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
77345 index 7db62b4..ee4d949 100644
77346 --- a/security/smack/smack_lsm.c
77347 +++ b/security/smack/smack_lsm.c
77348 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
77352 -struct security_operations smack_ops = {
77353 +struct security_operations smack_ops __read_only = {
77356 .ptrace_access_check = smack_ptrace_access_check,
77357 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
77358 index 4b327b6..646c57a 100644
77359 --- a/security/tomoyo/tomoyo.c
77360 +++ b/security/tomoyo/tomoyo.c
77361 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
77362 * tomoyo_security_ops is a "struct security_operations" which is used for
77363 * registering TOMOYO.
77365 -static struct security_operations tomoyo_security_ops = {
77366 +static struct security_operations tomoyo_security_ops __read_only = {
77368 .cred_alloc_blank = tomoyo_cred_alloc_blank,
77369 .cred_prepare = tomoyo_cred_prepare,
77370 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
77371 index 762af68..7103453 100644
77372 --- a/sound/aoa/codecs/onyx.c
77373 +++ b/sound/aoa/codecs/onyx.c
77374 @@ -54,7 +54,7 @@ struct onyx {
77379 + local_t open_count;
77380 struct codec_info *codec_info;
77382 /* mutex serializes concurrent access to the device
77383 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
77384 struct onyx *onyx = cii->codec_data;
77386 mutex_lock(&onyx->mutex);
77387 - onyx->open_count++;
77388 + local_inc(&onyx->open_count);
77389 mutex_unlock(&onyx->mutex);
77392 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
77393 struct onyx *onyx = cii->codec_data;
77395 mutex_lock(&onyx->mutex);
77396 - onyx->open_count--;
77397 - if (!onyx->open_count)
77398 + if (local_dec_and_test(&onyx->open_count))
77399 onyx->spdif_locked = onyx->analog_locked = 0;
77400 mutex_unlock(&onyx->mutex);
77402 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
77403 index ffd2025..df062c9 100644
77404 --- a/sound/aoa/codecs/onyx.h
77405 +++ b/sound/aoa/codecs/onyx.h
77407 #include <linux/i2c.h>
77408 #include <asm/pmac_low_i2c.h>
77409 #include <asm/prom.h>
77410 +#include <asm/local.h>
77412 /* PCM3052 register definitions */
77414 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
77415 index 3cc4b86..af0a951 100644
77416 --- a/sound/core/oss/pcm_oss.c
77417 +++ b/sound/core/oss/pcm_oss.c
77418 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
77421 fs = snd_enter_user();
77422 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
77423 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
77424 snd_leave_user(fs);
77426 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
77427 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
77429 if (ret != -EPIPE && ret != -ESTRPIPE)
77431 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
77434 fs = snd_enter_user();
77435 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
77436 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
77437 snd_leave_user(fs);
77439 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
77440 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
77442 if (ret == -EPIPE) {
77443 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
77444 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
77445 struct snd_pcm_plugin_channel *channels;
77446 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
77448 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
77449 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
77451 buf = runtime->oss.buffer;
77453 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
77456 tmp = snd_pcm_oss_write2(substream,
77457 - (const char __force *)buf,
77458 + (const char __force_kernel *)buf,
77459 runtime->oss.period_bytes, 0);
77462 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
77463 struct snd_pcm_runtime *runtime = substream->runtime;
77464 snd_pcm_sframes_t frames, frames1;
77465 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
77466 - char __user *final_dst = (char __force __user *)buf;
77467 + char __user *final_dst = (char __force_user *)buf;
77468 if (runtime->oss.plugin_first) {
77469 struct snd_pcm_plugin_channel *channels;
77470 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
77471 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
77473 runtime->oss.buffer_used -= tmp;
77475 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
77476 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
77477 runtime->oss.period_bytes, 0);
77480 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
77482 size1 /= runtime->channels; /* frames */
77483 fs = snd_enter_user();
77484 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
77485 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
77486 snd_leave_user(fs);
77488 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
77489 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
77490 index 91cdf94..4085161 100644
77491 --- a/sound/core/pcm_compat.c
77492 +++ b/sound/core/pcm_compat.c
77493 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
77496 fs = snd_enter_user();
77497 - err = snd_pcm_delay(substream, &delay);
77498 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
77499 snd_leave_user(fs);
77502 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
77503 index 25ed9fe..24c46e9 100644
77504 --- a/sound/core/pcm_native.c
77505 +++ b/sound/core/pcm_native.c
77506 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
77507 switch (substream->stream) {
77508 case SNDRV_PCM_STREAM_PLAYBACK:
77509 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
77510 - (void __user *)arg);
77511 + (void __force_user *)arg);
77513 case SNDRV_PCM_STREAM_CAPTURE:
77514 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
77515 - (void __user *)arg);
77516 + (void __force_user *)arg);
77520 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
77521 index 5cf8d65..912a79c 100644
77522 --- a/sound/core/seq/seq_device.c
77523 +++ b/sound/core/seq/seq_device.c
77524 @@ -64,7 +64,7 @@ struct ops_list {
77525 int argsize; /* argument size */
77528 - struct snd_seq_dev_ops ops;
77529 + struct snd_seq_dev_ops *ops;
77531 /* registred devices */
77532 struct list_head dev_list; /* list of devices */
77533 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
77535 mutex_lock(&ops->reg_mutex);
77536 /* copy driver operators */
77537 - ops->ops = *entry;
77538 + ops->ops = entry;
77539 ops->driver |= DRIVER_LOADED;
77540 ops->argsize = argsize;
77542 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
77543 dev->name, ops->id, ops->argsize, dev->argsize);
77546 - if (ops->ops.init_device(dev) >= 0) {
77547 + if (ops->ops->init_device(dev) >= 0) {
77548 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
77549 ops->num_init_devices++;
77551 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
77552 dev->name, ops->id, ops->argsize, dev->argsize);
77555 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
77556 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
77557 dev->status = SNDRV_SEQ_DEVICE_FREE;
77558 dev->driver_data = NULL;
77559 ops->num_init_devices--;
77560 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
77561 index f24bf9a..1f7b67c 100644
77562 --- a/sound/drivers/mts64.c
77563 +++ b/sound/drivers/mts64.c
77565 #include <sound/initval.h>
77566 #include <sound/rawmidi.h>
77567 #include <sound/control.h>
77568 +#include <asm/local.h>
77570 #define CARD_NAME "Miditerminal 4140"
77571 #define DRIVER_NAME "MTS64"
77572 @@ -67,7 +68,7 @@ struct mts64 {
77573 struct pardevice *pardev;
77574 int pardev_claimed;
77577 + local_t open_count;
77578 int current_midi_output_port;
77579 int current_midi_input_port;
77580 u8 mode[MTS64_NUM_INPUT_PORTS];
77581 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77583 struct mts64 *mts = substream->rmidi->private_data;
77585 - if (mts->open_count == 0) {
77586 + if (local_read(&mts->open_count) == 0) {
77587 /* We don't need a spinlock here, because this is just called
77588 if the device has not been opened before.
77589 So there aren't any IRQs from the device */
77590 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77594 - ++(mts->open_count);
77595 + local_inc(&mts->open_count);
77599 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77600 struct mts64 *mts = substream->rmidi->private_data;
77601 unsigned long flags;
77603 - --(mts->open_count);
77604 - if (mts->open_count == 0) {
77605 + if (local_dec_return(&mts->open_count) == 0) {
77606 /* We need the spinlock_irqsave here because we can still
77607 have IRQs at this point */
77608 spin_lock_irqsave(&mts->lock, flags);
77609 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77613 - } else if (mts->open_count < 0)
77614 - mts->open_count = 0;
77615 + } else if (local_read(&mts->open_count) < 0)
77616 + local_set(&mts->open_count, 0);
77620 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
77621 index b953fb4..1999c01 100644
77622 --- a/sound/drivers/opl4/opl4_lib.c
77623 +++ b/sound/drivers/opl4/opl4_lib.c
77624 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
77625 MODULE_DESCRIPTION("OPL4 driver");
77626 MODULE_LICENSE("GPL");
77628 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
77629 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
77632 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
77633 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
77634 index f664823..590c745 100644
77635 --- a/sound/drivers/portman2x4.c
77636 +++ b/sound/drivers/portman2x4.c
77638 #include <sound/initval.h>
77639 #include <sound/rawmidi.h>
77640 #include <sound/control.h>
77641 +#include <asm/local.h>
77643 #define CARD_NAME "Portman 2x4"
77644 #define DRIVER_NAME "portman"
77645 @@ -85,7 +86,7 @@ struct portman {
77646 struct pardevice *pardev;
77647 int pardev_claimed;
77650 + local_t open_count;
77651 int mode[PORTMAN_NUM_INPUT_PORTS];
77652 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
77654 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
77655 index 87657dd..a8268d4 100644
77656 --- a/sound/firewire/amdtp.c
77657 +++ b/sound/firewire/amdtp.c
77658 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
77659 ptr = s->pcm_buffer_pointer + data_blocks;
77660 if (ptr >= pcm->runtime->buffer_size)
77661 ptr -= pcm->runtime->buffer_size;
77662 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
77663 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
77665 s->pcm_period_pointer += data_blocks;
77666 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
77667 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
77669 void amdtp_out_stream_update(struct amdtp_out_stream *s)
77671 - ACCESS_ONCE(s->source_node_id_field) =
77672 + ACCESS_ONCE_RW(s->source_node_id_field) =
77673 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
77675 EXPORT_SYMBOL(amdtp_out_stream_update);
77676 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
77677 index 537a9cb..8e8c8e9 100644
77678 --- a/sound/firewire/amdtp.h
77679 +++ b/sound/firewire/amdtp.h
77680 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
77681 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
77682 struct snd_pcm_substream *pcm)
77684 - ACCESS_ONCE(s->pcm) = pcm;
77685 + ACCESS_ONCE_RW(s->pcm) = pcm;
77689 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
77690 index cd094ec..eca1277 100644
77691 --- a/sound/firewire/isight.c
77692 +++ b/sound/firewire/isight.c
77693 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
77695 if (ptr >= runtime->buffer_size)
77696 ptr -= runtime->buffer_size;
77697 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
77698 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
77700 isight->period_counter += count;
77701 if (isight->period_counter >= runtime->period_size) {
77702 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
77706 - ACCESS_ONCE(isight->pcm_active) = true;
77707 + ACCESS_ONCE_RW(isight->pcm_active) = true;
77711 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
77713 struct isight *isight = substream->private_data;
77715 - ACCESS_ONCE(isight->pcm_active) = false;
77716 + ACCESS_ONCE_RW(isight->pcm_active) = false;
77718 mutex_lock(&isight->mutex);
77719 isight_stop_streaming(isight);
77720 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
77723 case SNDRV_PCM_TRIGGER_START:
77724 - ACCESS_ONCE(isight->pcm_running) = true;
77725 + ACCESS_ONCE_RW(isight->pcm_running) = true;
77727 case SNDRV_PCM_TRIGGER_STOP:
77728 - ACCESS_ONCE(isight->pcm_running) = false;
77729 + ACCESS_ONCE_RW(isight->pcm_running) = false;
77733 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
77734 index c94578d..0794ac1 100644
77735 --- a/sound/isa/cmi8330.c
77736 +++ b/sound/isa/cmi8330.c
77737 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
77739 struct snd_pcm *pcm;
77740 struct snd_cmi8330_stream {
77741 - struct snd_pcm_ops ops;
77742 + snd_pcm_ops_no_const ops;
77743 snd_pcm_open_callback_t open;
77744 void *private_data; /* sb or wss */
77746 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
77747 index 733b014..56ce96f 100644
77748 --- a/sound/oss/sb_audio.c
77749 +++ b/sound/oss/sb_audio.c
77750 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
77751 buf16 = (signed short *)(localbuf + localoffs);
77754 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77755 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77756 if (copy_from_user(lbuf8,
77757 userbuf+useroffs + p,
77759 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
77760 index 09d4648..cf234c7 100644
77761 --- a/sound/oss/swarm_cs4297a.c
77762 +++ b/sound/oss/swarm_cs4297a.c
77763 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
77765 struct cs4297a_state *s;
77769 #ifndef CONFIG_BCM_CS4297A_CSWARM
77771 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
77773 char *sb1250_duart_present;
77780 val = SOUND_MASK_LINE;
77781 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
77782 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
77783 val = initvol[i].vol;
77784 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
77787 // cs4297a_write_ac97(s, 0x18, 0x0808);
77789 // cs4297a_write_ac97(s, 0x5e, 0x180);
77790 cs4297a_write_ac97(s, 0x02, 0x0808);
77791 cs4297a_write_ac97(s, 0x18, 0x0808);
77795 list_add(&s->list, &cs4297a_devs);
77797 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
77798 index 5644711..a2aebc1 100644
77799 --- a/sound/pci/hda/hda_codec.h
77800 +++ b/sound/pci/hda/hda_codec.h
77801 @@ -611,7 +611,7 @@ struct hda_bus_ops {
77802 /* notify power-up/down from codec to controller */
77803 void (*pm_notify)(struct hda_bus *bus);
77808 /* template to pass to the bus constructor */
77809 struct hda_bus_template {
77810 @@ -713,6 +713,7 @@ struct hda_codec_ops {
77812 void (*reboot_notify)(struct hda_codec *codec);
77814 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
77816 /* record for amp information cache */
77817 struct hda_cache_head {
77818 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
77819 struct snd_pcm_substream *substream);
77820 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
77821 struct snd_pcm_substream *substream);
77825 /* PCM information for each substream */
77826 struct hda_pcm_stream {
77827 @@ -801,7 +802,7 @@ struct hda_codec {
77828 const char *modelname; /* model name for preset */
77831 - struct hda_codec_ops patch_ops;
77832 + hda_codec_ops_no_const patch_ops;
77834 /* PCM to create, set by patch_ops.build_pcms callback */
77835 unsigned int num_pcms;
77836 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
77837 index 0da778a..bc38b84 100644
77838 --- a/sound/pci/ice1712/ice1712.h
77839 +++ b/sound/pci/ice1712/ice1712.h
77840 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
77841 unsigned int mask_flags; /* total mask bits */
77842 struct snd_akm4xxx_ops {
77843 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
77845 + } __no_const ops;
77848 struct snd_ice1712_spdif {
77849 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
77850 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77851 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77852 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77854 + } __no_const ops;
77858 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
77859 index 03ee4e3..be86b46 100644
77860 --- a/sound/pci/ymfpci/ymfpci_main.c
77861 +++ b/sound/pci/ymfpci/ymfpci_main.c
77862 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
77863 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
77866 - if (atomic_read(&chip->interrupt_sleep_count)) {
77867 - atomic_set(&chip->interrupt_sleep_count, 0);
77868 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77869 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77870 wake_up(&chip->interrupt_sleep);
77873 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
77875 init_waitqueue_entry(&wait, current);
77876 add_wait_queue(&chip->interrupt_sleep, &wait);
77877 - atomic_inc(&chip->interrupt_sleep_count);
77878 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
77879 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
77880 remove_wait_queue(&chip->interrupt_sleep, &wait);
77882 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
77883 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
77884 spin_unlock(&chip->reg_lock);
77886 - if (atomic_read(&chip->interrupt_sleep_count)) {
77887 - atomic_set(&chip->interrupt_sleep_count, 0);
77888 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77889 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77890 wake_up(&chip->interrupt_sleep);
77893 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
77894 spin_lock_init(&chip->reg_lock);
77895 spin_lock_init(&chip->voice_lock);
77896 init_waitqueue_head(&chip->interrupt_sleep);
77897 - atomic_set(&chip->interrupt_sleep_count, 0);
77898 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77902 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
77903 index ee15337..e2187a6 100644
77904 --- a/sound/soc/soc-pcm.c
77905 +++ b/sound/soc/soc-pcm.c
77906 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
77909 /* ASoC PCM operations */
77910 -static struct snd_pcm_ops soc_pcm_ops = {
77911 +static snd_pcm_ops_no_const soc_pcm_ops = {
77912 .open = soc_pcm_open,
77913 .close = soc_pcm_close,
77914 .hw_params = soc_pcm_hw_params,
77915 diff --git a/sound/usb/card.h b/sound/usb/card.h
77916 index a39edcc..1014050 100644
77917 --- a/sound/usb/card.h
77918 +++ b/sound/usb/card.h
77919 @@ -44,6 +44,7 @@ struct snd_urb_ops {
77920 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77921 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77923 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
77925 struct snd_usb_substream {
77926 struct snd_usb_stream *stream;
77927 @@ -93,7 +94,7 @@ struct snd_usb_substream {
77928 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
77931 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
77932 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
77933 int last_frame_number; /* stored frame number */
77934 int last_delay; /* stored delay */
77936 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
77937 new file mode 100644
77938 index 0000000..469b06a
77940 +++ b/tools/gcc/Makefile
77943 +#PLUGIN_SOURCE_FILES := pax_plugin.c
77944 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
77945 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
77946 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
77948 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
77950 +hostlibs-y := constify_plugin.so
77951 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
77952 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
77953 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
77954 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
77956 +always := $(hostlibs-y)
77958 +constify_plugin-objs := constify_plugin.o
77959 +stackleak_plugin-objs := stackleak_plugin.o
77960 +kallocstat_plugin-objs := kallocstat_plugin.o
77961 +kernexec_plugin-objs := kernexec_plugin.o
77962 +checker_plugin-objs := checker_plugin.o
77963 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
77964 new file mode 100644
77965 index 0000000..d41b5af
77967 +++ b/tools/gcc/checker_plugin.c
77970 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
77971 + * Licensed under the GPL v2
77973 + * Note: the choice of the license means that the compilation process is
77974 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
77975 + * but for the kernel it doesn't matter since it doesn't link against
77976 + * any of the gcc libraries
77978 + * gcc plugin to implement various sparse (source code checker) features
77981 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
77986 +#include "gcc-plugin.h"
77987 +#include "config.h"
77988 +#include "system.h"
77989 +#include "coretypes.h"
77991 +#include "tree-pass.h"
77992 +#include "flags.h"
77994 +#include "toplev.h"
77995 +#include "plugin.h"
77996 +//#include "expr.h" where are you...
77997 +#include "diagnostic.h"
77998 +#include "plugin-version.h"
78000 +#include "function.h"
78001 +#include "basic-block.h"
78002 +#include "gimple.h"
78004 +#include "emit-rtl.h"
78005 +#include "tree-flow.h"
78006 +#include "target.h"
78008 +extern void c_register_addr_space (const char *str, addr_space_t as);
78009 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
78010 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
78011 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
78012 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
78013 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
78015 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78016 +extern rtx emit_move_insn(rtx x, rtx y);
78018 +int plugin_is_GPL_compatible;
78020 +static struct plugin_info checker_plugin_info = {
78021 + .version = "201111150100",
78024 +#define ADDR_SPACE_KERNEL 0
78025 +#define ADDR_SPACE_FORCE_KERNEL 1
78026 +#define ADDR_SPACE_USER 2
78027 +#define ADDR_SPACE_FORCE_USER 3
78028 +#define ADDR_SPACE_IOMEM 0
78029 +#define ADDR_SPACE_FORCE_IOMEM 0
78030 +#define ADDR_SPACE_PERCPU 0
78031 +#define ADDR_SPACE_FORCE_PERCPU 0
78032 +#define ADDR_SPACE_RCU 0
78033 +#define ADDR_SPACE_FORCE_RCU 0
78035 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
78037 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
78040 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
78042 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
78045 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
78047 + return default_addr_space_valid_pointer_mode(mode, as);
78050 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
78052 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
78055 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
78057 + return default_addr_space_legitimize_address(x, oldx, mode, as);
78060 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
78062 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
78065 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
78068 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
78071 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
78074 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
78077 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
78080 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
78083 + return subset == superset;
78086 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
78088 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
78089 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
78094 +static void register_checker_address_spaces(void *event_data, void *data)
78096 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
78097 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
78098 + c_register_addr_space("__user", ADDR_SPACE_USER);
78099 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
78100 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
78101 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
78102 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
78103 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
78104 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
78105 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
78107 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
78108 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
78109 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
78110 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
78111 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
78112 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
78113 + targetm.addr_space.convert = checker_addr_space_convert;
78116 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78118 + const char * const plugin_name = plugin_info->base_name;
78119 + const int argc = plugin_info->argc;
78120 + const struct plugin_argument * const argv = plugin_info->argv;
78123 + if (!plugin_default_version_check(version, &gcc_version)) {
78124 + error(G_("incompatible gcc/plugin versions"));
78128 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
78130 + for (i = 0; i < argc; ++i)
78131 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78133 + if (TARGET_64BIT == 0)
78136 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
78140 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
78141 new file mode 100644
78142 index 0000000..704a564
78144 +++ b/tools/gcc/constify_plugin.c
78147 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
78148 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
78149 + * Licensed under the GPL v2, or (at your option) v3
78151 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
78154 + * http://www.grsecurity.net/~ephox/const_plugin/
78157 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
78158 + * $ gcc -fplugin=constify_plugin.so test.c -O2
78161 +#include "gcc-plugin.h"
78162 +#include "config.h"
78163 +#include "system.h"
78164 +#include "coretypes.h"
78166 +#include "tree-pass.h"
78167 +#include "flags.h"
78169 +#include "toplev.h"
78170 +#include "plugin.h"
78171 +#include "diagnostic.h"
78172 +#include "plugin-version.h"
78174 +#include "function.h"
78175 +#include "basic-block.h"
78176 +#include "gimple.h"
78178 +#include "emit-rtl.h"
78179 +#include "tree-flow.h"
78181 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
78183 +int plugin_is_GPL_compatible;
78185 +static struct plugin_info const_plugin_info = {
78186 + .version = "201111150100",
78187 + .help = "no-constify\tturn off constification\n",
78190 +static void constify_type(tree type);
78191 +static bool walk_struct(tree node);
78193 +static tree deconstify_type(tree old_type)
78195 + tree new_type, field;
78197 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
78198 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
78199 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
78200 + DECL_FIELD_CONTEXT(field) = new_type;
78201 + TYPE_READONLY(new_type) = 0;
78202 + C_TYPE_FIELDS_READONLY(new_type) = 0;
78206 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
78210 + *no_add_attrs = true;
78211 + if (TREE_CODE(*node) == FUNCTION_DECL) {
78212 + error("%qE attribute does not apply to functions", name);
78213 + return NULL_TREE;
78216 + if (TREE_CODE(*node) == VAR_DECL) {
78217 + error("%qE attribute does not apply to variables", name);
78218 + return NULL_TREE;
78221 + if (TYPE_P(*node)) {
78222 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
78223 + *no_add_attrs = false;
78225 + error("%qE attribute applies to struct and union types only", name);
78226 + return NULL_TREE;
78229 + type = TREE_TYPE(*node);
78231 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
78232 + error("%qE attribute applies to struct and union types only", name);
78233 + return NULL_TREE;
78236 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
78237 + error("%qE attribute is already applied to the type", name);
78238 + return NULL_TREE;
78241 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
78242 + error("%qE attribute used on type that is not constified", name);
78243 + return NULL_TREE;
78246 + if (TREE_CODE(*node) == TYPE_DECL) {
78247 + TREE_TYPE(*node) = deconstify_type(type);
78248 + TREE_READONLY(*node) = 0;
78249 + return NULL_TREE;
78252 + return NULL_TREE;
78255 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
78257 + *no_add_attrs = true;
78258 + if (!TYPE_P(*node)) {
78259 + error("%qE attribute applies to types only", name);
78260 + return NULL_TREE;
78263 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
78264 + error("%qE attribute applies to struct and union types only", name);
78265 + return NULL_TREE;
78268 + *no_add_attrs = false;
78269 + constify_type(*node);
78270 + return NULL_TREE;
78273 +static struct attribute_spec no_const_attr = {
78274 + .name = "no_const",
78277 + .decl_required = false,
78278 + .type_required = false,
78279 + .function_type_required = false,
78280 + .handler = handle_no_const_attribute,
78281 +#if BUILDING_GCC_VERSION >= 4007
78282 + .affects_type_identity = true
78286 +static struct attribute_spec do_const_attr = {
78287 + .name = "do_const",
78290 + .decl_required = false,
78291 + .type_required = false,
78292 + .function_type_required = false,
78293 + .handler = handle_do_const_attribute,
78294 +#if BUILDING_GCC_VERSION >= 4007
78295 + .affects_type_identity = true
78299 +static void register_attributes(void *event_data, void *data)
78301 + register_attribute(&no_const_attr);
78302 + register_attribute(&do_const_attr);
78305 +static void constify_type(tree type)
78307 + TYPE_READONLY(type) = 1;
78308 + C_TYPE_FIELDS_READONLY(type) = 1;
78311 +static bool is_fptr(tree field)
78313 + tree ptr = TREE_TYPE(field);
78315 + if (TREE_CODE(ptr) != POINTER_TYPE)
78318 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
78321 +static bool walk_struct(tree node)
78325 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
78328 + if (TYPE_FIELDS(node) == NULL_TREE)
78331 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
78332 + tree type = TREE_TYPE(field);
78333 + enum tree_code code = TREE_CODE(type);
78334 + if (code == RECORD_TYPE || code == UNION_TYPE) {
78335 + if (!(walk_struct(type)))
78337 + } else if (!is_fptr(field) && !TREE_READONLY(field))
78343 +static void finish_type(void *event_data, void *data)
78345 + tree type = (tree)event_data;
78347 + if (type == NULL_TREE)
78350 + if (TYPE_READONLY(type))
78353 + if (walk_struct(type))
78354 + constify_type(type);
78357 +static unsigned int check_local_variables(void);
78359 +struct gimple_opt_pass pass_local_variable = {
78361 + .type = GIMPLE_PASS,
78362 + .name = "check_local_variables",
78364 + .execute = check_local_variables,
78367 + .static_pass_number = 0,
78368 + .tv_id = TV_NONE,
78369 + .properties_required = 0,
78370 + .properties_provided = 0,
78371 + .properties_destroyed = 0,
78372 + .todo_flags_start = 0,
78373 + .todo_flags_finish = 0
78377 +static unsigned int check_local_variables(void)
78380 + referenced_var_iterator rvi;
78382 +#if BUILDING_GCC_VERSION == 4005
78383 + FOR_EACH_REFERENCED_VAR(var, rvi) {
78385 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
78387 + tree type = TREE_TYPE(var);
78389 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
78392 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
78395 + if (!TYPE_READONLY(type))
78398 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
78401 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
78404 + if (walk_struct(type)) {
78405 + error("constified variable %qE cannot be local", var);
78412 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78414 + const char * const plugin_name = plugin_info->base_name;
78415 + const int argc = plugin_info->argc;
78416 + const struct plugin_argument * const argv = plugin_info->argv;
78418 + bool constify = true;
78420 + struct register_pass_info local_variable_pass_info = {
78421 + .pass = &pass_local_variable.pass,
78422 + .reference_pass_name = "*referenced_vars",
78423 + .ref_pass_instance_number = 0,
78424 + .pos_op = PASS_POS_INSERT_AFTER
78427 + if (!plugin_default_version_check(version, &gcc_version)) {
78428 + error(G_("incompatible gcc/plugin versions"));
78432 + for (i = 0; i < argc; ++i) {
78433 + if (!(strcmp(argv[i].key, "no-constify"))) {
78434 + constify = false;
78437 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78440 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
78442 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
78443 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
78445 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
78449 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
78450 new file mode 100644
78451 index 0000000..a5eabce
78453 +++ b/tools/gcc/kallocstat_plugin.c
78456 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78457 + * Licensed under the GPL v2
78459 + * Note: the choice of the license means that the compilation process is
78460 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78461 + * but for the kernel it doesn't matter since it doesn't link against
78462 + * any of the gcc libraries
78464 + * gcc plugin to find the distribution of k*alloc sizes
78471 +#include "gcc-plugin.h"
78472 +#include "config.h"
78473 +#include "system.h"
78474 +#include "coretypes.h"
78476 +#include "tree-pass.h"
78477 +#include "flags.h"
78479 +#include "toplev.h"
78480 +#include "plugin.h"
78481 +//#include "expr.h" where are you...
78482 +#include "diagnostic.h"
78483 +#include "plugin-version.h"
78485 +#include "function.h"
78486 +#include "basic-block.h"
78487 +#include "gimple.h"
78489 +#include "emit-rtl.h"
78491 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78493 +int plugin_is_GPL_compatible;
78495 +static const char * const kalloc_functions[] = {
78501 + "kmalloc_order_trace",
78507 +static struct plugin_info kallocstat_plugin_info = {
78508 + .version = "201111150100",
78511 +static unsigned int execute_kallocstat(void);
78513 +static struct gimple_opt_pass kallocstat_pass = {
78515 + .type = GIMPLE_PASS,
78516 + .name = "kallocstat",
78518 + .execute = execute_kallocstat,
78521 + .static_pass_number = 0,
78522 + .tv_id = TV_NONE,
78523 + .properties_required = 0,
78524 + .properties_provided = 0,
78525 + .properties_destroyed = 0,
78526 + .todo_flags_start = 0,
78527 + .todo_flags_finish = 0
78531 +static bool is_kalloc(const char *fnname)
78535 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
78536 + if (!strcmp(fnname, kalloc_functions[i]))
78541 +static unsigned int execute_kallocstat(void)
78545 + // 1. loop through BBs and GIMPLE statements
78546 + FOR_EACH_BB(bb) {
78547 + gimple_stmt_iterator gsi;
78548 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78550 + tree fndecl, size;
78551 + gimple call_stmt;
78552 + const char *fnname;
78555 + call_stmt = gsi_stmt(gsi);
78556 + if (!is_gimple_call(call_stmt))
78558 + fndecl = gimple_call_fndecl(call_stmt);
78559 + if (fndecl == NULL_TREE)
78561 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
78564 + // is it a call to k*alloc
78565 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
78566 + if (!is_kalloc(fnname))
78569 + // is the size arg the result of a simple const assignment
78570 + size = gimple_call_arg(call_stmt, 0);
78573 + expanded_location xloc;
78576 + if (TREE_CODE(size) != SSA_NAME)
78578 + def_stmt = SSA_NAME_DEF_STMT(size);
78579 + if (!def_stmt || !is_gimple_assign(def_stmt))
78581 + if (gimple_num_ops(def_stmt) != 2)
78583 + size = gimple_assign_rhs1(def_stmt);
78584 + if (!TREE_CONSTANT(size))
78586 + xloc = expand_location(gimple_location(def_stmt));
78588 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
78589 + size_val = TREE_INT_CST_LOW(size);
78590 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
78593 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78594 +//debug_tree(gimple_call_fn(call_stmt));
78595 +//print_node(stderr, "pax", fndecl, 4);
78602 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78604 + const char * const plugin_name = plugin_info->base_name;
78605 + struct register_pass_info kallocstat_pass_info = {
78606 + .pass = &kallocstat_pass.pass,
78607 + .reference_pass_name = "ssa",
78608 + .ref_pass_instance_number = 0,
78609 + .pos_op = PASS_POS_INSERT_AFTER
78612 + if (!plugin_default_version_check(version, &gcc_version)) {
78613 + error(G_("incompatible gcc/plugin versions"));
78617 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
78618 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
78622 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
78623 new file mode 100644
78624 index 0000000..008f159
78626 +++ b/tools/gcc/kernexec_plugin.c
78629 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78630 + * Licensed under the GPL v2
78632 + * Note: the choice of the license means that the compilation process is
78633 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78634 + * but for the kernel it doesn't matter since it doesn't link against
78635 + * any of the gcc libraries
78637 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
78644 +#include "gcc-plugin.h"
78645 +#include "config.h"
78646 +#include "system.h"
78647 +#include "coretypes.h"
78649 +#include "tree-pass.h"
78650 +#include "flags.h"
78652 +#include "toplev.h"
78653 +#include "plugin.h"
78654 +//#include "expr.h" where are you...
78655 +#include "diagnostic.h"
78656 +#include "plugin-version.h"
78658 +#include "function.h"
78659 +#include "basic-block.h"
78660 +#include "gimple.h"
78662 +#include "emit-rtl.h"
78663 +#include "tree-flow.h"
78665 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78666 +extern rtx emit_move_insn(rtx x, rtx y);
78668 +int plugin_is_GPL_compatible;
78670 +static struct plugin_info kernexec_plugin_info = {
78671 + .version = "201111291120",
78672 + .help = "method=[bts|or]\tinstrumentation method\n"
78675 +static unsigned int execute_kernexec_reload(void);
78676 +static unsigned int execute_kernexec_fptr(void);
78677 +static unsigned int execute_kernexec_retaddr(void);
78678 +static bool kernexec_cmodel_check(void);
78680 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
78681 +static void (*kernexec_instrument_retaddr)(rtx);
78683 +static struct gimple_opt_pass kernexec_reload_pass = {
78685 + .type = GIMPLE_PASS,
78686 + .name = "kernexec_reload",
78687 + .gate = kernexec_cmodel_check,
78688 + .execute = execute_kernexec_reload,
78691 + .static_pass_number = 0,
78692 + .tv_id = TV_NONE,
78693 + .properties_required = 0,
78694 + .properties_provided = 0,
78695 + .properties_destroyed = 0,
78696 + .todo_flags_start = 0,
78697 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
78701 +static struct gimple_opt_pass kernexec_fptr_pass = {
78703 + .type = GIMPLE_PASS,
78704 + .name = "kernexec_fptr",
78705 + .gate = kernexec_cmodel_check,
78706 + .execute = execute_kernexec_fptr,
78709 + .static_pass_number = 0,
78710 + .tv_id = TV_NONE,
78711 + .properties_required = 0,
78712 + .properties_provided = 0,
78713 + .properties_destroyed = 0,
78714 + .todo_flags_start = 0,
78715 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
78719 +static struct rtl_opt_pass kernexec_retaddr_pass = {
78721 + .type = RTL_PASS,
78722 + .name = "kernexec_retaddr",
78723 + .gate = kernexec_cmodel_check,
78724 + .execute = execute_kernexec_retaddr,
78727 + .static_pass_number = 0,
78728 + .tv_id = TV_NONE,
78729 + .properties_required = 0,
78730 + .properties_provided = 0,
78731 + .properties_destroyed = 0,
78732 + .todo_flags_start = 0,
78733 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
78737 +static bool kernexec_cmodel_check(void)
78741 + if (ix86_cmodel != CM_KERNEL)
78744 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
78745 + if (!section || !TREE_VALUE(section))
78748 + section = TREE_VALUE(TREE_VALUE(section));
78749 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
78756 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
78758 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
78760 + gimple asm_movabs_stmt;
78762 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
78763 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
78764 + gimple_asm_set_volatile(asm_movabs_stmt, true);
78765 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
78766 + update_stmt(asm_movabs_stmt);
78770 + * find all asm() stmts that clobber r10 and add a reload of r10
78772 +static unsigned int execute_kernexec_reload(void)
78776 + // 1. loop through BBs and GIMPLE statements
78777 + FOR_EACH_BB(bb) {
78778 + gimple_stmt_iterator gsi;
78780 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78781 + // gimple match: __asm__ ("" : : : "r10");
78783 + size_t nclobbers;
78785 + // is it an asm ...
78786 + asm_stmt = gsi_stmt(gsi);
78787 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
78790 + // ... clobbering r10
78791 + nclobbers = gimple_asm_nclobbers(asm_stmt);
78792 + while (nclobbers--) {
78793 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
78794 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
78796 + kernexec_reload_fptr_mask(&gsi);
78797 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
78807 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
78808 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
78810 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
78812 + gimple assign_intptr, assign_new_fptr, call_stmt;
78813 + tree intptr, old_fptr, new_fptr, kernexec_mask;
78815 + call_stmt = gsi_stmt(*gsi);
78816 + old_fptr = gimple_call_fn(call_stmt);
78818 + // create temporary unsigned long variable used for bitops and cast fptr to it
78819 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
78820 + add_referenced_var(intptr);
78821 + mark_sym_for_renaming(intptr);
78822 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
78823 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
78824 + update_stmt(assign_intptr);
78826 + // apply logical or to temporary unsigned long and bitmask
78827 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
78828 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
78829 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
78830 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
78831 + update_stmt(assign_intptr);
78833 + // cast temporary unsigned long back to a temporary fptr variable
78834 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
78835 + add_referenced_var(new_fptr);
78836 + mark_sym_for_renaming(new_fptr);
78837 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
78838 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
78839 + update_stmt(assign_new_fptr);
78841 + // replace call stmt fn with the new fptr
78842 + gimple_call_set_fn(call_stmt, new_fptr);
78843 + update_stmt(call_stmt);
78846 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
78848 + gimple asm_or_stmt, call_stmt;
78849 + tree old_fptr, new_fptr, input, output;
78850 + VEC(tree, gc) *inputs = NULL;
78851 + VEC(tree, gc) *outputs = NULL;
78853 + call_stmt = gsi_stmt(*gsi);
78854 + old_fptr = gimple_call_fn(call_stmt);
78856 + // create temporary fptr variable
78857 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
78858 + add_referenced_var(new_fptr);
78859 + mark_sym_for_renaming(new_fptr);
78861 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
78862 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
78863 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
78864 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
78865 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
78866 + VEC_safe_push(tree, gc, inputs, input);
78867 + VEC_safe_push(tree, gc, outputs, output);
78868 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
78869 + gimple_asm_set_volatile(asm_or_stmt, true);
78870 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
78871 + update_stmt(asm_or_stmt);
78873 + // replace call stmt fn with the new fptr
78874 + gimple_call_set_fn(call_stmt, new_fptr);
78875 + update_stmt(call_stmt);
78879 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
78881 +static unsigned int execute_kernexec_fptr(void)
78885 + // 1. loop through BBs and GIMPLE statements
78886 + FOR_EACH_BB(bb) {
78887 + gimple_stmt_iterator gsi;
78889 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78890 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
78892 + gimple call_stmt;
78894 + // is it a call ...
78895 + call_stmt = gsi_stmt(gsi);
78896 + if (!is_gimple_call(call_stmt))
78898 + fn = gimple_call_fn(call_stmt);
78899 + if (TREE_CODE(fn) == ADDR_EXPR)
78901 + if (TREE_CODE(fn) != SSA_NAME)
78902 + gcc_unreachable();
78904 + // ... through a function pointer
78905 + fn = SSA_NAME_VAR(fn);
78906 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
78908 + fn = TREE_TYPE(fn);
78909 + if (TREE_CODE(fn) != POINTER_TYPE)
78911 + fn = TREE_TYPE(fn);
78912 + if (TREE_CODE(fn) != FUNCTION_TYPE)
78915 + kernexec_instrument_fptr(&gsi);
78917 +//debug_tree(gimple_call_fn(call_stmt));
78918 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78925 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
78926 +static void kernexec_instrument_retaddr_bts(rtx insn)
78929 + rtvec argvec, constraintvec, labelvec;
78932 + // create asm volatile("btsq $63,(%%rsp)":::)
78933 + argvec = rtvec_alloc(0);
78934 + constraintvec = rtvec_alloc(0);
78935 + labelvec = rtvec_alloc(0);
78936 + line = expand_location(RTL_LOCATION(insn)).line;
78937 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78938 + MEM_VOLATILE_P(btsq) = 1;
78939 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
78940 + emit_insn_before(btsq, insn);
78943 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
78944 +static void kernexec_instrument_retaddr_or(rtx insn)
78947 + rtvec argvec, constraintvec, labelvec;
78950 + // create asm volatile("orq %%r10,(%%rsp)":::)
78951 + argvec = rtvec_alloc(0);
78952 + constraintvec = rtvec_alloc(0);
78953 + labelvec = rtvec_alloc(0);
78954 + line = expand_location(RTL_LOCATION(insn)).line;
78955 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78956 + MEM_VOLATILE_P(orq) = 1;
78957 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
78958 + emit_insn_before(orq, insn);
78962 + * find all asm level function returns and forcibly set the highest bit of the return address
78964 +static unsigned int execute_kernexec_retaddr(void)
78968 + // 1. find function returns
78969 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
78970 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
78971 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
78975 + if (!JUMP_P(insn))
78977 + body = PATTERN(insn);
78978 + if (GET_CODE(body) == PARALLEL)
78979 + body = XVECEXP(body, 0, 0);
78980 + if (GET_CODE(body) != RETURN)
78982 + kernexec_instrument_retaddr(insn);
78985 +// print_simple_rtl(stderr, get_insns());
78986 +// print_rtl(stderr, get_insns());
78991 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78993 + const char * const plugin_name = plugin_info->base_name;
78994 + const int argc = plugin_info->argc;
78995 + const struct plugin_argument * const argv = plugin_info->argv;
78997 + struct register_pass_info kernexec_reload_pass_info = {
78998 + .pass = &kernexec_reload_pass.pass,
78999 + .reference_pass_name = "ssa",
79000 + .ref_pass_instance_number = 0,
79001 + .pos_op = PASS_POS_INSERT_AFTER
79003 + struct register_pass_info kernexec_fptr_pass_info = {
79004 + .pass = &kernexec_fptr_pass.pass,
79005 + .reference_pass_name = "ssa",
79006 + .ref_pass_instance_number = 0,
79007 + .pos_op = PASS_POS_INSERT_AFTER
79009 + struct register_pass_info kernexec_retaddr_pass_info = {
79010 + .pass = &kernexec_retaddr_pass.pass,
79011 + .reference_pass_name = "pro_and_epilogue",
79012 + .ref_pass_instance_number = 0,
79013 + .pos_op = PASS_POS_INSERT_AFTER
79016 + if (!plugin_default_version_check(version, &gcc_version)) {
79017 + error(G_("incompatible gcc/plugin versions"));
79021 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
79023 + if (TARGET_64BIT == 0)
79026 + for (i = 0; i < argc; ++i) {
79027 + if (!strcmp(argv[i].key, "method")) {
79028 + if (!argv[i].value) {
79029 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79032 + if (!strcmp(argv[i].value, "bts")) {
79033 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
79034 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
79035 + } else if (!strcmp(argv[i].value, "or")) {
79036 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
79037 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
79038 + fix_register("r10", 1, 1);
79040 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
79043 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79045 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
79046 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
79048 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
79049 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
79050 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
79051 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
79055 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
79056 new file mode 100644
79057 index 0000000..4a9b187
79059 +++ b/tools/gcc/stackleak_plugin.c
79062 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79063 + * Licensed under the GPL v2
79065 + * Note: the choice of the license means that the compilation process is
79066 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79067 + * but for the kernel it doesn't matter since it doesn't link against
79068 + * any of the gcc libraries
79070 + * gcc plugin to help implement various PaX features
79072 + * - track lowest stack pointer
79075 + * - initialize all local variables
79080 +#include "gcc-plugin.h"
79081 +#include "config.h"
79082 +#include "system.h"
79083 +#include "coretypes.h"
79085 +#include "tree-pass.h"
79086 +#include "flags.h"
79088 +#include "toplev.h"
79089 +#include "plugin.h"
79090 +//#include "expr.h" where are you...
79091 +#include "diagnostic.h"
79092 +#include "plugin-version.h"
79094 +#include "function.h"
79095 +#include "basic-block.h"
79096 +#include "gimple.h"
79098 +#include "emit-rtl.h"
79100 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79102 +int plugin_is_GPL_compatible;
79104 +static int track_frame_size = -1;
79105 +static const char track_function[] = "pax_track_stack";
79106 +static const char check_function[] = "pax_check_alloca";
79107 +static tree pax_check_alloca_decl;
79108 +static tree pax_track_stack_decl;
79109 +static bool init_locals;
79111 +static struct plugin_info stackleak_plugin_info = {
79112 + .version = "201203021600",
79113 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
79114 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
79117 +static bool gate_stackleak_track_stack(void);
79118 +static unsigned int execute_stackleak_tree_instrument(void);
79119 +static unsigned int execute_stackleak_final(void);
79121 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
79123 + .type = GIMPLE_PASS,
79124 + .name = "stackleak_tree_instrument",
79125 + .gate = gate_stackleak_track_stack,
79126 + .execute = execute_stackleak_tree_instrument,
79129 + .static_pass_number = 0,
79130 + .tv_id = TV_NONE,
79131 + .properties_required = PROP_gimple_leh | PROP_cfg,
79132 + .properties_provided = 0,
79133 + .properties_destroyed = 0,
79134 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
79135 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
79139 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
79141 + .type = RTL_PASS,
79142 + .name = "stackleak_final",
79143 + .gate = gate_stackleak_track_stack,
79144 + .execute = execute_stackleak_final,
79147 + .static_pass_number = 0,
79148 + .tv_id = TV_NONE,
79149 + .properties_required = 0,
79150 + .properties_provided = 0,
79151 + .properties_destroyed = 0,
79152 + .todo_flags_start = 0,
79153 + .todo_flags_finish = TODO_dump_func
79157 +static bool gate_stackleak_track_stack(void)
79159 + return track_frame_size >= 0;
79162 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
79164 + gimple check_alloca;
79165 + tree alloca_size;
79167 + // insert call to void pax_check_alloca(unsigned long size)
79168 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
79169 + check_alloca = gimple_build_call(pax_check_alloca_decl, 1, alloca_size);
79170 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
79173 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
79175 + gimple track_stack;
79177 + // insert call to void pax_track_stack(void)
79178 + track_stack = gimple_build_call(pax_track_stack_decl, 0);
79179 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
79182 +#if BUILDING_GCC_VERSION == 4005
79183 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
79187 + if (!is_gimple_call(stmt))
79189 + fndecl = gimple_call_fndecl(stmt);
79192 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
79194 +// print_node(stderr, "pax", fndecl, 4);
79195 + return DECL_FUNCTION_CODE(fndecl) == code;
79199 +static bool is_alloca(gimple stmt)
79201 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
79204 +#if BUILDING_GCC_VERSION >= 4007
79205 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
79212 +static unsigned int execute_stackleak_tree_instrument(void)
79214 + basic_block bb, entry_bb;
79215 + bool prologue_instrumented = false, is_leaf = true;
79217 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
79219 + // 1. loop through BBs and GIMPLE statements
79220 + FOR_EACH_BB(bb) {
79221 + gimple_stmt_iterator gsi;
79223 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
79226 + stmt = gsi_stmt(gsi);
79228 + if (is_gimple_call(stmt))
79231 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
79232 + if (!is_alloca(stmt))
79235 + // 2. insert stack overflow check before each __builtin_alloca call
79236 + stackleak_check_alloca(&gsi);
79238 + // 3. insert track call after each __builtin_alloca call
79239 + stackleak_add_instrumentation(&gsi);
79240 + if (bb == entry_bb)
79241 + prologue_instrumented = true;
79245 + // special case for some bad linux code: taking the address of static inline functions will materialize them
79246 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
79247 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
79248 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
79249 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
79252 + // 4. insert track call at the beginning
79253 + if (!prologue_instrumented) {
79254 + gimple_stmt_iterator gsi;
79256 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
79257 + if (dom_info_available_p(CDI_DOMINATORS))
79258 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
79259 + gsi = gsi_start_bb(bb);
79260 + stackleak_add_instrumentation(&gsi);
79266 +static unsigned int execute_stackleak_final(void)
79270 + if (cfun->calls_alloca)
79273 + // keep calls only if function frame is big enough
79274 + if (get_frame_size() >= track_frame_size)
79277 + // 1. find pax_track_stack calls
79278 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
79279 + // 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))
79282 + if (!CALL_P(insn))
79284 + body = PATTERN(insn);
79285 + if (GET_CODE(body) != CALL)
79287 + body = XEXP(body, 0);
79288 + if (GET_CODE(body) != MEM)
79290 + body = XEXP(body, 0);
79291 + if (GET_CODE(body) != SYMBOL_REF)
79293 + if (strcmp(XSTR(body, 0), track_function))
79295 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
79296 + // 2. delete call
79297 + insn = delete_insn_and_edges(insn);
79298 +#if BUILDING_GCC_VERSION >= 4007
79299 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
79300 + insn = delete_insn_and_edges(insn);
79304 +// print_simple_rtl(stderr, get_insns());
79305 +// print_rtl(stderr, get_insns());
79306 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
79311 +static void stackleak_start_unit(void *gcc_data, void *user_dat)
79315 + // declare void pax_check_alloca(unsigned long size)
79316 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
79317 + pax_check_alloca_decl = build_fn_decl(check_function, fntype);
79318 + DECL_ASSEMBLER_NAME(pax_check_alloca_decl); // for LTO
79319 + TREE_PUBLIC(pax_check_alloca_decl) = 1;
79320 + DECL_EXTERNAL(pax_check_alloca_decl) = 1;
79321 + DECL_ARTIFICIAL(pax_check_alloca_decl) = 1;
79323 + // declare void pax_track_stack(void)
79324 + fntype = build_function_type_list(void_type_node, NULL_TREE);
79325 + pax_track_stack_decl = build_fn_decl(track_function, fntype);
79326 + DECL_ASSEMBLER_NAME(pax_track_stack_decl); // for LTO
79327 + TREE_PUBLIC(pax_track_stack_decl) = 1;
79328 + DECL_EXTERNAL(pax_track_stack_decl) = 1;
79329 + DECL_ARTIFICIAL(pax_track_stack_decl) = 1;
79332 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79334 + const char * const plugin_name = plugin_info->base_name;
79335 + const int argc = plugin_info->argc;
79336 + const struct plugin_argument * const argv = plugin_info->argv;
79338 + struct register_pass_info stackleak_tree_instrument_pass_info = {
79339 + .pass = &stackleak_tree_instrument_pass.pass,
79340 +// .reference_pass_name = "tree_profile",
79341 + .reference_pass_name = "optimized",
79342 + .ref_pass_instance_number = 0,
79343 + .pos_op = PASS_POS_INSERT_BEFORE
79345 + struct register_pass_info stackleak_final_pass_info = {
79346 + .pass = &stackleak_final_rtl_opt_pass.pass,
79347 + .reference_pass_name = "final",
79348 + .ref_pass_instance_number = 0,
79349 + .pos_op = PASS_POS_INSERT_BEFORE
79352 + if (!plugin_default_version_check(version, &gcc_version)) {
79353 + error(G_("incompatible gcc/plugin versions"));
79357 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
79359 + for (i = 0; i < argc; ++i) {
79360 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
79361 + if (!argv[i].value) {
79362 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79365 + track_frame_size = atoi(argv[i].value);
79366 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
79367 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
79370 + if (!strcmp(argv[i].key, "initialize-locals")) {
79371 + if (argv[i].value) {
79372 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
79375 + init_locals = true;
79378 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79381 + register_callback("start_unit", PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
79382 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
79383 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
79387 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
79388 index 6789d78..4afd019 100644
79389 --- a/tools/perf/util/include/asm/alternative-asm.h
79390 +++ b/tools/perf/util/include/asm/alternative-asm.h
79393 #define altinstruction_entry #
79395 + .macro pax_force_retaddr rip=0, reload=0
79399 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
79400 index af0f22f..9a7d479 100644
79401 --- a/usr/gen_init_cpio.c
79402 +++ b/usr/gen_init_cpio.c
79403 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
79412 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
79413 *env_var = *expanded = '\0';
79414 strncat(env_var, start + 2, end - start - 2);
79415 strncat(expanded, new_location, start - new_location);
79416 - strncat(expanded, getenv(env_var), PATH_MAX);
79417 - strncat(expanded, end + 1, PATH_MAX);
79418 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
79419 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
79420 strncpy(new_location, expanded, PATH_MAX);
79421 + new_location[PATH_MAX] = 0;
79425 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
79426 index d9cfb78..4f27c10 100644
79427 --- a/virt/kvm/kvm_main.c
79428 +++ b/virt/kvm/kvm_main.c
79429 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
79431 static cpumask_var_t cpus_hardware_enabled;
79432 static int kvm_usage_count = 0;
79433 -static atomic_t hardware_enable_failed;
79434 +static atomic_unchecked_t hardware_enable_failed;
79436 struct kmem_cache *kvm_vcpu_cache;
79437 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
79438 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
79441 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
79442 - atomic_inc(&hardware_enable_failed);
79443 + atomic_inc_unchecked(&hardware_enable_failed);
79444 printk(KERN_INFO "kvm: enabling virtualization on "
79445 "CPU%d failed\n", cpu);
79447 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
79450 if (kvm_usage_count == 1) {
79451 - atomic_set(&hardware_enable_failed, 0);
79452 + atomic_set_unchecked(&hardware_enable_failed, 0);
79453 on_each_cpu(hardware_enable_nolock, NULL, 1);
79455 - if (atomic_read(&hardware_enable_failed)) {
79456 + if (atomic_read_unchecked(&hardware_enable_failed)) {
79457 hardware_disable_all_nolock();
79460 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
79461 kvm_arch_vcpu_put(vcpu);
79464 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79465 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79466 struct module *module)
79469 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79471 vcpu_align = __alignof__(struct kvm_vcpu);
79472 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
79474 + SLAB_USERCOPY, NULL);
79475 if (!kvm_vcpu_cache) {
79478 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79482 - kvm_chardev_ops.owner = module;
79483 - kvm_vm_fops.owner = module;
79484 - kvm_vcpu_fops.owner = module;
79485 + pax_open_kernel();
79486 + *(void **)&kvm_chardev_ops.owner = module;
79487 + *(void **)&kvm_vm_fops.owner = module;
79488 + *(void **)&kvm_vcpu_fops.owner = module;
79489 + pax_close_kernel();
79491 r = misc_register(&kvm_dev);