diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 3 | ||||
-rw-r--r-- | kernel/audit_tree.c | 100 | ||||
-rw-r--r-- | kernel/auditsc.c | 7 | ||||
-rw-r--r-- | kernel/cpu.c | 2 | ||||
-rw-r--r-- | kernel/elfcore.c | 28 | ||||
-rw-r--r-- | kernel/exit.c | 5 | ||||
-rw-r--r-- | kernel/fork.c | 19 | ||||
-rw-r--r-- | kernel/kprobes.c | 647 | ||||
-rw-r--r-- | kernel/padata.c | 8 | ||||
-rw-r--r-- | kernel/panic.c | 46 | ||||
-rw-r--r-- | kernel/params.c | 1 | ||||
-rw-r--r-- | kernel/perf_event.c | 2 | ||||
-rw-r--r-- | kernel/pid.c | 2 | ||||
-rw-r--r-- | kernel/posix-cpu-timers.c | 36 | ||||
-rw-r--r-- | kernel/power/hibernate.c | 9 | ||||
-rw-r--r-- | kernel/power/suspend.c | 3 | ||||
-rw-r--r-- | kernel/printk.c | 3 | ||||
-rw-r--r-- | kernel/relay.c | 5 | ||||
-rw-r--r-- | kernel/sched.c | 4 | ||||
-rw-r--r-- | kernel/sched_cpupri.c | 2 | ||||
-rw-r--r-- | kernel/sched_rt.c | 5 | ||||
-rw-r--r-- | kernel/signal.c | 45 | ||||
-rw-r--r-- | kernel/sys.c | 3 | ||||
-rw-r--r-- | kernel/sysctl.c | 12 | ||||
-rw-r--r-- | kernel/sysctl_binary.c | 7 | ||||
-rw-r--r-- | kernel/tsacct.c | 1 |
26 files changed, 762 insertions, 243 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 7b974699f8c2..a987aa1676b5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -91,6 +91,9 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o | |||
91 | obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o | 91 | obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o |
92 | obj-$(CONFIG_TRACEPOINTS) += tracepoint.o | 92 | obj-$(CONFIG_TRACEPOINTS) += tracepoint.o |
93 | obj-$(CONFIG_LATENCYTOP) += latencytop.o | 93 | obj-$(CONFIG_LATENCYTOP) += latencytop.o |
94 | obj-$(CONFIG_BINFMT_ELF) += elfcore.o | ||
95 | obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o | ||
96 | obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o | ||
94 | obj-$(CONFIG_FUNCTION_TRACER) += trace/ | 97 | obj-$(CONFIG_FUNCTION_TRACER) += trace/ |
95 | obj-$(CONFIG_TRACING) += trace/ | 98 | obj-$(CONFIG_TRACING) += trace/ |
96 | obj-$(CONFIG_X86_DS) += trace/ | 99 | obj-$(CONFIG_X86_DS) += trace/ |
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index 4b05bd9479db..028e85663f27 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c | |||
@@ -548,6 +548,11 @@ int audit_remove_tree_rule(struct audit_krule *rule) | |||
548 | return 0; | 548 | return 0; |
549 | } | 549 | } |
550 | 550 | ||
551 | static int compare_root(struct vfsmount *mnt, void *arg) | ||
552 | { | ||
553 | return mnt->mnt_root->d_inode == arg; | ||
554 | } | ||
555 | |||
551 | void audit_trim_trees(void) | 556 | void audit_trim_trees(void) |
552 | { | 557 | { |
553 | struct list_head cursor; | 558 | struct list_head cursor; |
@@ -559,7 +564,6 @@ void audit_trim_trees(void) | |||
559 | struct path path; | 564 | struct path path; |
560 | struct vfsmount *root_mnt; | 565 | struct vfsmount *root_mnt; |
561 | struct node *node; | 566 | struct node *node; |
562 | struct list_head list; | ||
563 | int err; | 567 | int err; |
564 | 568 | ||
565 | tree = container_of(cursor.next, struct audit_tree, list); | 569 | tree = container_of(cursor.next, struct audit_tree, list); |
@@ -577,24 +581,16 @@ void audit_trim_trees(void) | |||
577 | if (!root_mnt) | 581 | if (!root_mnt) |
578 | goto skip_it; | 582 | goto skip_it; |
579 | 583 | ||
580 | list_add_tail(&list, &root_mnt->mnt_list); | ||
581 | spin_lock(&hash_lock); | 584 | spin_lock(&hash_lock); |
582 | list_for_each_entry(node, &tree->chunks, list) { | 585 | list_for_each_entry(node, &tree->chunks, list) { |
583 | struct audit_chunk *chunk = find_chunk(node); | 586 | struct inode *inode = find_chunk(node)->watch.inode; |
584 | struct inode *inode = chunk->watch.inode; | ||
585 | struct vfsmount *mnt; | ||
586 | node->index |= 1U<<31; | 587 | node->index |= 1U<<31; |
587 | list_for_each_entry(mnt, &list, mnt_list) { | 588 | if (iterate_mounts(compare_root, inode, root_mnt)) |
588 | if (mnt->mnt_root->d_inode == inode) { | 589 | node->index &= ~(1U<<31); |
589 | node->index &= ~(1U<<31); | ||
590 | break; | ||
591 | } | ||
592 | } | ||
593 | } | 590 | } |
594 | spin_unlock(&hash_lock); | 591 | spin_unlock(&hash_lock); |
595 | trim_marked(tree); | 592 | trim_marked(tree); |
596 | put_tree(tree); | 593 | put_tree(tree); |
597 | list_del_init(&list); | ||
598 | drop_collected_mounts(root_mnt); | 594 | drop_collected_mounts(root_mnt); |
599 | skip_it: | 595 | skip_it: |
600 | mutex_lock(&audit_filter_mutex); | 596 | mutex_lock(&audit_filter_mutex); |
@@ -603,22 +599,6 @@ skip_it: | |||
603 | mutex_unlock(&audit_filter_mutex); | 599 | mutex_unlock(&audit_filter_mutex); |
604 | } | 600 | } |
605 | 601 | ||
606 | static int is_under(struct vfsmount *mnt, struct dentry *dentry, | ||
607 | struct path *path) | ||
608 | { | ||
609 | if (mnt != path->mnt) { | ||
610 | for (;;) { | ||
611 | if (mnt->mnt_parent == mnt) | ||
612 | return 0; | ||
613 | if (mnt->mnt_parent == path->mnt) | ||
614 | break; | ||
615 | mnt = mnt->mnt_parent; | ||
616 | } | ||
617 | dentry = mnt->mnt_mountpoint; | ||
618 | } | ||
619 | return is_subdir(dentry, path->dentry); | ||
620 | } | ||
621 | |||
622 | int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) | 602 | int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) |
623 | { | 603 | { |
624 | 604 | ||
@@ -638,13 +618,17 @@ void audit_put_tree(struct audit_tree *tree) | |||
638 | put_tree(tree); | 618 | put_tree(tree); |
639 | } | 619 | } |
640 | 620 | ||
621 | static int tag_mount(struct vfsmount *mnt, void *arg) | ||
622 | { | ||
623 | return tag_chunk(mnt->mnt_root->d_inode, arg); | ||
624 | } | ||
625 | |||
641 | /* called with audit_filter_mutex */ | 626 | /* called with audit_filter_mutex */ |
642 | int audit_add_tree_rule(struct audit_krule *rule) | 627 | int audit_add_tree_rule(struct audit_krule *rule) |
643 | { | 628 | { |
644 | struct audit_tree *seed = rule->tree, *tree; | 629 | struct audit_tree *seed = rule->tree, *tree; |
645 | struct path path; | 630 | struct path path; |
646 | struct vfsmount *mnt, *p; | 631 | struct vfsmount *mnt; |
647 | struct list_head list; | ||
648 | int err; | 632 | int err; |
649 | 633 | ||
650 | list_for_each_entry(tree, &tree_list, list) { | 634 | list_for_each_entry(tree, &tree_list, list) { |
@@ -670,16 +654,9 @@ int audit_add_tree_rule(struct audit_krule *rule) | |||
670 | err = -ENOMEM; | 654 | err = -ENOMEM; |
671 | goto Err; | 655 | goto Err; |
672 | } | 656 | } |
673 | list_add_tail(&list, &mnt->mnt_list); | ||
674 | 657 | ||
675 | get_tree(tree); | 658 | get_tree(tree); |
676 | list_for_each_entry(p, &list, mnt_list) { | 659 | err = iterate_mounts(tag_mount, tree, mnt); |
677 | err = tag_chunk(p->mnt_root->d_inode, tree); | ||
678 | if (err) | ||
679 | break; | ||
680 | } | ||
681 | |||
682 | list_del(&list); | ||
683 | drop_collected_mounts(mnt); | 660 | drop_collected_mounts(mnt); |
684 | 661 | ||
685 | if (!err) { | 662 | if (!err) { |
@@ -714,31 +691,23 @@ int audit_tag_tree(char *old, char *new) | |||
714 | { | 691 | { |
715 | struct list_head cursor, barrier; | 692 | struct list_head cursor, barrier; |
716 | int failed = 0; | 693 | int failed = 0; |
717 | struct path path; | 694 | struct path path1, path2; |
718 | struct vfsmount *tagged; | 695 | struct vfsmount *tagged; |
719 | struct list_head list; | ||
720 | struct vfsmount *mnt; | ||
721 | struct dentry *dentry; | ||
722 | int err; | 696 | int err; |
723 | 697 | ||
724 | err = kern_path(new, 0, &path); | 698 | err = kern_path(new, 0, &path2); |
725 | if (err) | 699 | if (err) |
726 | return err; | 700 | return err; |
727 | tagged = collect_mounts(&path); | 701 | tagged = collect_mounts(&path2); |
728 | path_put(&path); | 702 | path_put(&path2); |
729 | if (!tagged) | 703 | if (!tagged) |
730 | return -ENOMEM; | 704 | return -ENOMEM; |
731 | 705 | ||
732 | err = kern_path(old, 0, &path); | 706 | err = kern_path(old, 0, &path1); |
733 | if (err) { | 707 | if (err) { |
734 | drop_collected_mounts(tagged); | 708 | drop_collected_mounts(tagged); |
735 | return err; | 709 | return err; |
736 | } | 710 | } |
737 | mnt = mntget(path.mnt); | ||
738 | dentry = dget(path.dentry); | ||
739 | path_put(&path); | ||
740 | |||
741 | list_add_tail(&list, &tagged->mnt_list); | ||
742 | 711 | ||
743 | mutex_lock(&audit_filter_mutex); | 712 | mutex_lock(&audit_filter_mutex); |
744 | list_add(&barrier, &tree_list); | 713 | list_add(&barrier, &tree_list); |
@@ -746,7 +715,7 @@ int audit_tag_tree(char *old, char *new) | |||
746 | 715 | ||
747 | while (cursor.next != &tree_list) { | 716 | while (cursor.next != &tree_list) { |
748 | struct audit_tree *tree; | 717 | struct audit_tree *tree; |
749 | struct vfsmount *p; | 718 | int good_one = 0; |
750 | 719 | ||
751 | tree = container_of(cursor.next, struct audit_tree, list); | 720 | tree = container_of(cursor.next, struct audit_tree, list); |
752 | get_tree(tree); | 721 | get_tree(tree); |
@@ -754,30 +723,19 @@ int audit_tag_tree(char *old, char *new) | |||
754 | list_add(&cursor, &tree->list); | 723 | list_add(&cursor, &tree->list); |
755 | mutex_unlock(&audit_filter_mutex); | 724 | mutex_unlock(&audit_filter_mutex); |
756 | 725 | ||
757 | err = kern_path(tree->pathname, 0, &path); | 726 | err = kern_path(tree->pathname, 0, &path2); |
758 | if (err) { | 727 | if (!err) { |
759 | put_tree(tree); | 728 | good_one = path_is_under(&path1, &path2); |
760 | mutex_lock(&audit_filter_mutex); | 729 | path_put(&path2); |
761 | continue; | ||
762 | } | 730 | } |
763 | 731 | ||
764 | spin_lock(&vfsmount_lock); | 732 | if (!good_one) { |
765 | if (!is_under(mnt, dentry, &path)) { | ||
766 | spin_unlock(&vfsmount_lock); | ||
767 | path_put(&path); | ||
768 | put_tree(tree); | 733 | put_tree(tree); |
769 | mutex_lock(&audit_filter_mutex); | 734 | mutex_lock(&audit_filter_mutex); |
770 | continue; | 735 | continue; |
771 | } | 736 | } |
772 | spin_unlock(&vfsmount_lock); | ||
773 | path_put(&path); | ||
774 | |||
775 | list_for_each_entry(p, &list, mnt_list) { | ||
776 | failed = tag_chunk(p->mnt_root->d_inode, tree); | ||
777 | if (failed) | ||
778 | break; | ||
779 | } | ||
780 | 737 | ||
738 | failed = iterate_mounts(tag_mount, tree, tagged); | ||
781 | if (failed) { | 739 | if (failed) { |
782 | put_tree(tree); | 740 | put_tree(tree); |
783 | mutex_lock(&audit_filter_mutex); | 741 | mutex_lock(&audit_filter_mutex); |
@@ -818,10 +776,8 @@ int audit_tag_tree(char *old, char *new) | |||
818 | } | 776 | } |
819 | list_del(&barrier); | 777 | list_del(&barrier); |
820 | list_del(&cursor); | 778 | list_del(&cursor); |
821 | list_del(&list); | ||
822 | mutex_unlock(&audit_filter_mutex); | 779 | mutex_unlock(&audit_filter_mutex); |
823 | dput(dentry); | 780 | path_put(&path1); |
824 | mntput(mnt); | ||
825 | drop_collected_mounts(tagged); | 781 | drop_collected_mounts(tagged); |
826 | return failed; | 782 | return failed; |
827 | } | 783 | } |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index fc0f928167e7..f3a461c0970a 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -1988,7 +1988,6 @@ void __audit_inode(const char *name, const struct dentry *dentry) | |||
1988 | 1988 | ||
1989 | /** | 1989 | /** |
1990 | * audit_inode_child - collect inode info for created/removed objects | 1990 | * audit_inode_child - collect inode info for created/removed objects |
1991 | * @dname: inode's dentry name | ||
1992 | * @dentry: dentry being audited | 1991 | * @dentry: dentry being audited |
1993 | * @parent: inode of dentry parent | 1992 | * @parent: inode of dentry parent |
1994 | * | 1993 | * |
@@ -2000,13 +1999,14 @@ void __audit_inode(const char *name, const struct dentry *dentry) | |||
2000 | * must be hooked prior, in order to capture the target inode during | 1999 | * must be hooked prior, in order to capture the target inode during |
2001 | * unsuccessful attempts. | 2000 | * unsuccessful attempts. |
2002 | */ | 2001 | */ |
2003 | void __audit_inode_child(const char *dname, const struct dentry *dentry, | 2002 | void __audit_inode_child(const struct dentry *dentry, |
2004 | const struct inode *parent) | 2003 | const struct inode *parent) |
2005 | { | 2004 | { |
2006 | int idx; | 2005 | int idx; |
2007 | struct audit_context *context = current->audit_context; | 2006 | struct audit_context *context = current->audit_context; |
2008 | const char *found_parent = NULL, *found_child = NULL; | 2007 | const char *found_parent = NULL, *found_child = NULL; |
2009 | const struct inode *inode = dentry->d_inode; | 2008 | const struct inode *inode = dentry->d_inode; |
2009 | const char *dname = dentry->d_name.name; | ||
2010 | int dirlen = 0; | 2010 | int dirlen = 0; |
2011 | 2011 | ||
2012 | if (!context->in_syscall) | 2012 | if (!context->in_syscall) |
@@ -2014,9 +2014,6 @@ void __audit_inode_child(const char *dname, const struct dentry *dentry, | |||
2014 | 2014 | ||
2015 | if (inode) | 2015 | if (inode) |
2016 | handle_one(inode); | 2016 | handle_one(inode); |
2017 | /* determine matching parent */ | ||
2018 | if (!dname) | ||
2019 | goto add_names; | ||
2020 | 2017 | ||
2021 | /* parent is more likely, look for it first */ | 2018 | /* parent is more likely, look for it first */ |
2022 | for (idx = 0; idx < context->name_count; idx++) { | 2019 | for (idx = 0; idx < context->name_count; idx++) { |
diff --git a/kernel/cpu.c b/kernel/cpu.c index 677f25376a38..f8cced2692b3 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -338,7 +338,7 @@ int __cpuinit cpu_up(unsigned int cpu) | |||
338 | if (!cpu_possible(cpu)) { | 338 | if (!cpu_possible(cpu)) { |
339 | printk(KERN_ERR "can't online cpu %d because it is not " | 339 | printk(KERN_ERR "can't online cpu %d because it is not " |
340 | "configured as may-hotadd at boot time\n", cpu); | 340 | "configured as may-hotadd at boot time\n", cpu); |
341 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) | 341 | #if defined(CONFIG_IA64) |
342 | printk(KERN_ERR "please check additional_cpus= boot " | 342 | printk(KERN_ERR "please check additional_cpus= boot " |
343 | "parameter\n"); | 343 | "parameter\n"); |
344 | #endif | 344 | #endif |
diff --git a/kernel/elfcore.c b/kernel/elfcore.c new file mode 100644 index 000000000000..ff915efef66d --- /dev/null +++ b/kernel/elfcore.c | |||
@@ -0,0 +1,28 @@ | |||
1 | #include <linux/elf.h> | ||
2 | #include <linux/fs.h> | ||
3 | #include <linux/mm.h> | ||
4 | |||
5 | #include <asm/elf.h> | ||
6 | |||
7 | |||
8 | Elf_Half __weak elf_core_extra_phdrs(void) | ||
9 | { | ||
10 | return 0; | ||
11 | } | ||
12 | |||
13 | int __weak elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size, | ||
14 | unsigned long limit) | ||
15 | { | ||
16 | return 1; | ||
17 | } | ||
18 | |||
19 | int __weak elf_core_write_extra_data(struct file *file, size_t *size, | ||
20 | unsigned long limit) | ||
21 | { | ||
22 | return 1; | ||
23 | } | ||
24 | |||
25 | size_t __weak elf_core_extra_data_size(void) | ||
26 | { | ||
27 | return 0; | ||
28 | } | ||
diff --git a/kernel/exit.c b/kernel/exit.c index 45ed043b8bf5..ce1e48c2d93d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -952,7 +952,8 @@ NORET_TYPE void do_exit(long code) | |||
952 | preempt_count()); | 952 | preempt_count()); |
953 | 953 | ||
954 | acct_update_integrals(tsk); | 954 | acct_update_integrals(tsk); |
955 | 955 | /* sync mm's RSS info before statistics gathering */ | |
956 | sync_mm_rss(tsk, tsk->mm); | ||
956 | group_dead = atomic_dec_and_test(&tsk->signal->live); | 957 | group_dead = atomic_dec_and_test(&tsk->signal->live); |
957 | if (group_dead) { | 958 | if (group_dead) { |
958 | hrtimer_cancel(&tsk->signal->real_timer); | 959 | hrtimer_cancel(&tsk->signal->real_timer); |
@@ -1188,7 +1189,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) | |||
1188 | 1189 | ||
1189 | if (unlikely(wo->wo_flags & WNOWAIT)) { | 1190 | if (unlikely(wo->wo_flags & WNOWAIT)) { |
1190 | int exit_code = p->exit_code; | 1191 | int exit_code = p->exit_code; |
1191 | int why, status; | 1192 | int why; |
1192 | 1193 | ||
1193 | get_task_struct(p); | 1194 | get_task_struct(p); |
1194 | read_unlock(&tasklist_lock); | 1195 | read_unlock(&tasklist_lock); |
diff --git a/kernel/fork.c b/kernel/fork.c index 17bbf093356d..b0ec34abc0bb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -329,15 +329,17 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) | |||
329 | if (!tmp) | 329 | if (!tmp) |
330 | goto fail_nomem; | 330 | goto fail_nomem; |
331 | *tmp = *mpnt; | 331 | *tmp = *mpnt; |
332 | INIT_LIST_HEAD(&tmp->anon_vma_chain); | ||
332 | pol = mpol_dup(vma_policy(mpnt)); | 333 | pol = mpol_dup(vma_policy(mpnt)); |
333 | retval = PTR_ERR(pol); | 334 | retval = PTR_ERR(pol); |
334 | if (IS_ERR(pol)) | 335 | if (IS_ERR(pol)) |
335 | goto fail_nomem_policy; | 336 | goto fail_nomem_policy; |
336 | vma_set_policy(tmp, pol); | 337 | vma_set_policy(tmp, pol); |
338 | if (anon_vma_fork(tmp, mpnt)) | ||
339 | goto fail_nomem_anon_vma_fork; | ||
337 | tmp->vm_flags &= ~VM_LOCKED; | 340 | tmp->vm_flags &= ~VM_LOCKED; |
338 | tmp->vm_mm = mm; | 341 | tmp->vm_mm = mm; |
339 | tmp->vm_next = NULL; | 342 | tmp->vm_next = NULL; |
340 | anon_vma_link(tmp); | ||
341 | file = tmp->vm_file; | 343 | file = tmp->vm_file; |
342 | if (file) { | 344 | if (file) { |
343 | struct inode *inode = file->f_path.dentry->d_inode; | 345 | struct inode *inode = file->f_path.dentry->d_inode; |
@@ -392,6 +394,8 @@ out: | |||
392 | flush_tlb_mm(oldmm); | 394 | flush_tlb_mm(oldmm); |
393 | up_write(&oldmm->mmap_sem); | 395 | up_write(&oldmm->mmap_sem); |
394 | return retval; | 396 | return retval; |
397 | fail_nomem_anon_vma_fork: | ||
398 | mpol_put(pol); | ||
395 | fail_nomem_policy: | 399 | fail_nomem_policy: |
396 | kmem_cache_free(vm_area_cachep, tmp); | 400 | kmem_cache_free(vm_area_cachep, tmp); |
397 | fail_nomem: | 401 | fail_nomem: |
@@ -455,8 +459,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) | |||
455 | (current->mm->flags & MMF_INIT_MASK) : default_dump_filter; | 459 | (current->mm->flags & MMF_INIT_MASK) : default_dump_filter; |
456 | mm->core_state = NULL; | 460 | mm->core_state = NULL; |
457 | mm->nr_ptes = 0; | 461 | mm->nr_ptes = 0; |
458 | set_mm_counter(mm, file_rss, 0); | 462 | memset(&mm->rss_stat, 0, sizeof(mm->rss_stat)); |
459 | set_mm_counter(mm, anon_rss, 0); | ||
460 | spin_lock_init(&mm->page_table_lock); | 463 | spin_lock_init(&mm->page_table_lock); |
461 | mm->free_area_cache = TASK_UNMAPPED_BASE; | 464 | mm->free_area_cache = TASK_UNMAPPED_BASE; |
462 | mm->cached_hole_size = ~0UL; | 465 | mm->cached_hole_size = ~0UL; |
@@ -825,6 +828,8 @@ void __cleanup_sighand(struct sighand_struct *sighand) | |||
825 | */ | 828 | */ |
826 | static void posix_cpu_timers_init_group(struct signal_struct *sig) | 829 | static void posix_cpu_timers_init_group(struct signal_struct *sig) |
827 | { | 830 | { |
831 | unsigned long cpu_limit; | ||
832 | |||
828 | /* Thread group counters. */ | 833 | /* Thread group counters. */ |
829 | thread_group_cputime_init(sig); | 834 | thread_group_cputime_init(sig); |
830 | 835 | ||
@@ -839,9 +844,9 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig) | |||
839 | sig->cputime_expires.virt_exp = cputime_zero; | 844 | sig->cputime_expires.virt_exp = cputime_zero; |
840 | sig->cputime_expires.sched_exp = 0; | 845 | sig->cputime_expires.sched_exp = 0; |
841 | 846 | ||
842 | if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { | 847 | cpu_limit = ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur); |
843 | sig->cputime_expires.prof_exp = | 848 | if (cpu_limit != RLIM_INFINITY) { |
844 | secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); | 849 | sig->cputime_expires.prof_exp = secs_to_cputime(cpu_limit); |
845 | sig->cputimer.running = 1; | 850 | sig->cputimer.running = 1; |
846 | } | 851 | } |
847 | 852 | ||
@@ -1034,7 +1039,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1034 | #endif | 1039 | #endif |
1035 | retval = -EAGAIN; | 1040 | retval = -EAGAIN; |
1036 | if (atomic_read(&p->real_cred->user->processes) >= | 1041 | if (atomic_read(&p->real_cred->user->processes) >= |
1037 | p->signal->rlim[RLIMIT_NPROC].rlim_cur) { | 1042 | task_rlimit(p, RLIMIT_NPROC)) { |
1038 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && | 1043 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && |
1039 | p->real_cred->user != INIT_USER) | 1044 | p->real_cred->user != INIT_USER) |
1040 | goto bad_fork_free; | 1045 | goto bad_fork_free; |
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index ccec774c716d..fa034d29cf73 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -42,9 +42,11 @@ | |||
42 | #include <linux/freezer.h> | 42 | #include <linux/freezer.h> |
43 | #include <linux/seq_file.h> | 43 | #include <linux/seq_file.h> |
44 | #include <linux/debugfs.h> | 44 | #include <linux/debugfs.h> |
45 | #include <linux/sysctl.h> | ||
45 | #include <linux/kdebug.h> | 46 | #include <linux/kdebug.h> |
46 | #include <linux/memory.h> | 47 | #include <linux/memory.h> |
47 | #include <linux/ftrace.h> | 48 | #include <linux/ftrace.h> |
49 | #include <linux/cpu.h> | ||
48 | 50 | ||
49 | #include <asm-generic/sections.h> | 51 | #include <asm-generic/sections.h> |
50 | #include <asm/cacheflush.h> | 52 | #include <asm/cacheflush.h> |
@@ -105,57 +107,74 @@ static struct kprobe_blackpoint kprobe_blacklist[] = { | |||
105 | * stepping on the instruction on a vmalloced/kmalloced/data page | 107 | * stepping on the instruction on a vmalloced/kmalloced/data page |
106 | * is a recipe for disaster | 108 | * is a recipe for disaster |
107 | */ | 109 | */ |
108 | #define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t))) | ||
109 | |||
110 | struct kprobe_insn_page { | 110 | struct kprobe_insn_page { |
111 | struct list_head list; | 111 | struct list_head list; |
112 | kprobe_opcode_t *insns; /* Page of instruction slots */ | 112 | kprobe_opcode_t *insns; /* Page of instruction slots */ |
113 | char slot_used[INSNS_PER_PAGE]; | ||
114 | int nused; | 113 | int nused; |
115 | int ngarbage; | 114 | int ngarbage; |
115 | char slot_used[]; | ||
116 | }; | ||
117 | |||
118 | #define KPROBE_INSN_PAGE_SIZE(slots) \ | ||
119 | (offsetof(struct kprobe_insn_page, slot_used) + \ | ||
120 | (sizeof(char) * (slots))) | ||
121 | |||
122 | struct kprobe_insn_cache { | ||
123 | struct list_head pages; /* list of kprobe_insn_page */ | ||
124 | size_t insn_size; /* size of instruction slot */ | ||
125 | int nr_garbage; | ||
116 | }; | 126 | }; |
117 | 127 | ||
128 | static int slots_per_page(struct kprobe_insn_cache *c) | ||
129 | { | ||
130 | return PAGE_SIZE/(c->insn_size * sizeof(kprobe_opcode_t)); | ||
131 | } | ||
132 | |||
118 | enum kprobe_slot_state { | 133 | enum kprobe_slot_state { |
119 | SLOT_CLEAN = 0, | 134 | SLOT_CLEAN = 0, |
120 | SLOT_DIRTY = 1, | 135 | SLOT_DIRTY = 1, |
121 | SLOT_USED = 2, | 136 | SLOT_USED = 2, |
122 | }; | 137 | }; |
123 | 138 | ||
124 | static DEFINE_MUTEX(kprobe_insn_mutex); /* Protects kprobe_insn_pages */ | 139 | static DEFINE_MUTEX(kprobe_insn_mutex); /* Protects kprobe_insn_slots */ |
125 | static LIST_HEAD(kprobe_insn_pages); | 140 | static struct kprobe_insn_cache kprobe_insn_slots = { |
126 | static int kprobe_garbage_slots; | 141 | .pages = LIST_HEAD_INIT(kprobe_insn_slots.pages), |
127 | static int collect_garbage_slots(void); | 142 | .insn_size = MAX_INSN_SIZE, |
143 | .nr_garbage = 0, | ||
144 | }; | ||
145 | static int __kprobes collect_garbage_slots(struct kprobe_insn_cache *c); | ||
128 | 146 | ||
129 | /** | 147 | /** |
130 | * __get_insn_slot() - Find a slot on an executable page for an instruction. | 148 | * __get_insn_slot() - Find a slot on an executable page for an instruction. |
131 | * We allocate an executable page if there's no room on existing ones. | 149 | * We allocate an executable page if there's no room on existing ones. |
132 | */ | 150 | */ |
133 | static kprobe_opcode_t __kprobes *__get_insn_slot(void) | 151 | static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c) |
134 | { | 152 | { |
135 | struct kprobe_insn_page *kip; | 153 | struct kprobe_insn_page *kip; |
136 | 154 | ||
137 | retry: | 155 | retry: |
138 | list_for_each_entry(kip, &kprobe_insn_pages, list) { | 156 | list_for_each_entry(kip, &c->pages, list) { |
139 | if (kip->nused < INSNS_PER_PAGE) { | 157 | if (kip->nused < slots_per_page(c)) { |
140 | int i; | 158 | int i; |
141 | for (i = 0; i < INSNS_PER_PAGE; i++) { | 159 | for (i = 0; i < slots_per_page(c); i++) { |
142 | if (kip->slot_used[i] == SLOT_CLEAN) { | 160 | if (kip->slot_used[i] == SLOT_CLEAN) { |
143 | kip->slot_used[i] = SLOT_USED; | 161 | kip->slot_used[i] = SLOT_USED; |
144 | kip->nused++; | 162 | kip->nused++; |
145 | return kip->insns + (i * MAX_INSN_SIZE); | 163 | return kip->insns + (i * c->insn_size); |
146 | } | 164 | } |
147 | } | 165 | } |
148 | /* Surprise! No unused slots. Fix kip->nused. */ | 166 | /* kip->nused is broken. Fix it. */ |
149 | kip->nused = INSNS_PER_PAGE; | 167 | kip->nused = slots_per_page(c); |
168 | WARN_ON(1); | ||
150 | } | 169 | } |
151 | } | 170 | } |
152 | 171 | ||
153 | /* If there are any garbage slots, collect it and try again. */ | 172 | /* If there are any garbage slots, collect it and try again. */ |
154 | if (kprobe_garbage_slots && collect_garbage_slots() == 0) { | 173 | if (c->nr_garbage && collect_garbage_slots(c) == 0) |
155 | goto retry; | 174 | goto retry; |
156 | } | 175 | |
157 | /* All out of space. Need to allocate a new page. Use slot 0. */ | 176 | /* All out of space. Need to allocate a new page. */ |
158 | kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL); | 177 | kip = kmalloc(KPROBE_INSN_PAGE_SIZE(slots_per_page(c)), GFP_KERNEL); |
159 | if (!kip) | 178 | if (!kip) |
160 | return NULL; | 179 | return NULL; |
161 | 180 | ||
@@ -170,20 +189,23 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void) | |||
170 | return NULL; | 189 | return NULL; |
171 | } | 190 | } |
172 | INIT_LIST_HEAD(&kip->list); | 191 | INIT_LIST_HEAD(&kip->list); |
173 | list_add(&kip->list, &kprobe_insn_pages); | 192 | memset(kip->slot_used, SLOT_CLEAN, slots_per_page(c)); |
174 | memset(kip->slot_used, SLOT_CLEAN, INSNS_PER_PAGE); | ||
175 | kip->slot_used[0] = SLOT_USED; | 193 | kip->slot_used[0] = SLOT_USED; |
176 | kip->nused = 1; | 194 | kip->nused = 1; |
177 | kip->ngarbage = 0; | 195 | kip->ngarbage = 0; |
196 | list_add(&kip->list, &c->pages); | ||
178 | return kip->insns; | 197 | return kip->insns; |
179 | } | 198 | } |
180 | 199 | ||
200 | |||
181 | kprobe_opcode_t __kprobes *get_insn_slot(void) | 201 | kprobe_opcode_t __kprobes *get_insn_slot(void) |
182 | { | 202 | { |
183 | kprobe_opcode_t *ret; | 203 | kprobe_opcode_t *ret = NULL; |
204 | |||
184 | mutex_lock(&kprobe_insn_mutex); | 205 | mutex_lock(&kprobe_insn_mutex); |
185 | ret = __get_insn_slot(); | 206 | ret = __get_insn_slot(&kprobe_insn_slots); |
186 | mutex_unlock(&kprobe_insn_mutex); | 207 | mutex_unlock(&kprobe_insn_mutex); |
208 | |||
187 | return ret; | 209 | return ret; |
188 | } | 210 | } |
189 | 211 | ||
@@ -199,7 +221,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx) | |||
199 | * so as not to have to set it up again the | 221 | * so as not to have to set it up again the |
200 | * next time somebody inserts a probe. | 222 | * next time somebody inserts a probe. |
201 | */ | 223 | */ |
202 | if (!list_is_singular(&kprobe_insn_pages)) { | 224 | if (!list_is_singular(&kip->list)) { |
203 | list_del(&kip->list); | 225 | list_del(&kip->list); |
204 | module_free(NULL, kip->insns); | 226 | module_free(NULL, kip->insns); |
205 | kfree(kip); | 227 | kfree(kip); |
@@ -209,51 +231,84 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx) | |||
209 | return 0; | 231 | return 0; |
210 | } | 232 | } |
211 | 233 | ||
212 | static int __kprobes collect_garbage_slots(void) | 234 | static int __kprobes collect_garbage_slots(struct kprobe_insn_cache *c) |
213 | { | 235 | { |
214 | struct kprobe_insn_page *kip, *next; | 236 | struct kprobe_insn_page *kip, *next; |
215 | 237 | ||
216 | /* Ensure no-one is interrupted on the garbages */ | 238 | /* Ensure no-one is interrupted on the garbages */ |
217 | synchronize_sched(); | 239 | synchronize_sched(); |
218 | 240 | ||
219 | list_for_each_entry_safe(kip, next, &kprobe_insn_pages, list) { | 241 | list_for_each_entry_safe(kip, next, &c->pages, list) { |
220 | int i; | 242 | int i; |
221 | if (kip->ngarbage == 0) | 243 | if (kip->ngarbage == 0) |
222 | continue; | 244 | continue; |
223 | kip->ngarbage = 0; /* we will collect all garbages */ | 245 | kip->ngarbage = 0; /* we will collect all garbages */ |
224 | for (i = 0; i < INSNS_PER_PAGE; i++) { | 246 | for (i = 0; i < slots_per_page(c); i++) { |
225 | if (kip->slot_used[i] == SLOT_DIRTY && | 247 | if (kip->slot_used[i] == SLOT_DIRTY && |
226 | collect_one_slot(kip, i)) | 248 | collect_one_slot(kip, i)) |
227 | break; | 249 | break; |
228 | } | 250 | } |
229 | } | 251 | } |
230 | kprobe_garbage_slots = 0; | 252 | c->nr_garbage = 0; |
231 | return 0; | 253 | return 0; |
232 | } | 254 | } |
233 | 255 | ||
234 | void __kprobes free_insn_slot(kprobe_opcode_t * slot, int dirty) | 256 | static void __kprobes __free_insn_slot(struct kprobe_insn_cache *c, |
257 | kprobe_opcode_t *slot, int dirty) | ||
235 | { | 258 | { |
236 | struct kprobe_insn_page *kip; | 259 | struct kprobe_insn_page *kip; |
237 | 260 | ||
238 | mutex_lock(&kprobe_insn_mutex); | 261 | list_for_each_entry(kip, &c->pages, list) { |
239 | list_for_each_entry(kip, &kprobe_insn_pages, list) { | 262 | long idx = ((long)slot - (long)kip->insns) / c->insn_size; |
240 | if (kip->insns <= slot && | 263 | if (idx >= 0 && idx < slots_per_page(c)) { |
241 | slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) { | 264 | WARN_ON(kip->slot_used[idx] != SLOT_USED); |
242 | int i = (slot - kip->insns) / MAX_INSN_SIZE; | ||
243 | if (dirty) { | 265 | if (dirty) { |
244 | kip->slot_used[i] = SLOT_DIRTY; | 266 | kip->slot_used[idx] = SLOT_DIRTY; |
245 | kip->ngarbage++; | 267 | kip->ngarbage++; |
268 | if (++c->nr_garbage > slots_per_page(c)) | ||
269 | collect_garbage_slots(c); | ||
246 | } else | 270 | } else |
247 | collect_one_slot(kip, i); | 271 | collect_one_slot(kip, idx); |
248 | break; | 272 | return; |
249 | } | 273 | } |
250 | } | 274 | } |
275 | /* Could not free this slot. */ | ||
276 | WARN_ON(1); | ||
277 | } | ||
251 | 278 | ||
252 | if (dirty && ++kprobe_garbage_slots > INSNS_PER_PAGE) | 279 | void __kprobes free_insn_slot(kprobe_opcode_t * slot, int dirty) |
253 | collect_garbage_slots(); | 280 | { |
254 | 281 | mutex_lock(&kprobe_insn_mutex); | |
282 | __free_insn_slot(&kprobe_insn_slots, slot, dirty); | ||
255 | mutex_unlock(&kprobe_insn_mutex); | 283 | mutex_unlock(&kprobe_insn_mutex); |
256 | } | 284 | } |
285 | #ifdef CONFIG_OPTPROBES | ||
286 | /* For optimized_kprobe buffer */ | ||
287 | static DEFINE_MUTEX(kprobe_optinsn_mutex); /* Protects kprobe_optinsn_slots */ | ||
288 | static struct kprobe_insn_cache kprobe_optinsn_slots = { | ||
289 | .pages = LIST_HEAD_INIT(kprobe_optinsn_slots.pages), | ||
290 | /* .insn_size is initialized later */ | ||
291 | .nr_garbage = 0, | ||
292 | }; | ||
293 | /* Get a slot for optimized_kprobe buffer */ | ||
294 | kprobe_opcode_t __kprobes *get_optinsn_slot(void) | ||
295 | { | ||
296 | kprobe_opcode_t *ret = NULL; | ||
297 | |||
298 | mutex_lock(&kprobe_optinsn_mutex); | ||
299 | ret = __get_insn_slot(&kprobe_optinsn_slots); | ||
300 | mutex_unlock(&kprobe_optinsn_mutex); | ||
301 | |||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | void __kprobes free_optinsn_slot(kprobe_opcode_t * slot, int dirty) | ||
306 | { | ||
307 | mutex_lock(&kprobe_optinsn_mutex); | ||
308 | __free_insn_slot(&kprobe_optinsn_slots, slot, dirty); | ||
309 | mutex_unlock(&kprobe_optinsn_mutex); | ||
310 | } | ||
311 | #endif | ||
257 | #endif | 312 | #endif |
258 | 313 | ||
259 | /* We have preemption disabled.. so it is safe to use __ versions */ | 314 | /* We have preemption disabled.. so it is safe to use __ versions */ |
@@ -284,23 +339,401 @@ struct kprobe __kprobes *get_kprobe(void *addr) | |||
284 | if (p->addr == addr) | 339 | if (p->addr == addr) |
285 | return p; | 340 | return p; |
286 | } | 341 | } |
342 | |||
343 | return NULL; | ||
344 | } | ||
345 | |||
346 | static int __kprobes aggr_pre_handler(struct kprobe *p, struct pt_regs *regs); | ||
347 | |||
348 | /* Return true if the kprobe is an aggregator */ | ||
349 | static inline int kprobe_aggrprobe(struct kprobe *p) | ||
350 | { | ||
351 | return p->pre_handler == aggr_pre_handler; | ||
352 | } | ||
353 | |||
354 | /* | ||
355 | * Keep all fields in the kprobe consistent | ||
356 | */ | ||
357 | static inline void copy_kprobe(struct kprobe *old_p, struct kprobe *p) | ||
358 | { | ||
359 | memcpy(&p->opcode, &old_p->opcode, sizeof(kprobe_opcode_t)); | ||
360 | memcpy(&p->ainsn, &old_p->ainsn, sizeof(struct arch_specific_insn)); | ||
361 | } | ||
362 | |||
363 | #ifdef CONFIG_OPTPROBES | ||
364 | /* NOTE: change this value only with kprobe_mutex held */ | ||
365 | static bool kprobes_allow_optimization; | ||
366 | |||
367 | /* | ||
368 | * Call all pre_handler on the list, but ignores its return value. | ||
369 | * This must be called from arch-dep optimized caller. | ||
370 | */ | ||
371 | void __kprobes opt_pre_handler(struct kprobe *p, struct pt_regs *regs) | ||
372 | { | ||
373 | struct kprobe *kp; | ||
374 | |||
375 | list_for_each_entry_rcu(kp, &p->list, list) { | ||
376 | if (kp->pre_handler && likely(!kprobe_disabled(kp))) { | ||
377 | set_kprobe_instance(kp); | ||
378 | kp->pre_handler(kp, regs); | ||
379 | } | ||
380 | reset_kprobe_instance(); | ||
381 | } | ||
382 | } | ||
383 | |||
384 | /* Return true(!0) if the kprobe is ready for optimization. */ | ||
385 | static inline int kprobe_optready(struct kprobe *p) | ||
386 | { | ||
387 | struct optimized_kprobe *op; | ||
388 | |||
389 | if (kprobe_aggrprobe(p)) { | ||
390 | op = container_of(p, struct optimized_kprobe, kp); | ||
391 | return arch_prepared_optinsn(&op->optinsn); | ||
392 | } | ||
393 | |||
394 | return 0; | ||
395 | } | ||
396 | |||
397 | /* | ||
398 | * Return an optimized kprobe whose optimizing code replaces | ||
399 | * instructions including addr (exclude breakpoint). | ||
400 | */ | ||
401 | struct kprobe *__kprobes get_optimized_kprobe(unsigned long addr) | ||
402 | { | ||
403 | int i; | ||
404 | struct kprobe *p = NULL; | ||
405 | struct optimized_kprobe *op; | ||
406 | |||
407 | /* Don't check i == 0, since that is a breakpoint case. */ | ||
408 | for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH; i++) | ||
409 | p = get_kprobe((void *)(addr - i)); | ||
410 | |||
411 | if (p && kprobe_optready(p)) { | ||
412 | op = container_of(p, struct optimized_kprobe, kp); | ||
413 | if (arch_within_optimized_kprobe(op, addr)) | ||
414 | return p; | ||
415 | } | ||
416 | |||
287 | return NULL; | 417 | return NULL; |
288 | } | 418 | } |
289 | 419 | ||
420 | /* Optimization staging list, protected by kprobe_mutex */ | ||
421 | static LIST_HEAD(optimizing_list); | ||
422 | |||
423 | static void kprobe_optimizer(struct work_struct *work); | ||
424 | static DECLARE_DELAYED_WORK(optimizing_work, kprobe_optimizer); | ||
425 | #define OPTIMIZE_DELAY 5 | ||
426 | |||
427 | /* Kprobe jump optimizer */ | ||
428 | static __kprobes void kprobe_optimizer(struct work_struct *work) | ||
429 | { | ||
430 | struct optimized_kprobe *op, *tmp; | ||
431 | |||
432 | /* Lock modules while optimizing kprobes */ | ||
433 | mutex_lock(&module_mutex); | ||
434 | mutex_lock(&kprobe_mutex); | ||
435 | if (kprobes_all_disarmed || !kprobes_allow_optimization) | ||
436 | goto end; | ||
437 | |||
438 | /* | ||
439 | * Wait for quiesence period to ensure all running interrupts | ||
440 | * are done. Because optprobe may modify multiple instructions | ||
441 | * there is a chance that Nth instruction is interrupted. In that | ||
442 | * case, running interrupt can return to 2nd-Nth byte of jump | ||
443 | * instruction. This wait is for avoiding it. | ||
444 | */ | ||
445 | synchronize_sched(); | ||
446 | |||
447 | /* | ||
448 | * The optimization/unoptimization refers online_cpus via | ||
449 | * stop_machine() and cpu-hotplug modifies online_cpus. | ||
450 | * And same time, text_mutex will be held in cpu-hotplug and here. | ||
451 | * This combination can cause a deadlock (cpu-hotplug try to lock | ||
452 | * text_mutex but stop_machine can not be done because online_cpus | ||
453 | * has been changed) | ||
454 | * To avoid this deadlock, we need to call get_online_cpus() | ||
455 | * for preventing cpu-hotplug outside of text_mutex locking. | ||
456 | */ | ||
457 | get_online_cpus(); | ||
458 | mutex_lock(&text_mutex); | ||
459 | list_for_each_entry_safe(op, tmp, &optimizing_list, list) { | ||
460 | WARN_ON(kprobe_disabled(&op->kp)); | ||
461 | if (arch_optimize_kprobe(op) < 0) | ||
462 | op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; | ||
463 | list_del_init(&op->list); | ||
464 | } | ||
465 | mutex_unlock(&text_mutex); | ||
466 | put_online_cpus(); | ||
467 | end: | ||
468 | mutex_unlock(&kprobe_mutex); | ||
469 | mutex_unlock(&module_mutex); | ||
470 | } | ||
471 | |||
472 | /* Optimize kprobe if p is ready to be optimized */ | ||
473 | static __kprobes void optimize_kprobe(struct kprobe *p) | ||
474 | { | ||
475 | struct optimized_kprobe *op; | ||
476 | |||
477 | /* Check if the kprobe is disabled or not ready for optimization. */ | ||
478 | if (!kprobe_optready(p) || !kprobes_allow_optimization || | ||
479 | (kprobe_disabled(p) || kprobes_all_disarmed)) | ||
480 | return; | ||
481 | |||
482 | /* Both of break_handler and post_handler are not supported. */ | ||
483 | if (p->break_handler || p->post_handler) | ||
484 | return; | ||
485 | |||
486 | op = container_of(p, struct optimized_kprobe, kp); | ||
487 | |||
488 | /* Check there is no other kprobes at the optimized instructions */ | ||
489 | if (arch_check_optimized_kprobe(op) < 0) | ||
490 | return; | ||
491 | |||
492 | /* Check if it is already optimized. */ | ||
493 | if (op->kp.flags & KPROBE_FLAG_OPTIMIZED) | ||
494 | return; | ||
495 | |||
496 | op->kp.flags |= KPROBE_FLAG_OPTIMIZED; | ||
497 | list_add(&op->list, &optimizing_list); | ||
498 | if (!delayed_work_pending(&optimizing_work)) | ||
499 | schedule_delayed_work(&optimizing_work, OPTIMIZE_DELAY); | ||
500 | } | ||
501 | |||
502 | /* Unoptimize a kprobe if p is optimized */ | ||
503 | static __kprobes void unoptimize_kprobe(struct kprobe *p) | ||
504 | { | ||
505 | struct optimized_kprobe *op; | ||
506 | |||
507 | if ((p->flags & KPROBE_FLAG_OPTIMIZED) && kprobe_aggrprobe(p)) { | ||
508 | op = container_of(p, struct optimized_kprobe, kp); | ||
509 | if (!list_empty(&op->list)) | ||
510 | /* Dequeue from the optimization queue */ | ||
511 | list_del_init(&op->list); | ||
512 | else | ||
513 | /* Replace jump with break */ | ||
514 | arch_unoptimize_kprobe(op); | ||
515 | op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; | ||
516 | } | ||
517 | } | ||
518 | |||
519 | /* Remove optimized instructions */ | ||
520 | static void __kprobes kill_optimized_kprobe(struct kprobe *p) | ||
521 | { | ||
522 | struct optimized_kprobe *op; | ||
523 | |||
524 | op = container_of(p, struct optimized_kprobe, kp); | ||
525 | if (!list_empty(&op->list)) { | ||
526 | /* Dequeue from the optimization queue */ | ||
527 | list_del_init(&op->list); | ||
528 | op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; | ||
529 | } | ||
530 | /* Don't unoptimize, because the target code will be freed. */ | ||
531 | arch_remove_optimized_kprobe(op); | ||
532 | } | ||
533 | |||
534 | /* Try to prepare optimized instructions */ | ||
535 | static __kprobes void prepare_optimized_kprobe(struct kprobe *p) | ||
536 | { | ||
537 | struct optimized_kprobe *op; | ||
538 | |||
539 | op = container_of(p, struct optimized_kprobe, kp); | ||
540 | arch_prepare_optimized_kprobe(op); | ||
541 | } | ||
542 | |||
543 | /* Free optimized instructions and optimized_kprobe */ | ||
544 | static __kprobes void free_aggr_kprobe(struct kprobe *p) | ||
545 | { | ||
546 | struct optimized_kprobe *op; | ||
547 | |||
548 | op = container_of(p, struct optimized_kprobe, kp); | ||
549 | arch_remove_optimized_kprobe(op); | ||
550 | kfree(op); | ||
551 | } | ||
552 | |||
553 | /* Allocate new optimized_kprobe and try to prepare optimized instructions */ | ||
554 | static __kprobes struct kprobe *alloc_aggr_kprobe(struct kprobe *p) | ||
555 | { | ||
556 | struct optimized_kprobe *op; | ||
557 | |||
558 | op = kzalloc(sizeof(struct optimized_kprobe), GFP_KERNEL); | ||
559 | if (!op) | ||
560 | return NULL; | ||
561 | |||
562 | INIT_LIST_HEAD(&op->list); | ||
563 | op->kp.addr = p->addr; | ||
564 | arch_prepare_optimized_kprobe(op); | ||
565 | |||
566 | return &op->kp; | ||
567 | } | ||
568 | |||
569 | static void __kprobes init_aggr_kprobe(struct kprobe *ap, struct kprobe *p); | ||
570 | |||
571 | /* | ||
572 | * Prepare an optimized_kprobe and optimize it | ||
573 | * NOTE: p must be a normal registered kprobe | ||
574 | */ | ||
575 | static __kprobes void try_to_optimize_kprobe(struct kprobe *p) | ||
576 | { | ||
577 | struct kprobe *ap; | ||
578 | struct optimized_kprobe *op; | ||
579 | |||
580 | ap = alloc_aggr_kprobe(p); | ||
581 | if (!ap) | ||
582 | return; | ||
583 | |||
584 | op = container_of(ap, struct optimized_kprobe, kp); | ||
585 | if (!arch_prepared_optinsn(&op->optinsn)) { | ||
586 | /* If failed to setup optimizing, fallback to kprobe */ | ||
587 | free_aggr_kprobe(ap); | ||
588 | return; | ||
589 | } | ||
590 | |||
591 | init_aggr_kprobe(ap, p); | ||
592 | optimize_kprobe(ap); | ||
593 | } | ||
594 | |||
595 | #ifdef CONFIG_SYSCTL | ||
596 | static void __kprobes optimize_all_kprobes(void) | ||
597 | { | ||
598 | struct hlist_head *head; | ||
599 | struct hlist_node *node; | ||
600 | struct kprobe *p; | ||
601 | unsigned int i; | ||
602 | |||
603 | /* If optimization is already allowed, just return */ | ||
604 | if (kprobes_allow_optimization) | ||
605 | return; | ||
606 | |||
607 | kprobes_allow_optimization = true; | ||
608 | mutex_lock(&text_mutex); | ||
609 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | ||
610 | head = &kprobe_table[i]; | ||
611 | hlist_for_each_entry_rcu(p, node, head, hlist) | ||
612 | if (!kprobe_disabled(p)) | ||
613 | optimize_kprobe(p); | ||
614 | } | ||
615 | mutex_unlock(&text_mutex); | ||
616 | printk(KERN_INFO "Kprobes globally optimized\n"); | ||
617 | } | ||
618 | |||
619 | static void __kprobes unoptimize_all_kprobes(void) | ||
620 | { | ||
621 | struct hlist_head *head; | ||
622 | struct hlist_node *node; | ||
623 | struct kprobe *p; | ||
624 | unsigned int i; | ||
625 | |||
626 | /* If optimization is already prohibited, just return */ | ||
627 | if (!kprobes_allow_optimization) | ||
628 | return; | ||
629 | |||
630 | kprobes_allow_optimization = false; | ||
631 | printk(KERN_INFO "Kprobes globally unoptimized\n"); | ||
632 | get_online_cpus(); /* For avoiding text_mutex deadlock */ | ||
633 | mutex_lock(&text_mutex); | ||
634 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | ||
635 | head = &kprobe_table[i]; | ||
636 | hlist_for_each_entry_rcu(p, node, head, hlist) { | ||
637 | if (!kprobe_disabled(p)) | ||
638 | unoptimize_kprobe(p); | ||
639 | } | ||
640 | } | ||
641 | |||
642 | mutex_unlock(&text_mutex); | ||
643 | put_online_cpus(); | ||
644 | /* Allow all currently running kprobes to complete */ | ||
645 | synchronize_sched(); | ||
646 | } | ||
647 | |||
648 | int sysctl_kprobes_optimization; | ||
649 | int proc_kprobes_optimization_handler(struct ctl_table *table, int write, | ||
650 | void __user *buffer, size_t *length, | ||
651 | loff_t *ppos) | ||
652 | { | ||
653 | int ret; | ||
654 | |||
655 | mutex_lock(&kprobe_mutex); | ||
656 | sysctl_kprobes_optimization = kprobes_allow_optimization ? 1 : 0; | ||
657 | ret = proc_dointvec_minmax(table, write, buffer, length, ppos); | ||
658 | |||
659 | if (sysctl_kprobes_optimization) | ||
660 | optimize_all_kprobes(); | ||
661 | else | ||
662 | unoptimize_all_kprobes(); | ||
663 | mutex_unlock(&kprobe_mutex); | ||
664 | |||
665 | return ret; | ||
666 | } | ||
667 | #endif /* CONFIG_SYSCTL */ | ||
668 | |||
669 | static void __kprobes __arm_kprobe(struct kprobe *p) | ||
670 | { | ||
671 | struct kprobe *old_p; | ||
672 | |||
673 | /* Check collision with other optimized kprobes */ | ||
674 | old_p = get_optimized_kprobe((unsigned long)p->addr); | ||
675 | if (unlikely(old_p)) | ||
676 | unoptimize_kprobe(old_p); /* Fallback to unoptimized kprobe */ | ||
677 | |||
678 | arch_arm_kprobe(p); | ||
679 | optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */ | ||
680 | } | ||
681 | |||
682 | static void __kprobes __disarm_kprobe(struct kprobe *p) | ||
683 | { | ||
684 | struct kprobe *old_p; | ||
685 | |||
686 | unoptimize_kprobe(p); /* Try to unoptimize */ | ||
687 | arch_disarm_kprobe(p); | ||
688 | |||
689 | /* If another kprobe was blocked, optimize it. */ | ||
690 | old_p = get_optimized_kprobe((unsigned long)p->addr); | ||
691 | if (unlikely(old_p)) | ||
692 | optimize_kprobe(old_p); | ||
693 | } | ||
694 | |||
695 | #else /* !CONFIG_OPTPROBES */ | ||
696 | |||
697 | #define optimize_kprobe(p) do {} while (0) | ||
698 | #define unoptimize_kprobe(p) do {} while (0) | ||
699 | #define kill_optimized_kprobe(p) do {} while (0) | ||
700 | #define prepare_optimized_kprobe(p) do {} while (0) | ||
701 | #define try_to_optimize_kprobe(p) do {} while (0) | ||
702 | #define __arm_kprobe(p) arch_arm_kprobe(p) | ||
703 | #define __disarm_kprobe(p) arch_disarm_kprobe(p) | ||
704 | |||
705 | static __kprobes void free_aggr_kprobe(struct kprobe *p) | ||
706 | { | ||
707 | kfree(p); | ||
708 | } | ||
709 | |||
710 | static __kprobes struct kprobe *alloc_aggr_kprobe(struct kprobe *p) | ||
711 | { | ||
712 | return kzalloc(sizeof(struct kprobe), GFP_KERNEL); | ||
713 | } | ||
714 | #endif /* CONFIG_OPTPROBES */ | ||
715 | |||
290 | /* Arm a kprobe with text_mutex */ | 716 | /* Arm a kprobe with text_mutex */ |
291 | static void __kprobes arm_kprobe(struct kprobe *kp) | 717 | static void __kprobes arm_kprobe(struct kprobe *kp) |
292 | { | 718 | { |
719 | /* | ||
720 | * Here, since __arm_kprobe() doesn't use stop_machine(), | ||
721 | * this doesn't cause deadlock on text_mutex. So, we don't | ||
722 | * need get_online_cpus(). | ||
723 | */ | ||
293 | mutex_lock(&text_mutex); | 724 | mutex_lock(&text_mutex); |
294 | arch_arm_kprobe(kp); | 725 | __arm_kprobe(kp); |
295 | mutex_unlock(&text_mutex); | 726 | mutex_unlock(&text_mutex); |
296 | } | 727 | } |
297 | 728 | ||
298 | /* Disarm a kprobe with text_mutex */ | 729 | /* Disarm a kprobe with text_mutex */ |
299 | static void __kprobes disarm_kprobe(struct kprobe *kp) | 730 | static void __kprobes disarm_kprobe(struct kprobe *kp) |
300 | { | 731 | { |
732 | get_online_cpus(); /* For avoiding text_mutex deadlock */ | ||
301 | mutex_lock(&text_mutex); | 733 | mutex_lock(&text_mutex); |
302 | arch_disarm_kprobe(kp); | 734 | __disarm_kprobe(kp); |
303 | mutex_unlock(&text_mutex); | 735 | mutex_unlock(&text_mutex); |
736 | put_online_cpus(); | ||
304 | } | 737 | } |
305 | 738 | ||
306 | /* | 739 | /* |
@@ -369,7 +802,7 @@ static int __kprobes aggr_break_handler(struct kprobe *p, struct pt_regs *regs) | |||
369 | void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) | 802 | void __kprobes kprobes_inc_nmissed_count(struct kprobe *p) |
370 | { | 803 | { |
371 | struct kprobe *kp; | 804 | struct kprobe *kp; |
372 | if (p->pre_handler != aggr_pre_handler) { | 805 | if (!kprobe_aggrprobe(p)) { |
373 | p->nmissed++; | 806 | p->nmissed++; |
374 | } else { | 807 | } else { |
375 | list_for_each_entry_rcu(kp, &p->list, list) | 808 | list_for_each_entry_rcu(kp, &p->list, list) |
@@ -493,21 +926,16 @@ static void __kprobes cleanup_rp_inst(struct kretprobe *rp) | |||
493 | } | 926 | } |
494 | 927 | ||
495 | /* | 928 | /* |
496 | * Keep all fields in the kprobe consistent | ||
497 | */ | ||
498 | static inline void copy_kprobe(struct kprobe *old_p, struct kprobe *p) | ||
499 | { | ||
500 | memcpy(&p->opcode, &old_p->opcode, sizeof(kprobe_opcode_t)); | ||
501 | memcpy(&p->ainsn, &old_p->ainsn, sizeof(struct arch_specific_insn)); | ||
502 | } | ||
503 | |||
504 | /* | ||
505 | * Add the new probe to ap->list. Fail if this is the | 929 | * Add the new probe to ap->list. Fail if this is the |
506 | * second jprobe at the address - two jprobes can't coexist | 930 | * second jprobe at the address - two jprobes can't coexist |
507 | */ | 931 | */ |
508 | static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) | 932 | static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) |
509 | { | 933 | { |
510 | BUG_ON(kprobe_gone(ap) || kprobe_gone(p)); | 934 | BUG_ON(kprobe_gone(ap) || kprobe_gone(p)); |
935 | |||
936 | if (p->break_handler || p->post_handler) | ||
937 | unoptimize_kprobe(ap); /* Fall back to normal kprobe */ | ||
938 | |||
511 | if (p->break_handler) { | 939 | if (p->break_handler) { |
512 | if (ap->break_handler) | 940 | if (ap->break_handler) |
513 | return -EEXIST; | 941 | return -EEXIST; |
@@ -522,7 +950,7 @@ static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) | |||
522 | ap->flags &= ~KPROBE_FLAG_DISABLED; | 950 | ap->flags &= ~KPROBE_FLAG_DISABLED; |
523 | if (!kprobes_all_disarmed) | 951 | if (!kprobes_all_disarmed) |
524 | /* Arm the breakpoint again. */ | 952 | /* Arm the breakpoint again. */ |
525 | arm_kprobe(ap); | 953 | __arm_kprobe(ap); |
526 | } | 954 | } |
527 | return 0; | 955 | return 0; |
528 | } | 956 | } |
@@ -531,12 +959,13 @@ static int __kprobes add_new_kprobe(struct kprobe *ap, struct kprobe *p) | |||
531 | * Fill in the required fields of the "manager kprobe". Replace the | 959 | * Fill in the required fields of the "manager kprobe". Replace the |
532 | * earlier kprobe in the hlist with the manager kprobe | 960 | * earlier kprobe in the hlist with the manager kprobe |
533 | */ | 961 | */ |
534 | static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p) | 962 | static void __kprobes init_aggr_kprobe(struct kprobe *ap, struct kprobe *p) |
535 | { | 963 | { |
964 | /* Copy p's insn slot to ap */ | ||
536 | copy_kprobe(p, ap); | 965 | copy_kprobe(p, ap); |
537 | flush_insn_slot(ap); | 966 | flush_insn_slot(ap); |
538 | ap->addr = p->addr; | 967 | ap->addr = p->addr; |
539 | ap->flags = p->flags; | 968 | ap->flags = p->flags & ~KPROBE_FLAG_OPTIMIZED; |
540 | ap->pre_handler = aggr_pre_handler; | 969 | ap->pre_handler = aggr_pre_handler; |
541 | ap->fault_handler = aggr_fault_handler; | 970 | ap->fault_handler = aggr_fault_handler; |
542 | /* We don't care the kprobe which has gone. */ | 971 | /* We don't care the kprobe which has gone. */ |
@@ -546,8 +975,9 @@ static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p) | |||
546 | ap->break_handler = aggr_break_handler; | 975 | ap->break_handler = aggr_break_handler; |
547 | 976 | ||
548 | INIT_LIST_HEAD(&ap->list); | 977 | INIT_LIST_HEAD(&ap->list); |
549 | list_add_rcu(&p->list, &ap->list); | 978 | INIT_HLIST_NODE(&ap->hlist); |
550 | 979 | ||
980 | list_add_rcu(&p->list, &ap->list); | ||
551 | hlist_replace_rcu(&p->hlist, &ap->hlist); | 981 | hlist_replace_rcu(&p->hlist, &ap->hlist); |
552 | } | 982 | } |
553 | 983 | ||
@@ -561,12 +991,12 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
561 | int ret = 0; | 991 | int ret = 0; |
562 | struct kprobe *ap = old_p; | 992 | struct kprobe *ap = old_p; |
563 | 993 | ||
564 | if (old_p->pre_handler != aggr_pre_handler) { | 994 | if (!kprobe_aggrprobe(old_p)) { |
565 | /* If old_p is not an aggr_probe, create new aggr_kprobe. */ | 995 | /* If old_p is not an aggr_kprobe, create new aggr_kprobe. */ |
566 | ap = kzalloc(sizeof(struct kprobe), GFP_KERNEL); | 996 | ap = alloc_aggr_kprobe(old_p); |
567 | if (!ap) | 997 | if (!ap) |
568 | return -ENOMEM; | 998 | return -ENOMEM; |
569 | add_aggr_kprobe(ap, old_p); | 999 | init_aggr_kprobe(ap, old_p); |
570 | } | 1000 | } |
571 | 1001 | ||
572 | if (kprobe_gone(ap)) { | 1002 | if (kprobe_gone(ap)) { |
@@ -585,6 +1015,9 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
585 | */ | 1015 | */ |
586 | return ret; | 1016 | return ret; |
587 | 1017 | ||
1018 | /* Prepare optimized instructions if possible. */ | ||
1019 | prepare_optimized_kprobe(ap); | ||
1020 | |||
588 | /* | 1021 | /* |
589 | * Clear gone flag to prevent allocating new slot again, and | 1022 | * Clear gone flag to prevent allocating new slot again, and |
590 | * set disabled flag because it is not armed yet. | 1023 | * set disabled flag because it is not armed yet. |
@@ -593,6 +1026,7 @@ static int __kprobes register_aggr_kprobe(struct kprobe *old_p, | |||
593 | | KPROBE_FLAG_DISABLED; | 1026 | | KPROBE_FLAG_DISABLED; |
594 | } | 1027 | } |
595 | 1028 | ||
1029 | /* Copy ap's insn slot to p */ | ||
596 | copy_kprobe(ap, p); | 1030 | copy_kprobe(ap, p); |
597 | return add_new_kprobe(ap, p); | 1031 | return add_new_kprobe(ap, p); |
598 | } | 1032 | } |
@@ -743,27 +1177,34 @@ int __kprobes register_kprobe(struct kprobe *p) | |||
743 | p->nmissed = 0; | 1177 | p->nmissed = 0; |
744 | INIT_LIST_HEAD(&p->list); | 1178 | INIT_LIST_HEAD(&p->list); |
745 | mutex_lock(&kprobe_mutex); | 1179 | mutex_lock(&kprobe_mutex); |
1180 | |||
1181 | get_online_cpus(); /* For avoiding text_mutex deadlock. */ | ||
1182 | mutex_lock(&text_mutex); | ||
1183 | |||
746 | old_p = get_kprobe(p->addr); | 1184 | old_p = get_kprobe(p->addr); |
747 | if (old_p) { | 1185 | if (old_p) { |
1186 | /* Since this may unoptimize old_p, locking text_mutex. */ | ||
748 | ret = register_aggr_kprobe(old_p, p); | 1187 | ret = register_aggr_kprobe(old_p, p); |
749 | goto out; | 1188 | goto out; |
750 | } | 1189 | } |
751 | 1190 | ||
752 | mutex_lock(&text_mutex); | ||
753 | ret = arch_prepare_kprobe(p); | 1191 | ret = arch_prepare_kprobe(p); |
754 | if (ret) | 1192 | if (ret) |
755 | goto out_unlock_text; | 1193 | goto out; |
756 | 1194 | ||
757 | INIT_HLIST_NODE(&p->hlist); | 1195 | INIT_HLIST_NODE(&p->hlist); |
758 | hlist_add_head_rcu(&p->hlist, | 1196 | hlist_add_head_rcu(&p->hlist, |
759 | &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); | 1197 | &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); |
760 | 1198 | ||
761 | if (!kprobes_all_disarmed && !kprobe_disabled(p)) | 1199 | if (!kprobes_all_disarmed && !kprobe_disabled(p)) |
762 | arch_arm_kprobe(p); | 1200 | __arm_kprobe(p); |
1201 | |||
1202 | /* Try to optimize kprobe */ | ||
1203 | try_to_optimize_kprobe(p); | ||
763 | 1204 | ||
764 | out_unlock_text: | ||
765 | mutex_unlock(&text_mutex); | ||
766 | out: | 1205 | out: |
1206 | mutex_unlock(&text_mutex); | ||
1207 | put_online_cpus(); | ||
767 | mutex_unlock(&kprobe_mutex); | 1208 | mutex_unlock(&kprobe_mutex); |
768 | 1209 | ||
769 | if (probed_mod) | 1210 | if (probed_mod) |
@@ -785,7 +1226,7 @@ static int __kprobes __unregister_kprobe_top(struct kprobe *p) | |||
785 | return -EINVAL; | 1226 | return -EINVAL; |
786 | 1227 | ||
787 | if (old_p == p || | 1228 | if (old_p == p || |
788 | (old_p->pre_handler == aggr_pre_handler && | 1229 | (kprobe_aggrprobe(old_p) && |
789 | list_is_singular(&old_p->list))) { | 1230 | list_is_singular(&old_p->list))) { |
790 | /* | 1231 | /* |
791 | * Only probe on the hash list. Disarm only if kprobes are | 1232 | * Only probe on the hash list. Disarm only if kprobes are |
@@ -793,7 +1234,7 @@ static int __kprobes __unregister_kprobe_top(struct kprobe *p) | |||
793 | * already have been removed. We save on flushing icache. | 1234 | * already have been removed. We save on flushing icache. |
794 | */ | 1235 | */ |
795 | if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) | 1236 | if (!kprobes_all_disarmed && !kprobe_disabled(old_p)) |
796 | disarm_kprobe(p); | 1237 | disarm_kprobe(old_p); |
797 | hlist_del_rcu(&old_p->hlist); | 1238 | hlist_del_rcu(&old_p->hlist); |
798 | } else { | 1239 | } else { |
799 | if (p->break_handler && !kprobe_gone(p)) | 1240 | if (p->break_handler && !kprobe_gone(p)) |
@@ -809,8 +1250,13 @@ noclean: | |||
809 | list_del_rcu(&p->list); | 1250 | list_del_rcu(&p->list); |
810 | if (!kprobe_disabled(old_p)) { | 1251 | if (!kprobe_disabled(old_p)) { |
811 | try_to_disable_aggr_kprobe(old_p); | 1252 | try_to_disable_aggr_kprobe(old_p); |
812 | if (!kprobes_all_disarmed && kprobe_disabled(old_p)) | 1253 | if (!kprobes_all_disarmed) { |
813 | disarm_kprobe(old_p); | 1254 | if (kprobe_disabled(old_p)) |
1255 | disarm_kprobe(old_p); | ||
1256 | else | ||
1257 | /* Try to optimize this probe again */ | ||
1258 | optimize_kprobe(old_p); | ||
1259 | } | ||
814 | } | 1260 | } |
815 | } | 1261 | } |
816 | return 0; | 1262 | return 0; |
@@ -827,7 +1273,7 @@ static void __kprobes __unregister_kprobe_bottom(struct kprobe *p) | |||
827 | old_p = list_entry(p->list.next, struct kprobe, list); | 1273 | old_p = list_entry(p->list.next, struct kprobe, list); |
828 | list_del(&p->list); | 1274 | list_del(&p->list); |
829 | arch_remove_kprobe(old_p); | 1275 | arch_remove_kprobe(old_p); |
830 | kfree(old_p); | 1276 | free_aggr_kprobe(old_p); |
831 | } | 1277 | } |
832 | } | 1278 | } |
833 | 1279 | ||
@@ -1123,7 +1569,7 @@ static void __kprobes kill_kprobe(struct kprobe *p) | |||
1123 | struct kprobe *kp; | 1569 | struct kprobe *kp; |
1124 | 1570 | ||
1125 | p->flags |= KPROBE_FLAG_GONE; | 1571 | p->flags |= KPROBE_FLAG_GONE; |
1126 | if (p->pre_handler == aggr_pre_handler) { | 1572 | if (kprobe_aggrprobe(p)) { |
1127 | /* | 1573 | /* |
1128 | * If this is an aggr_kprobe, we have to list all the | 1574 | * If this is an aggr_kprobe, we have to list all the |
1129 | * chained probes and mark them GONE. | 1575 | * chained probes and mark them GONE. |
@@ -1132,6 +1578,7 @@ static void __kprobes kill_kprobe(struct kprobe *p) | |||
1132 | kp->flags |= KPROBE_FLAG_GONE; | 1578 | kp->flags |= KPROBE_FLAG_GONE; |
1133 | p->post_handler = NULL; | 1579 | p->post_handler = NULL; |
1134 | p->break_handler = NULL; | 1580 | p->break_handler = NULL; |
1581 | kill_optimized_kprobe(p); | ||
1135 | } | 1582 | } |
1136 | /* | 1583 | /* |
1137 | * Here, we can remove insn_slot safely, because no thread calls | 1584 | * Here, we can remove insn_slot safely, because no thread calls |
@@ -1241,6 +1688,15 @@ static int __init init_kprobes(void) | |||
1241 | } | 1688 | } |
1242 | } | 1689 | } |
1243 | 1690 | ||
1691 | #if defined(CONFIG_OPTPROBES) | ||
1692 | #if defined(__ARCH_WANT_KPROBES_INSN_SLOT) | ||
1693 | /* Init kprobe_optinsn_slots */ | ||
1694 | kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE; | ||
1695 | #endif | ||
1696 | /* By default, kprobes can be optimized */ | ||
1697 | kprobes_allow_optimization = true; | ||
1698 | #endif | ||
1699 | |||
1244 | /* By default, kprobes are armed */ | 1700 | /* By default, kprobes are armed */ |
1245 | kprobes_all_disarmed = false; | 1701 | kprobes_all_disarmed = false; |
1246 | 1702 | ||
@@ -1259,7 +1715,7 @@ static int __init init_kprobes(void) | |||
1259 | 1715 | ||
1260 | #ifdef CONFIG_DEBUG_FS | 1716 | #ifdef CONFIG_DEBUG_FS |
1261 | static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, | 1717 | static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, |
1262 | const char *sym, int offset,char *modname) | 1718 | const char *sym, int offset, char *modname, struct kprobe *pp) |
1263 | { | 1719 | { |
1264 | char *kprobe_type; | 1720 | char *kprobe_type; |
1265 | 1721 | ||
@@ -1269,19 +1725,21 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p, | |||
1269 | kprobe_type = "j"; | 1725 | kprobe_type = "j"; |
1270 | else | 1726 | else |
1271 | kprobe_type = "k"; | 1727 | kprobe_type = "k"; |
1728 | |||
1272 | if (sym) | 1729 | if (sym) |
1273 | seq_printf(pi, "%p %s %s+0x%x %s %s%s\n", | 1730 | seq_printf(pi, "%p %s %s+0x%x %s ", |
1274 | p->addr, kprobe_type, sym, offset, | 1731 | p->addr, kprobe_type, sym, offset, |
1275 | (modname ? modname : " "), | 1732 | (modname ? modname : " ")); |
1276 | (kprobe_gone(p) ? "[GONE]" : ""), | ||
1277 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? | ||
1278 | "[DISABLED]" : "")); | ||
1279 | else | 1733 | else |
1280 | seq_printf(pi, "%p %s %p %s%s\n", | 1734 | seq_printf(pi, "%p %s %p ", |
1281 | p->addr, kprobe_type, p->addr, | 1735 | p->addr, kprobe_type, p->addr); |
1282 | (kprobe_gone(p) ? "[GONE]" : ""), | 1736 | |
1283 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? | 1737 | if (!pp) |
1284 | "[DISABLED]" : "")); | 1738 | pp = p; |
1739 | seq_printf(pi, "%s%s%s\n", | ||
1740 | (kprobe_gone(p) ? "[GONE]" : ""), | ||
1741 | ((kprobe_disabled(p) && !kprobe_gone(p)) ? "[DISABLED]" : ""), | ||
1742 | (kprobe_optimized(pp) ? "[OPTIMIZED]" : "")); | ||
1285 | } | 1743 | } |
1286 | 1744 | ||
1287 | static void __kprobes *kprobe_seq_start(struct seq_file *f, loff_t *pos) | 1745 | static void __kprobes *kprobe_seq_start(struct seq_file *f, loff_t *pos) |
@@ -1317,11 +1775,11 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v) | |||
1317 | hlist_for_each_entry_rcu(p, node, head, hlist) { | 1775 | hlist_for_each_entry_rcu(p, node, head, hlist) { |
1318 | sym = kallsyms_lookup((unsigned long)p->addr, NULL, | 1776 | sym = kallsyms_lookup((unsigned long)p->addr, NULL, |
1319 | &offset, &modname, namebuf); | 1777 | &offset, &modname, namebuf); |
1320 | if (p->pre_handler == aggr_pre_handler) { | 1778 | if (kprobe_aggrprobe(p)) { |
1321 | list_for_each_entry_rcu(kp, &p->list, list) | 1779 | list_for_each_entry_rcu(kp, &p->list, list) |
1322 | report_probe(pi, kp, sym, offset, modname); | 1780 | report_probe(pi, kp, sym, offset, modname, p); |
1323 | } else | 1781 | } else |
1324 | report_probe(pi, p, sym, offset, modname); | 1782 | report_probe(pi, p, sym, offset, modname, NULL); |
1325 | } | 1783 | } |
1326 | preempt_enable(); | 1784 | preempt_enable(); |
1327 | return 0; | 1785 | return 0; |
@@ -1399,12 +1857,13 @@ int __kprobes enable_kprobe(struct kprobe *kp) | |||
1399 | goto out; | 1857 | goto out; |
1400 | } | 1858 | } |
1401 | 1859 | ||
1402 | if (!kprobes_all_disarmed && kprobe_disabled(p)) | ||
1403 | arm_kprobe(p); | ||
1404 | |||
1405 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
1406 | if (p != kp) | 1860 | if (p != kp) |
1407 | kp->flags &= ~KPROBE_FLAG_DISABLED; | 1861 | kp->flags &= ~KPROBE_FLAG_DISABLED; |
1862 | |||
1863 | if (!kprobes_all_disarmed && kprobe_disabled(p)) { | ||
1864 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
1865 | arm_kprobe(p); | ||
1866 | } | ||
1408 | out: | 1867 | out: |
1409 | mutex_unlock(&kprobe_mutex); | 1868 | mutex_unlock(&kprobe_mutex); |
1410 | return ret; | 1869 | return ret; |
@@ -1424,12 +1883,13 @@ static void __kprobes arm_all_kprobes(void) | |||
1424 | if (!kprobes_all_disarmed) | 1883 | if (!kprobes_all_disarmed) |
1425 | goto already_enabled; | 1884 | goto already_enabled; |
1426 | 1885 | ||
1886 | /* Arming kprobes doesn't optimize kprobe itself */ | ||
1427 | mutex_lock(&text_mutex); | 1887 | mutex_lock(&text_mutex); |
1428 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1888 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
1429 | head = &kprobe_table[i]; | 1889 | head = &kprobe_table[i]; |
1430 | hlist_for_each_entry_rcu(p, node, head, hlist) | 1890 | hlist_for_each_entry_rcu(p, node, head, hlist) |
1431 | if (!kprobe_disabled(p)) | 1891 | if (!kprobe_disabled(p)) |
1432 | arch_arm_kprobe(p); | 1892 | __arm_kprobe(p); |
1433 | } | 1893 | } |
1434 | mutex_unlock(&text_mutex); | 1894 | mutex_unlock(&text_mutex); |
1435 | 1895 | ||
@@ -1456,16 +1916,23 @@ static void __kprobes disarm_all_kprobes(void) | |||
1456 | 1916 | ||
1457 | kprobes_all_disarmed = true; | 1917 | kprobes_all_disarmed = true; |
1458 | printk(KERN_INFO "Kprobes globally disabled\n"); | 1918 | printk(KERN_INFO "Kprobes globally disabled\n"); |
1919 | |||
1920 | /* | ||
1921 | * Here we call get_online_cpus() for avoiding text_mutex deadlock, | ||
1922 | * because disarming may also unoptimize kprobes. | ||
1923 | */ | ||
1924 | get_online_cpus(); | ||
1459 | mutex_lock(&text_mutex); | 1925 | mutex_lock(&text_mutex); |
1460 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { | 1926 | for (i = 0; i < KPROBE_TABLE_SIZE; i++) { |
1461 | head = &kprobe_table[i]; | 1927 | head = &kprobe_table[i]; |
1462 | hlist_for_each_entry_rcu(p, node, head, hlist) { | 1928 | hlist_for_each_entry_rcu(p, node, head, hlist) { |
1463 | if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) | 1929 | if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) |
1464 | arch_disarm_kprobe(p); | 1930 | __disarm_kprobe(p); |
1465 | } | 1931 | } |
1466 | } | 1932 | } |
1467 | 1933 | ||
1468 | mutex_unlock(&text_mutex); | 1934 | mutex_unlock(&text_mutex); |
1935 | put_online_cpus(); | ||
1469 | mutex_unlock(&kprobe_mutex); | 1936 | mutex_unlock(&kprobe_mutex); |
1470 | /* Allow all currently running kprobes to complete */ | 1937 | /* Allow all currently running kprobes to complete */ |
1471 | synchronize_sched(); | 1938 | synchronize_sched(); |
diff --git a/kernel/padata.c b/kernel/padata.c index 6f9bcb8313d6..93caf65ff57c 100644 --- a/kernel/padata.c +++ b/kernel/padata.c | |||
@@ -642,6 +642,9 @@ struct padata_instance *padata_alloc(const struct cpumask *cpumask, | |||
642 | if (!pd) | 642 | if (!pd) |
643 | goto err_free_inst; | 643 | goto err_free_inst; |
644 | 644 | ||
645 | if (!alloc_cpumask_var(&pinst->cpumask, GFP_KERNEL)) | ||
646 | goto err_free_pd; | ||
647 | |||
645 | rcu_assign_pointer(pinst->pd, pd); | 648 | rcu_assign_pointer(pinst->pd, pd); |
646 | 649 | ||
647 | pinst->wq = wq; | 650 | pinst->wq = wq; |
@@ -654,12 +657,14 @@ struct padata_instance *padata_alloc(const struct cpumask *cpumask, | |||
654 | pinst->cpu_notifier.priority = 0; | 657 | pinst->cpu_notifier.priority = 0; |
655 | err = register_hotcpu_notifier(&pinst->cpu_notifier); | 658 | err = register_hotcpu_notifier(&pinst->cpu_notifier); |
656 | if (err) | 659 | if (err) |
657 | goto err_free_pd; | 660 | goto err_free_cpumask; |
658 | 661 | ||
659 | mutex_init(&pinst->lock); | 662 | mutex_init(&pinst->lock); |
660 | 663 | ||
661 | return pinst; | 664 | return pinst; |
662 | 665 | ||
666 | err_free_cpumask: | ||
667 | free_cpumask_var(pinst->cpumask); | ||
663 | err_free_pd: | 668 | err_free_pd: |
664 | padata_free_pd(pd); | 669 | padata_free_pd(pd); |
665 | err_free_inst: | 670 | err_free_inst: |
@@ -685,6 +690,7 @@ void padata_free(struct padata_instance *pinst) | |||
685 | 690 | ||
686 | unregister_hotcpu_notifier(&pinst->cpu_notifier); | 691 | unregister_hotcpu_notifier(&pinst->cpu_notifier); |
687 | padata_free_pd(pinst->pd); | 692 | padata_free_pd(pinst->pd); |
693 | free_cpumask_var(pinst->cpumask); | ||
688 | kfree(pinst); | 694 | kfree(pinst); |
689 | } | 695 | } |
690 | EXPORT_SYMBOL(padata_free); | 696 | EXPORT_SYMBOL(padata_free); |
diff --git a/kernel/panic.c b/kernel/panic.c index c787333282b8..13d966b4c14a 100644 --- a/kernel/panic.c +++ b/kernel/panic.c | |||
@@ -36,15 +36,36 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list); | |||
36 | 36 | ||
37 | EXPORT_SYMBOL(panic_notifier_list); | 37 | EXPORT_SYMBOL(panic_notifier_list); |
38 | 38 | ||
39 | static long no_blink(long time) | ||
40 | { | ||
41 | return 0; | ||
42 | } | ||
43 | |||
44 | /* Returns how long it waited in ms */ | 39 | /* Returns how long it waited in ms */ |
45 | long (*panic_blink)(long time); | 40 | long (*panic_blink)(long time); |
46 | EXPORT_SYMBOL(panic_blink); | 41 | EXPORT_SYMBOL(panic_blink); |
47 | 42 | ||
43 | static void panic_blink_one_second(void) | ||
44 | { | ||
45 | static long i = 0, end; | ||
46 | |||
47 | if (panic_blink) { | ||
48 | end = i + MSEC_PER_SEC; | ||
49 | |||
50 | while (i < end) { | ||
51 | i += panic_blink(i); | ||
52 | mdelay(1); | ||
53 | i++; | ||
54 | } | ||
55 | } else { | ||
56 | /* | ||
57 | * When running under a hypervisor a small mdelay may get | ||
58 | * rounded up to the hypervisor timeslice. For example, with | ||
59 | * a 1ms in 10ms hypervisor timeslice we might inflate a | ||
60 | * mdelay(1) loop by 10x. | ||
61 | * | ||
62 | * If we have nothing to blink, spin on 1 second calls to | ||
63 | * mdelay to avoid this. | ||
64 | */ | ||
65 | mdelay(MSEC_PER_SEC); | ||
66 | } | ||
67 | } | ||
68 | |||
48 | /** | 69 | /** |
49 | * panic - halt the system | 70 | * panic - halt the system |
50 | * @fmt: The text string to print | 71 | * @fmt: The text string to print |
@@ -95,9 +116,6 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
95 | 116 | ||
96 | bust_spinlocks(0); | 117 | bust_spinlocks(0); |
97 | 118 | ||
98 | if (!panic_blink) | ||
99 | panic_blink = no_blink; | ||
100 | |||
101 | if (panic_timeout > 0) { | 119 | if (panic_timeout > 0) { |
102 | /* | 120 | /* |
103 | * Delay timeout seconds before rebooting the machine. | 121 | * Delay timeout seconds before rebooting the machine. |
@@ -105,11 +123,9 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
105 | */ | 123 | */ |
106 | printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout); | 124 | printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout); |
107 | 125 | ||
108 | for (i = 0; i < panic_timeout*1000; ) { | 126 | for (i = 0; i < panic_timeout; i++) { |
109 | touch_nmi_watchdog(); | 127 | touch_nmi_watchdog(); |
110 | i += panic_blink(i); | 128 | panic_blink_one_second(); |
111 | mdelay(1); | ||
112 | i++; | ||
113 | } | 129 | } |
114 | /* | 130 | /* |
115 | * This will not be a clean reboot, with everything | 131 | * This will not be a clean reboot, with everything |
@@ -135,11 +151,9 @@ NORET_TYPE void panic(const char * fmt, ...) | |||
135 | } | 151 | } |
136 | #endif | 152 | #endif |
137 | local_irq_enable(); | 153 | local_irq_enable(); |
138 | for (i = 0; ; ) { | 154 | while (1) { |
139 | touch_softlockup_watchdog(); | 155 | touch_softlockup_watchdog(); |
140 | i += panic_blink(i); | 156 | panic_blink_one_second(); |
141 | mdelay(1); | ||
142 | i++; | ||
143 | } | 157 | } |
144 | } | 158 | } |
145 | 159 | ||
diff --git a/kernel/params.c b/kernel/params.c index cf1b69183127..8d95f5451b22 100644 --- a/kernel/params.c +++ b/kernel/params.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/ctype.h> | 26 | #include <linux/ctype.h> |
27 | #include <linux/string.h> | ||
28 | 27 | ||
29 | #if 0 | 28 | #if 0 |
30 | #define DEBUGP printk | 29 | #define DEBUGP printk |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index a661e7991865..8e352c756ba7 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -2610,7 +2610,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) | |||
2610 | if (user_locked > user_lock_limit) | 2610 | if (user_locked > user_lock_limit) |
2611 | extra = user_locked - user_lock_limit; | 2611 | extra = user_locked - user_lock_limit; |
2612 | 2612 | ||
2613 | lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; | 2613 | lock_limit = rlimit(RLIMIT_MEMLOCK); |
2614 | lock_limit >>= PAGE_SHIFT; | 2614 | lock_limit >>= PAGE_SHIFT; |
2615 | locked = vma->vm_mm->locked_vm + extra; | 2615 | locked = vma->vm_mm->locked_vm + extra; |
2616 | 2616 | ||
diff --git a/kernel/pid.c b/kernel/pid.c index b08e697cd83f..86b296943e5f 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
@@ -376,7 +376,7 @@ struct task_struct *pid_task(struct pid *pid, enum pid_type type) | |||
376 | EXPORT_SYMBOL(pid_task); | 376 | EXPORT_SYMBOL(pid_task); |
377 | 377 | ||
378 | /* | 378 | /* |
379 | * Must be called under rcu_read_lock() or with tasklist_lock read-held. | 379 | * Must be called under rcu_read_lock(). |
380 | */ | 380 | */ |
381 | struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns) | 381 | struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns) |
382 | { | 382 | { |
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index 438ff4523513..1a22dfd42df9 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
@@ -982,6 +982,7 @@ static void check_thread_timers(struct task_struct *tsk, | |||
982 | int maxfire; | 982 | int maxfire; |
983 | struct list_head *timers = tsk->cpu_timers; | 983 | struct list_head *timers = tsk->cpu_timers; |
984 | struct signal_struct *const sig = tsk->signal; | 984 | struct signal_struct *const sig = tsk->signal; |
985 | unsigned long soft; | ||
985 | 986 | ||
986 | maxfire = 20; | 987 | maxfire = 20; |
987 | tsk->cputime_expires.prof_exp = cputime_zero; | 988 | tsk->cputime_expires.prof_exp = cputime_zero; |
@@ -1030,9 +1031,10 @@ static void check_thread_timers(struct task_struct *tsk, | |||
1030 | /* | 1031 | /* |
1031 | * Check for the special case thread timers. | 1032 | * Check for the special case thread timers. |
1032 | */ | 1033 | */ |
1033 | if (sig->rlim[RLIMIT_RTTIME].rlim_cur != RLIM_INFINITY) { | 1034 | soft = ACCESS_ONCE(sig->rlim[RLIMIT_RTTIME].rlim_cur); |
1034 | unsigned long hard = sig->rlim[RLIMIT_RTTIME].rlim_max; | 1035 | if (soft != RLIM_INFINITY) { |
1035 | unsigned long *soft = &sig->rlim[RLIMIT_RTTIME].rlim_cur; | 1036 | unsigned long hard = |
1037 | ACCESS_ONCE(sig->rlim[RLIMIT_RTTIME].rlim_max); | ||
1036 | 1038 | ||
1037 | if (hard != RLIM_INFINITY && | 1039 | if (hard != RLIM_INFINITY && |
1038 | tsk->rt.timeout > DIV_ROUND_UP(hard, USEC_PER_SEC/HZ)) { | 1040 | tsk->rt.timeout > DIV_ROUND_UP(hard, USEC_PER_SEC/HZ)) { |
@@ -1043,14 +1045,13 @@ static void check_thread_timers(struct task_struct *tsk, | |||
1043 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); | 1045 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); |
1044 | return; | 1046 | return; |
1045 | } | 1047 | } |
1046 | if (tsk->rt.timeout > DIV_ROUND_UP(*soft, USEC_PER_SEC/HZ)) { | 1048 | if (tsk->rt.timeout > DIV_ROUND_UP(soft, USEC_PER_SEC/HZ)) { |
1047 | /* | 1049 | /* |
1048 | * At the soft limit, send a SIGXCPU every second. | 1050 | * At the soft limit, send a SIGXCPU every second. |
1049 | */ | 1051 | */ |
1050 | if (sig->rlim[RLIMIT_RTTIME].rlim_cur | 1052 | if (soft < hard) { |
1051 | < sig->rlim[RLIMIT_RTTIME].rlim_max) { | 1053 | soft += USEC_PER_SEC; |
1052 | sig->rlim[RLIMIT_RTTIME].rlim_cur += | 1054 | sig->rlim[RLIMIT_RTTIME].rlim_cur = soft; |
1053 | USEC_PER_SEC; | ||
1054 | } | 1055 | } |
1055 | printk(KERN_INFO | 1056 | printk(KERN_INFO |
1056 | "RT Watchdog Timeout: %s[%d]\n", | 1057 | "RT Watchdog Timeout: %s[%d]\n", |
@@ -1121,6 +1122,7 @@ static void check_process_timers(struct task_struct *tsk, | |||
1121 | unsigned long long sum_sched_runtime, sched_expires; | 1122 | unsigned long long sum_sched_runtime, sched_expires; |
1122 | struct list_head *timers = sig->cpu_timers; | 1123 | struct list_head *timers = sig->cpu_timers; |
1123 | struct task_cputime cputime; | 1124 | struct task_cputime cputime; |
1125 | unsigned long soft; | ||
1124 | 1126 | ||
1125 | /* | 1127 | /* |
1126 | * Don't sample the current process CPU clocks if there are no timers. | 1128 | * Don't sample the current process CPU clocks if there are no timers. |
@@ -1193,11 +1195,13 @@ static void check_process_timers(struct task_struct *tsk, | |||
1193 | SIGPROF); | 1195 | SIGPROF); |
1194 | check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime, | 1196 | check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime, |
1195 | SIGVTALRM); | 1197 | SIGVTALRM); |
1196 | 1198 | soft = ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur); | |
1197 | if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { | 1199 | if (soft != RLIM_INFINITY) { |
1198 | unsigned long psecs = cputime_to_secs(ptime); | 1200 | unsigned long psecs = cputime_to_secs(ptime); |
1201 | unsigned long hard = | ||
1202 | ACCESS_ONCE(sig->rlim[RLIMIT_CPU].rlim_max); | ||
1199 | cputime_t x; | 1203 | cputime_t x; |
1200 | if (psecs >= sig->rlim[RLIMIT_CPU].rlim_max) { | 1204 | if (psecs >= hard) { |
1201 | /* | 1205 | /* |
1202 | * At the hard limit, we just die. | 1206 | * At the hard limit, we just die. |
1203 | * No need to calculate anything else now. | 1207 | * No need to calculate anything else now. |
@@ -1205,17 +1209,17 @@ static void check_process_timers(struct task_struct *tsk, | |||
1205 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); | 1209 | __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk); |
1206 | return; | 1210 | return; |
1207 | } | 1211 | } |
1208 | if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) { | 1212 | if (psecs >= soft) { |
1209 | /* | 1213 | /* |
1210 | * At the soft limit, send a SIGXCPU every second. | 1214 | * At the soft limit, send a SIGXCPU every second. |
1211 | */ | 1215 | */ |
1212 | __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk); | 1216 | __group_send_sig_info(SIGXCPU, SEND_SIG_PRIV, tsk); |
1213 | if (sig->rlim[RLIMIT_CPU].rlim_cur | 1217 | if (soft < hard) { |
1214 | < sig->rlim[RLIMIT_CPU].rlim_max) { | 1218 | soft++; |
1215 | sig->rlim[RLIMIT_CPU].rlim_cur++; | 1219 | sig->rlim[RLIMIT_CPU].rlim_cur = soft; |
1216 | } | 1220 | } |
1217 | } | 1221 | } |
1218 | x = secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); | 1222 | x = secs_to_cputime(soft); |
1219 | if (cputime_eq(prof_expires, cputime_zero) || | 1223 | if (cputime_eq(prof_expires, cputime_zero) || |
1220 | cputime_lt(x, prof_expires)) { | 1224 | cputime_lt(x, prof_expires)) { |
1221 | prof_expires = x; | 1225 | prof_expires = x; |
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index bbfe472d7524..da5288ec2392 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c | |||
@@ -323,6 +323,7 @@ static int create_image(int platform_mode) | |||
323 | int hibernation_snapshot(int platform_mode) | 323 | int hibernation_snapshot(int platform_mode) |
324 | { | 324 | { |
325 | int error; | 325 | int error; |
326 | gfp_t saved_mask; | ||
326 | 327 | ||
327 | error = platform_begin(platform_mode); | 328 | error = platform_begin(platform_mode); |
328 | if (error) | 329 | if (error) |
@@ -334,6 +335,7 @@ int hibernation_snapshot(int platform_mode) | |||
334 | goto Close; | 335 | goto Close; |
335 | 336 | ||
336 | suspend_console(); | 337 | suspend_console(); |
338 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
337 | error = dpm_suspend_start(PMSG_FREEZE); | 339 | error = dpm_suspend_start(PMSG_FREEZE); |
338 | if (error) | 340 | if (error) |
339 | goto Recover_platform; | 341 | goto Recover_platform; |
@@ -351,6 +353,7 @@ int hibernation_snapshot(int platform_mode) | |||
351 | 353 | ||
352 | dpm_resume_end(in_suspend ? | 354 | dpm_resume_end(in_suspend ? |
353 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); | 355 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); |
356 | set_gfp_allowed_mask(saved_mask); | ||
354 | resume_console(); | 357 | resume_console(); |
355 | Close: | 358 | Close: |
356 | platform_end(platform_mode); | 359 | platform_end(platform_mode); |
@@ -445,14 +448,17 @@ static int resume_target_kernel(bool platform_mode) | |||
445 | int hibernation_restore(int platform_mode) | 448 | int hibernation_restore(int platform_mode) |
446 | { | 449 | { |
447 | int error; | 450 | int error; |
451 | gfp_t saved_mask; | ||
448 | 452 | ||
449 | pm_prepare_console(); | 453 | pm_prepare_console(); |
450 | suspend_console(); | 454 | suspend_console(); |
455 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
451 | error = dpm_suspend_start(PMSG_QUIESCE); | 456 | error = dpm_suspend_start(PMSG_QUIESCE); |
452 | if (!error) { | 457 | if (!error) { |
453 | error = resume_target_kernel(platform_mode); | 458 | error = resume_target_kernel(platform_mode); |
454 | dpm_resume_end(PMSG_RECOVER); | 459 | dpm_resume_end(PMSG_RECOVER); |
455 | } | 460 | } |
461 | set_gfp_allowed_mask(saved_mask); | ||
456 | resume_console(); | 462 | resume_console(); |
457 | pm_restore_console(); | 463 | pm_restore_console(); |
458 | return error; | 464 | return error; |
@@ -466,6 +472,7 @@ int hibernation_restore(int platform_mode) | |||
466 | int hibernation_platform_enter(void) | 472 | int hibernation_platform_enter(void) |
467 | { | 473 | { |
468 | int error; | 474 | int error; |
475 | gfp_t saved_mask; | ||
469 | 476 | ||
470 | if (!hibernation_ops) | 477 | if (!hibernation_ops) |
471 | return -ENOSYS; | 478 | return -ENOSYS; |
@@ -481,6 +488,7 @@ int hibernation_platform_enter(void) | |||
481 | 488 | ||
482 | entering_platform_hibernation = true; | 489 | entering_platform_hibernation = true; |
483 | suspend_console(); | 490 | suspend_console(); |
491 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
484 | error = dpm_suspend_start(PMSG_HIBERNATE); | 492 | error = dpm_suspend_start(PMSG_HIBERNATE); |
485 | if (error) { | 493 | if (error) { |
486 | if (hibernation_ops->recover) | 494 | if (hibernation_ops->recover) |
@@ -518,6 +526,7 @@ int hibernation_platform_enter(void) | |||
518 | Resume_devices: | 526 | Resume_devices: |
519 | entering_platform_hibernation = false; | 527 | entering_platform_hibernation = false; |
520 | dpm_resume_end(PMSG_RESTORE); | 528 | dpm_resume_end(PMSG_RESTORE); |
529 | set_gfp_allowed_mask(saved_mask); | ||
521 | resume_console(); | 530 | resume_console(); |
522 | 531 | ||
523 | Close: | 532 | Close: |
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 6f10dfc2d3e9..44cce10b582d 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c | |||
@@ -189,6 +189,7 @@ static int suspend_enter(suspend_state_t state) | |||
189 | int suspend_devices_and_enter(suspend_state_t state) | 189 | int suspend_devices_and_enter(suspend_state_t state) |
190 | { | 190 | { |
191 | int error; | 191 | int error; |
192 | gfp_t saved_mask; | ||
192 | 193 | ||
193 | if (!suspend_ops) | 194 | if (!suspend_ops) |
194 | return -ENOSYS; | 195 | return -ENOSYS; |
@@ -199,6 +200,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
199 | goto Close; | 200 | goto Close; |
200 | } | 201 | } |
201 | suspend_console(); | 202 | suspend_console(); |
203 | saved_mask = clear_gfp_allowed_mask(GFP_IOFS); | ||
202 | suspend_test_start(); | 204 | suspend_test_start(); |
203 | error = dpm_suspend_start(PMSG_SUSPEND); | 205 | error = dpm_suspend_start(PMSG_SUSPEND); |
204 | if (error) { | 206 | if (error) { |
@@ -215,6 +217,7 @@ int suspend_devices_and_enter(suspend_state_t state) | |||
215 | suspend_test_start(); | 217 | suspend_test_start(); |
216 | dpm_resume_end(PMSG_RESUME); | 218 | dpm_resume_end(PMSG_RESUME); |
217 | suspend_test_finish("resume devices"); | 219 | suspend_test_finish("resume devices"); |
220 | set_gfp_allowed_mask(saved_mask); | ||
218 | resume_console(); | 221 | resume_console(); |
219 | Close: | 222 | Close: |
220 | if (suspend_ops->end) | 223 | if (suspend_ops->end) |
diff --git a/kernel/printk.c b/kernel/printk.c index 40674122ecf2..75077ad0b537 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -70,8 +70,6 @@ int console_printk[4] = { | |||
70 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ | 70 | DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static int saved_console_loglevel = -1; | ||
74 | |||
75 | /* | 73 | /* |
76 | * Low level drivers may need that to know if they can schedule in | 74 | * Low level drivers may need that to know if they can schedule in |
77 | * their unblank() callback or not. So let's export it. | 75 | * their unblank() callback or not. So let's export it. |
@@ -146,6 +144,7 @@ static char __log_buf[__LOG_BUF_LEN]; | |||
146 | static char *log_buf = __log_buf; | 144 | static char *log_buf = __log_buf; |
147 | static int log_buf_len = __LOG_BUF_LEN; | 145 | static int log_buf_len = __LOG_BUF_LEN; |
148 | static unsigned logged_chars; /* Number of chars produced since last read+clear operation */ | 146 | static unsigned logged_chars; /* Number of chars produced since last read+clear operation */ |
147 | static int saved_console_loglevel = -1; | ||
149 | 148 | ||
150 | #ifdef CONFIG_KEXEC | 149 | #ifdef CONFIG_KEXEC |
151 | /* | 150 | /* |
diff --git a/kernel/relay.c b/kernel/relay.c index c705a41b4ba3..3d97f2821611 100644 --- a/kernel/relay.c +++ b/kernel/relay.c | |||
@@ -1215,14 +1215,14 @@ static void relay_page_release(struct splice_pipe_desc *spd, unsigned int i) | |||
1215 | /* | 1215 | /* |
1216 | * subbuf_splice_actor - splice up to one subbuf's worth of data | 1216 | * subbuf_splice_actor - splice up to one subbuf's worth of data |
1217 | */ | 1217 | */ |
1218 | static int subbuf_splice_actor(struct file *in, | 1218 | static ssize_t subbuf_splice_actor(struct file *in, |
1219 | loff_t *ppos, | 1219 | loff_t *ppos, |
1220 | struct pipe_inode_info *pipe, | 1220 | struct pipe_inode_info *pipe, |
1221 | size_t len, | 1221 | size_t len, |
1222 | unsigned int flags, | 1222 | unsigned int flags, |
1223 | int *nonpad_ret) | 1223 | int *nonpad_ret) |
1224 | { | 1224 | { |
1225 | unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret; | 1225 | unsigned int pidx, poff, total_len, subbuf_pages, nr_pages; |
1226 | struct rchan_buf *rbuf = in->private_data; | 1226 | struct rchan_buf *rbuf = in->private_data; |
1227 | unsigned int subbuf_size = rbuf->chan->subbuf_size; | 1227 | unsigned int subbuf_size = rbuf->chan->subbuf_size; |
1228 | uint64_t pos = (uint64_t) *ppos; | 1228 | uint64_t pos = (uint64_t) *ppos; |
@@ -1241,6 +1241,7 @@ static int subbuf_splice_actor(struct file *in, | |||
1241 | .ops = &relay_pipe_buf_ops, | 1241 | .ops = &relay_pipe_buf_ops, |
1242 | .spd_release = relay_page_release, | 1242 | .spd_release = relay_page_release, |
1243 | }; | 1243 | }; |
1244 | ssize_t ret; | ||
1244 | 1245 | ||
1245 | if (rbuf->subbufs_produced == rbuf->subbufs_consumed) | 1246 | if (rbuf->subbufs_produced == rbuf->subbufs_consumed) |
1246 | return 0; | 1247 | return 0; |
diff --git a/kernel/sched.c b/kernel/sched.c index abb36b16b93b..b47ceeec1a91 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -4353,7 +4353,7 @@ int can_nice(const struct task_struct *p, const int nice) | |||
4353 | /* convert nice value [19,-20] to rlimit style value [1,40] */ | 4353 | /* convert nice value [19,-20] to rlimit style value [1,40] */ |
4354 | int nice_rlim = 20 - nice; | 4354 | int nice_rlim = 20 - nice; |
4355 | 4355 | ||
4356 | return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur || | 4356 | return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || |
4357 | capable(CAP_SYS_NICE)); | 4357 | capable(CAP_SYS_NICE)); |
4358 | } | 4358 | } |
4359 | 4359 | ||
@@ -4530,7 +4530,7 @@ recheck: | |||
4530 | 4530 | ||
4531 | if (!lock_task_sighand(p, &flags)) | 4531 | if (!lock_task_sighand(p, &flags)) |
4532 | return -ESRCH; | 4532 | return -ESRCH; |
4533 | rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur; | 4533 | rlim_rtprio = task_rlimit(p, RLIMIT_RTPRIO); |
4534 | unlock_task_sighand(p, &flags); | 4534 | unlock_task_sighand(p, &flags); |
4535 | 4535 | ||
4536 | /* can't set/change the rt policy */ | 4536 | /* can't set/change the rt policy */ |
diff --git a/kernel/sched_cpupri.c b/kernel/sched_cpupri.c index eeb3506c4834..82095bf2099f 100644 --- a/kernel/sched_cpupri.c +++ b/kernel/sched_cpupri.c | |||
@@ -47,7 +47,7 @@ static int convert_prio(int prio) | |||
47 | } | 47 | } |
48 | 48 | ||
49 | #define for_each_cpupri_active(array, idx) \ | 49 | #define for_each_cpupri_active(array, idx) \ |
50 | for_each_bit(idx, array, CPUPRI_NR_PRIORITIES) | 50 | for_each_set_bit(idx, array, CPUPRI_NR_PRIORITIES) |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * cpupri_find - find the best (lowest-pri) CPU in the system | 53 | * cpupri_find - find the best (lowest-pri) CPU in the system |
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index bf3e38fdbe6d..5a6ed1f0990a 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
@@ -1662,8 +1662,9 @@ static void watchdog(struct rq *rq, struct task_struct *p) | |||
1662 | if (!p->signal) | 1662 | if (!p->signal) |
1663 | return; | 1663 | return; |
1664 | 1664 | ||
1665 | soft = p->signal->rlim[RLIMIT_RTTIME].rlim_cur; | 1665 | /* max may change after cur was read, this will be fixed next tick */ |
1666 | hard = p->signal->rlim[RLIMIT_RTTIME].rlim_max; | 1666 | soft = task_rlimit(p, RLIMIT_RTTIME); |
1667 | hard = task_rlimit_max(p, RLIMIT_RTTIME); | ||
1667 | 1668 | ||
1668 | if (soft != RLIM_INFINITY) { | 1669 | if (soft != RLIM_INFINITY) { |
1669 | unsigned long next; | 1670 | unsigned long next; |
diff --git a/kernel/signal.c b/kernel/signal.c index 934ae5e687b9..dbd7fe073c55 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -159,6 +159,10 @@ void recalc_sigpending(void) | |||
159 | 159 | ||
160 | /* Given the mask, find the first available signal that should be serviced. */ | 160 | /* Given the mask, find the first available signal that should be serviced. */ |
161 | 161 | ||
162 | #define SYNCHRONOUS_MASK \ | ||
163 | (sigmask(SIGSEGV) | sigmask(SIGBUS) | sigmask(SIGILL) | \ | ||
164 | sigmask(SIGTRAP) | sigmask(SIGFPE)) | ||
165 | |||
162 | int next_signal(struct sigpending *pending, sigset_t *mask) | 166 | int next_signal(struct sigpending *pending, sigset_t *mask) |
163 | { | 167 | { |
164 | unsigned long i, *s, *m, x; | 168 | unsigned long i, *s, *m, x; |
@@ -166,26 +170,39 @@ int next_signal(struct sigpending *pending, sigset_t *mask) | |||
166 | 170 | ||
167 | s = pending->signal.sig; | 171 | s = pending->signal.sig; |
168 | m = mask->sig; | 172 | m = mask->sig; |
173 | |||
174 | /* | ||
175 | * Handle the first word specially: it contains the | ||
176 | * synchronous signals that need to be dequeued first. | ||
177 | */ | ||
178 | x = *s &~ *m; | ||
179 | if (x) { | ||
180 | if (x & SYNCHRONOUS_MASK) | ||
181 | x &= SYNCHRONOUS_MASK; | ||
182 | sig = ffz(~x) + 1; | ||
183 | return sig; | ||
184 | } | ||
185 | |||
169 | switch (_NSIG_WORDS) { | 186 | switch (_NSIG_WORDS) { |
170 | default: | 187 | default: |
171 | for (i = 0; i < _NSIG_WORDS; ++i, ++s, ++m) | 188 | for (i = 1; i < _NSIG_WORDS; ++i) { |
172 | if ((x = *s &~ *m) != 0) { | 189 | x = *++s &~ *++m; |
173 | sig = ffz(~x) + i*_NSIG_BPW + 1; | 190 | if (!x) |
174 | break; | 191 | continue; |
175 | } | 192 | sig = ffz(~x) + i*_NSIG_BPW + 1; |
193 | break; | ||
194 | } | ||
176 | break; | 195 | break; |
177 | 196 | ||
178 | case 2: if ((x = s[0] &~ m[0]) != 0) | 197 | case 2: |
179 | sig = 1; | 198 | x = s[1] &~ m[1]; |
180 | else if ((x = s[1] &~ m[1]) != 0) | 199 | if (!x) |
181 | sig = _NSIG_BPW + 1; | ||
182 | else | ||
183 | break; | 200 | break; |
184 | sig += ffz(~x); | 201 | sig = ffz(~x) + _NSIG_BPW + 1; |
185 | break; | 202 | break; |
186 | 203 | ||
187 | case 1: if ((x = *s &~ *m) != 0) | 204 | case 1: |
188 | sig = ffz(~x) + 1; | 205 | /* Nothing to do */ |
189 | break; | 206 | break; |
190 | } | 207 | } |
191 | 208 | ||
@@ -228,7 +245,7 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi | |||
228 | 245 | ||
229 | if (override_rlimit || | 246 | if (override_rlimit || |
230 | atomic_read(&user->sigpending) <= | 247 | atomic_read(&user->sigpending) <= |
231 | t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur) { | 248 | task_rlimit(t, RLIMIT_SIGPENDING)) { |
232 | q = kmem_cache_alloc(sigqueue_cachep, flags); | 249 | q = kmem_cache_alloc(sigqueue_cachep, flags); |
233 | } else { | 250 | } else { |
234 | print_dropped_signal(sig); | 251 | print_dropped_signal(sig); |
diff --git a/kernel/sys.c b/kernel/sys.c index 877fe4f8e05e..9814e43fb23b 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -571,8 +571,7 @@ static int set_user(struct cred *new) | |||
571 | if (!new_user) | 571 | if (!new_user) |
572 | return -EAGAIN; | 572 | return -EAGAIN; |
573 | 573 | ||
574 | if (atomic_read(&new_user->processes) >= | 574 | if (atomic_read(&new_user->processes) >= rlimit(RLIMIT_NPROC) && |
575 | current->signal->rlim[RLIMIT_NPROC].rlim_cur && | ||
576 | new_user != INIT_USER) { | 575 | new_user != INIT_USER) { |
577 | free_uid(new_user); | 576 | free_uid(new_user); |
578 | return -EAGAIN; | 577 | return -EAGAIN; |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 33e7a38b6eb9..0ef19c614f6d 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -50,6 +50,7 @@ | |||
50 | #include <linux/ftrace.h> | 50 | #include <linux/ftrace.h> |
51 | #include <linux/slow-work.h> | 51 | #include <linux/slow-work.h> |
52 | #include <linux/perf_event.h> | 52 | #include <linux/perf_event.h> |
53 | #include <linux/kprobes.h> | ||
53 | 54 | ||
54 | #include <asm/uaccess.h> | 55 | #include <asm/uaccess.h> |
55 | #include <asm/processor.h> | 56 | #include <asm/processor.h> |
@@ -1450,6 +1451,17 @@ static struct ctl_table debug_table[] = { | |||
1450 | .proc_handler = proc_dointvec | 1451 | .proc_handler = proc_dointvec |
1451 | }, | 1452 | }, |
1452 | #endif | 1453 | #endif |
1454 | #if defined(CONFIG_OPTPROBES) | ||
1455 | { | ||
1456 | .procname = "kprobes-optimization", | ||
1457 | .data = &sysctl_kprobes_optimization, | ||
1458 | .maxlen = sizeof(int), | ||
1459 | .mode = 0644, | ||
1460 | .proc_handler = proc_kprobes_optimization_handler, | ||
1461 | .extra1 = &zero, | ||
1462 | .extra2 = &one, | ||
1463 | }, | ||
1464 | #endif | ||
1453 | { } | 1465 | { } |
1454 | }; | 1466 | }; |
1455 | 1467 | ||
diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index 8f5d16e0707a..8cd50d8f9bde 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c | |||
@@ -1331,7 +1331,7 @@ static ssize_t binary_sysctl(const int *name, int nlen, | |||
1331 | ssize_t result; | 1331 | ssize_t result; |
1332 | char *pathname; | 1332 | char *pathname; |
1333 | int flags; | 1333 | int flags; |
1334 | int acc_mode, fmode; | 1334 | int acc_mode; |
1335 | 1335 | ||
1336 | pathname = sysctl_getname(name, nlen, &table); | 1336 | pathname = sysctl_getname(name, nlen, &table); |
1337 | result = PTR_ERR(pathname); | 1337 | result = PTR_ERR(pathname); |
@@ -1342,15 +1342,12 @@ static ssize_t binary_sysctl(const int *name, int nlen, | |||
1342 | if (oldval && oldlen && newval && newlen) { | 1342 | if (oldval && oldlen && newval && newlen) { |
1343 | flags = O_RDWR; | 1343 | flags = O_RDWR; |
1344 | acc_mode = MAY_READ | MAY_WRITE; | 1344 | acc_mode = MAY_READ | MAY_WRITE; |
1345 | fmode = FMODE_READ | FMODE_WRITE; | ||
1346 | } else if (newval && newlen) { | 1345 | } else if (newval && newlen) { |
1347 | flags = O_WRONLY; | 1346 | flags = O_WRONLY; |
1348 | acc_mode = MAY_WRITE; | 1347 | acc_mode = MAY_WRITE; |
1349 | fmode = FMODE_WRITE; | ||
1350 | } else if (oldval && oldlen) { | 1348 | } else if (oldval && oldlen) { |
1351 | flags = O_RDONLY; | 1349 | flags = O_RDONLY; |
1352 | acc_mode = MAY_READ; | 1350 | acc_mode = MAY_READ; |
1353 | fmode = FMODE_READ; | ||
1354 | } else { | 1351 | } else { |
1355 | result = 0; | 1352 | result = 0; |
1356 | goto out_putname; | 1353 | goto out_putname; |
@@ -1361,7 +1358,7 @@ static ssize_t binary_sysctl(const int *name, int nlen, | |||
1361 | if (result) | 1358 | if (result) |
1362 | goto out_putname; | 1359 | goto out_putname; |
1363 | 1360 | ||
1364 | result = may_open(&nd.path, acc_mode, fmode); | 1361 | result = may_open(&nd.path, acc_mode, flags); |
1365 | if (result) | 1362 | if (result) |
1366 | goto out_putpath; | 1363 | goto out_putpath; |
1367 | 1364 | ||
diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 00d59d048edf..0a67e041edf8 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/tsacct_kern.h> | 21 | #include <linux/tsacct_kern.h> |
22 | #include <linux/acct.h> | 22 | #include <linux/acct.h> |
23 | #include <linux/jiffies.h> | 23 | #include <linux/jiffies.h> |
24 | #include <linux/mm.h> | ||
24 | 25 | ||
25 | /* | 26 | /* |
26 | * fill in basic accounting fields | 27 | * fill in basic accounting fields |