From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26637 invoked by alias); 27 Feb 2014 07:34:15 -0000 Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org Received: (qmail 26559 invoked by uid 89); 27 Feb 2014 07:34:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_00,KHOP_BIG_TO_CC,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail7.hitachi.co.jp Received: from mail7.hitachi.co.jp (HELO mail7.hitachi.co.jp) (133.145.228.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Feb 2014 07:34:13 +0000 Received: from mlsv3.hitachi.co.jp (unknown [133.144.234.166]) by mail7.hitachi.co.jp (Postfix) with ESMTP id A138937ACD; Thu, 27 Feb 2014 16:34:11 +0900 (JST) Received: from mfilter03.hitachi.co.jp by mlsv3.hitachi.co.jp (8.13.1/8.13.1) id s1R7YBN2031115; Thu, 27 Feb 2014 16:34:11 +0900 Received: from vshuts01.hitachi.co.jp (vshuts01.hitachi.co.jp [10.201.6.83]) by mfilter03.hitachi.co.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id s1R7Y9F0032059; Thu, 27 Feb 2014 16:34:10 +0900 Received: from gmml27.itg.hitachi.co.jp (unknown [158.213.165.130]) by vshuts01.hitachi.co.jp (Postfix) with ESMTP id 5E5242F0050; Thu, 27 Feb 2014 16:34:10 +0900 (JST) Received: from ltc230.yrl.intra.hitachi.co.jp by gmml27.itg.hitachi.co.jp (AIX5.2/8.11.6p2/8.11.0) id s1R7Y9k1843272; Thu, 27 Feb 2014 16:34:09 +0900 Subject: [PATCH -tip v7 22/26] kprobes/x86: Use kprobe_blacklist for .kprobes.text and .entry.text From: Masami Hiramatsu To: linux-kernel@vger.kernel.org, Ingo Molnar Cc: Ananth N Mavinakayanahalli , Sandeepa Prabhu , Frederic Weisbecker , x86@kernel.org, Steven Rostedt , "David S. Miller" , fche@redhat.com, mingo@redhat.com, systemtap@sourceware.org, "H. Peter Anvin" , Andrew Morton , Thomas Gleixner Date: Thu, 27 Feb 2014 07:34:00 -0000 Message-ID: <20140227073409.20992.40223.stgit@ltc230.yrl.intra.hitachi.co.jp> In-Reply-To: <20140227073315.20992.6174.stgit@ltc230.yrl.intra.hitachi.co.jp> References: <20140227073315.20992.6174.stgit@ltc230.yrl.intra.hitachi.co.jp> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-q1/txt/msg00186.txt.bz2 Use kprobe_blackpoint for blacklisting .entry.text and .kprobees.text instead of arch_within_kprobe_blacklist. This also makes them visible via (debugfs)/kprobes/blacklist. Signed-off-by: Masami Hiramatsu Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Ananth N Mavinakayanahalli Cc: "David S. Miller" Cc: Steven Rostedt Cc: Andrew Morton --- arch/x86/kernel/kprobes/core.c | 11 +------ include/linux/kprobes.h | 1 + kernel/kprobes.c | 64 ++++++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index d00103a..4767fda 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -1065,17 +1065,10 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) } NOKPROBE_SYMBOL(longjmp_break_handler); -bool arch_within_kprobe_blacklist(unsigned long addr) -{ - return (addr >= (unsigned long)__kprobes_text_start && - addr < (unsigned long)__kprobes_text_end) || - (addr >= (unsigned long)__entry_text_start && - addr < (unsigned long)__entry_text_end); -} - int __init arch_init_kprobes(void) { - return 0; + return kprobe_blacklist_add_range((unsigned long)__entry_text_start, + (unsigned long) __entry_text_end); } int arch_trampoline_kprobe(struct kprobe *p) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index e059507..e81bced 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -266,6 +266,7 @@ extern int arch_init_kprobes(void); extern void show_registers(struct pt_regs *regs); extern void kprobes_inc_nmissed_count(struct kprobe *p); extern bool arch_within_kprobe_blacklist(unsigned long addr); +extern int kprobe_blacklist_add_range(unsigned long start, unsigned long end); struct kprobe_insn_cache { struct mutex mutex; diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 8319048..abdede5 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1325,13 +1325,6 @@ out: return ret; } -bool __weak arch_within_kprobe_blacklist(unsigned long addr) -{ - /* The __kprobes marked functions and entry code must not be probed */ - return addr >= (unsigned long)__kprobes_text_start && - addr < (unsigned long)__kprobes_text_end; -} - static struct kprobe_blacklist_entry *find_blacklist_entry(unsigned long addr) { struct kprobe_blacklist_entry *ent; @@ -1346,8 +1339,6 @@ static struct kprobe_blacklist_entry *find_blacklist_entry(unsigned long addr) static bool within_kprobe_blacklist(unsigned long addr) { - if (arch_within_kprobe_blacklist(addr)) - return true; /* * If there exists a kprobe_blacklist, verify and * fail any probe registration in the prohibited area @@ -2032,6 +2023,40 @@ void dump_kprobe(struct kprobe *kp) } NOKPROBE_SYMBOL(dump_kprobe); +static int __kprobe_blacklist_add(unsigned long start, unsigned long end) +{ + struct kprobe_blacklist_entry *ent; + + ent = kmalloc(sizeof(*ent), GFP_KERNEL); + if (!ent) + return -ENOMEM; + + ent->start_addr = start; + ent->end_addr = end; + INIT_LIST_HEAD(&ent->list); + list_add_tail(&ent->list, &kprobe_blacklist); + return 0; +} + +int kprobe_blacklist_add_range(unsigned long start, unsigned long end) +{ + unsigned long offset = 0, size = 0; + int err = 0; + + mutex_lock(&kprobe_blacklist_mutex); + while (!err && start < end) { + if (!kallsyms_lookup_size_offset(start, &size, &offset) || + size == 0) { + err = -ENOENT; + break; + } + err = __kprobe_blacklist_add(start, start + size); + start += size; + } + mutex_unlock(&kprobe_blacklist_mutex); + return err; +} + /* * Lookup and populate the kprobe_blacklist. * @@ -2043,8 +2068,8 @@ NOKPROBE_SYMBOL(dump_kprobe); static int populate_kprobe_blacklist(unsigned long *start, unsigned long *end) { unsigned long *iter; - struct kprobe_blacklist_entry *ent; unsigned long offset = 0, size = 0; + int ret; mutex_lock(&kprobe_blacklist_mutex); for (iter = start; iter < end; iter++) { @@ -2052,14 +2077,7 @@ static int populate_kprobe_blacklist(unsigned long *start, unsigned long *end) pr_err("Failed to find blacklist %p\n", (void *)*iter); continue; } - - ent = kmalloc(sizeof(*ent), GFP_KERNEL); - if (!ent) - return -ENOMEM; - ent->start_addr = *iter; - ent->end_addr = *iter + size; - INIT_LIST_HEAD(&ent->list); - list_add_tail(&ent->list, &kprobe_blacklist); + ret = __kprobe_blacklist_add(*iter, *iter + size); } mutex_unlock(&kprobe_blacklist_mutex); @@ -2154,7 +2172,15 @@ static int __init init_kprobes(void) err = populate_kprobe_blacklist(__start_kprobe_blacklist, __stop_kprobe_blacklist); - if (err) { + + if (err >= 0 && __kprobes_text_start != __kprobes_text_end) { + /* The __kprobes marked functions must not be probed */ + err = kprobe_blacklist_add_range( + (unsigned long)__kprobes_text_start, + (unsigned long)__kprobes_text_end); + } + + if (err < 0) { pr_err("kprobes: failed to populate blacklist: %d\n", err); pr_err("Please take care of using kprobes.\n"); }