diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/exit.c | 2 | ||||
-rw-r--r-- | kernel/fork.c | 5 | ||||
-rw-r--r-- | kernel/kprobes.c | 170 | ||||
-rw-r--r-- | kernel/sched.c | 8 |
4 files changed, 127 insertions, 58 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 3ebcd60a19c6..9d1b10ed0135 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -784,6 +784,8 @@ fastcall NORET_TYPE void do_exit(long code) profile_task_exit(tsk); + WARN_ON(atomic_read(&tsk->fs_excl)); + if (unlikely(in_interrupt())) panic("Aiee, killing interrupt handler!"); if (unlikely(!tsk->pid)) diff --git a/kernel/fork.c b/kernel/fork.c index 2c7806873bfd..cdef6cea8900 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1090,6 +1090,11 @@ static task_t *copy_process(unsigned long clone_flags, spin_unlock(¤t->sighand->siglock); } + /* + * inherit ioprio + */ + p->ioprio = current->ioprio; + SET_LINKS(p); if (unlikely(p->ptrace & PT_PTRACED)) __ptrace_link(p, current->parent); diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 334f37472c56..90c0e82b650c 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -36,6 +36,7 @@ #include <linux/hash.h> #include <linux/init.h> #include <linux/module.h> +#include <linux/moduleloader.h> #include <asm/cacheflush.h> #include <asm/errno.h> #include <asm/kdebug.h> @@ -50,6 +51,106 @@ unsigned int kprobe_cpu = NR_CPUS; static DEFINE_SPINLOCK(kprobe_lock); static struct kprobe *curr_kprobe; +/* + * kprobe->ainsn.insn points to the copy of the instruction to be + * single-stepped. x86_64, POWER4 and above have no-exec support and + * stepping on the instruction on a vmalloced/kmalloced/data page + * is a recipe for disaster + */ +#define INSNS_PER_PAGE (PAGE_SIZE/(MAX_INSN_SIZE * sizeof(kprobe_opcode_t))) + +struct kprobe_insn_page { + struct hlist_node hlist; + kprobe_opcode_t *insns; /* Page of instruction slots */ + char slot_used[INSNS_PER_PAGE]; + int nused; +}; + +static struct hlist_head kprobe_insn_pages; + +/** + * get_insn_slot() - Find a slot on an executable page for an instruction. + * We allocate an executable page if there's no room on existing ones. + */ +kprobe_opcode_t *get_insn_slot(void) +{ + struct kprobe_insn_page *kip; + struct hlist_node *pos; + + hlist_for_each(pos, &kprobe_insn_pages) { + kip = hlist_entry(pos, struct kprobe_insn_page, hlist); + if (kip->nused < INSNS_PER_PAGE) { + int i; + for (i = 0; i < INSNS_PER_PAGE; i++) { + if (!kip->slot_used[i]) { + kip->slot_used[i] = 1; + kip->nused++; + return kip->insns + (i * MAX_INSN_SIZE); + } + } + /* Surprise! No unused slots. Fix kip->nused. */ + kip->nused = INSNS_PER_PAGE; + } + } + + /* All out of space. Need to allocate a new page. Use slot 0.*/ + kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL); + if (!kip) { + return NULL; + } + + /* + * Use module_alloc so this page is within +/- 2GB of where the + * kernel image and loaded module images reside. This is required + * so x86_64 can correctly handle the %rip-relative fixups. + */ + kip->insns = module_alloc(PAGE_SIZE); + if (!kip->insns) { + kfree(kip); + return NULL; + } + INIT_HLIST_NODE(&kip->hlist); + hlist_add_head(&kip->hlist, &kprobe_insn_pages); + memset(kip->slot_used, 0, INSNS_PER_PAGE); + kip->slot_used[0] = 1; + kip->nused = 1; + return kip->insns; +} + +void free_insn_slot(kprobe_opcode_t *slot) +{ + struct kprobe_insn_page *kip; + struct hlist_node *pos; + + hlist_for_each(pos, &kprobe_insn_pages) { + kip = hlist_entry(pos, struct kprobe_insn_page, hlist); + if (kip->insns <= slot && + slot < kip->insns + (INSNS_PER_PAGE * MAX_INSN_SIZE)) { + int i = (slot - kip->insns) / MAX_INSN_SIZE; + kip->slot_used[i] = 0; + kip->nused--; + if (kip->nused == 0) { + /* + * Page is no longer in use. Free it unless + * it's the last one. We keep the last one + * so as not to have to set it up again the + * next time somebody inserts a probe. + */ + hlist_del(&kip->hlist); + if (hlist_empty(&kprobe_insn_pages)) { + INIT_HLIST_NODE(&kip->hlist); + hlist_add_head(&kip->hlist, + &kprobe_insn_pages); + } else { + module_free(NULL, kip->insns); + kfree(kip); + } + } + return; + } + } +} + /* Locks kprobe: irqs must be disabled */ void lock_kprobes(void) { @@ -139,12 +240,6 @@ static int aggr_break_handler(struct kprobe *p, struct pt_regs *regs) return 0; } -struct kprobe trampoline_p = { - .addr = (kprobe_opcode_t *) &kretprobe_trampoline, - .pre_handler = trampoline_probe_handler, - .post_handler = trampoline_post_handler -}; - struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp) { struct hlist_node *node; @@ -163,35 +258,18 @@ static struct kretprobe_instance *get_used_rp_inst(struct kretprobe *rp) return NULL; } -struct kretprobe_instance *get_rp_inst(void *sara) -{ - struct hlist_head *head; - struct hlist_node *node; - struct task_struct *tsk; - struct kretprobe_instance *ri; - - tsk = arch_get_kprobe_task(sara); - head = &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]; - hlist_for_each_entry(ri, node, head, hlist) { - if (ri->stack_addr == sara) - return ri; - } - return NULL; -} - void add_rp_inst(struct kretprobe_instance *ri) { - struct task_struct *tsk; /* * Remove rp inst off the free list - * Add it back when probed function returns */ hlist_del(&ri->uflist); - tsk = arch_get_kprobe_task(ri->stack_addr); + /* Add rp inst onto table */ INIT_HLIST_NODE(&ri->hlist); hlist_add_head(&ri->hlist, - &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]); + &kretprobe_inst_table[hash_ptr(ri->task, KPROBE_HASH_BITS)]); /* Also add this rp inst to the used list. */ INIT_HLIST_NODE(&ri->uflist); @@ -218,34 +296,25 @@ struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk) return &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]; } -struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk) -{ - struct task_struct *tsk; - struct hlist_head *head; - struct hlist_node *node; - struct kretprobe_instance *ri; - - head = &kretprobe_inst_table[hash_ptr(tk, KPROBE_HASH_BITS)]; - - hlist_for_each_entry(ri, node, head, hlist) { - tsk = arch_get_kprobe_task(ri->stack_addr); - if (tsk == tk) - return ri; - } - return NULL; -} - /* - * This function is called from do_exit or do_execv when task tk's stack is - * about to be recycled. Recycle any function-return probe instances - * associated with this task. These represent probed functions that have - * been called but may never return. + * This function is called from exit_thread or flush_thread when task tk's + * stack is being recycled so that we can recycle any function-return probe + * instances associated with this task. These left over instances represent + * probed functions that have been called but will never return. */ void kprobe_flush_task(struct task_struct *tk) { + struct kretprobe_instance *ri; + struct hlist_head *head; + struct hlist_node *node, *tmp; unsigned long flags = 0; + spin_lock_irqsave(&kprobe_lock, flags); - arch_kprobe_flush_task(tk); + head = kretprobe_inst_table_head(current); + hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { + if (ri->task == tk) + recycle_rp_inst(ri); + } spin_unlock_irqrestore(&kprobe_lock, flags); } @@ -505,9 +574,10 @@ static int __init init_kprobes(void) INIT_HLIST_HEAD(&kretprobe_inst_table[i]); } - err = register_die_notifier(&kprobe_exceptions_nb); - /* Register the trampoline probe for return probe */ - register_kprobe(&trampoline_p); + err = arch_init(); + if (!err) + err = register_die_notifier(&kprobe_exceptions_nb); + return err; } diff --git a/kernel/sched.c b/kernel/sched.c index a07cff90d849..e2b0d3e4dd06 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -3448,15 +3448,7 @@ int task_nice(const task_t *p) { return TASK_NICE(p); } - -/* - * The only users of task_nice are binfmt_elf and binfmt_elf32. - * binfmt_elf is no longer modular, but binfmt_elf32 still is. - * Therefore, task_nice is needed if there is a compat_mode. - */ -#ifdef CONFIG_COMPAT EXPORT_SYMBOL_GPL(task_nice); -#endif /** * idle_cpu - is a given cpu idle currently? |