public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Subject: Re: [PATCH 18/18] tracing/kprobes: Dump the culprit kprobe in case of kprobe recursion
Date: Thu, 27 Aug 2009 18:30:03 +0200	[thread overview]
Message-ID: <20090827163000.GB7618@nowhere> (raw)
In-Reply-To: <4A96ABA9.1010506@redhat.com>

On Thu, Aug 27, 2009 at 11:52:09AM -0400, Masami Hiramatsu wrote:
> Frederic Weisbecker wrote:
>> On Thu, Aug 27, 2009 at 11:30:24AM -0400, Masami Hiramatsu wrote:
>>> Hi Frederic,
>>>
>>> Frederic Weisbecker wrote:
>>>> Kprobes can enter into a probing recursion, ie: a kprobe that does an
>>>> endless loop because one of its core mechanism function used during
>>>> probing is also probed itself.
>>>>
>>>> This patch helps pinpointing the kprobe that raised such recursion
>>>> by dumping it and raising a BUG instead of a warning (we also disarm
>>>> the kprobe to try avoiding recursion in BUG itself). Having a BUG
>>>> instead of a warning stops the stacktrace in the right place and
>>>> doesn't pollute the logs with hundreds of traces that eventually end
>>>> up in a stack overflow.
>>>
>>> Thanks, but I also found similar bug cases.
>>>
>>>>
>>>> Signed-off-by: Frederic Weisbecker<fweisbec@gmail.com>
>>>> Cc: Masami Hiramatsu<mhiramat@redhat.com>
>>>> Cc: Ananth N Mavinakayanahalli<ananth@in.ibm.com>
>>>> ---
>>>>    arch/x86/kernel/kprobes.c |    8 ++++++--
>>>>    include/linux/kprobes.h   |    2 ++
>>>>    kernel/kprobes.c          |    7 +++++++
>>>>    3 files changed, 15 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
>>>> index 16ae961..ecee3d2 100644
>>>> --- a/arch/x86/kernel/kprobes.c
>>>> +++ b/arch/x86/kernel/kprobes.c
>>>> @@ -490,9 +490,13 @@ static int __kprobes reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
>>>
>>> Before this, kprobes checks p != kprobe_running(), but it's a
>>> meaningless branch. Hitting a kprobe while KPROBES_HIT_SS always
>>> treated as unrecoverable.
>>
>>
>>
>> Yeah, but that's the place where a probe ends up when bad reentrancy happens
>> right?
>
> No, a place which is shared by kprobes and other subsystems, will cause a
> problem.
>
> for example, I found an irq_return case which will be p == kprobe_running()
> on x86-64.
>
> -> <some irq occurs>
>  -> irq_return
>    -> <hit int3>
>      -> do_int3
>      -> <handling kprobe (set kprobe_running)>
>    -> irq_return (from do_int3)
>      -> <hit int3>
>        -> do_int3
>        <handling kprobe (kprobe_running == p)> <- here!
>


Oh right.


> Perhaps, the original code assumes that it will be caused by an int3
> which another subsystem inserted on out-of-line singlestep buffer
> if the hitting probe is same as current probe.
>
> However, in that case, int3 hitting address is on the out-of-line
> buffer and should be different from first (current) int3 address.


I see.


> So, I think this part should also be removed.
>
>               if (p == kprobe_running()) {
>                       regs->flags &= ~X86_EFLAGS_TF;
>                       regs->flags |= kcb->kprobe_saved_flags;
>                       return 0;
>               } else {
>
> Thank you,


So my patch is useless? Or is it also useful to detect real
recursion? (despite of such corner cases)



>>
>>
>>
>>>>    			/* A probe has been hit in the codepath leading up
>>>>    			 * to, or just after, single-stepping of a probed
>>>>    			 * instruction. This entire codepath should strictly
>>>> -			 * reside in .kprobes.text section. Raise a warning
>>>> -			 * to highlight this peculiar case.
>>>> +			 * reside in .kprobes.text section.
>>>> +			 * Raise a BUG or we'll continue in an endless
>>>> +			 * reentering loop and eventually a stack overflow.
>>>>    			 */
>>>> +			arch_disarm_kprobe(p);
>>>> +			dump_kprobe(p);
>>>> +			BUG();
>>>>    		}
>>>>    	default:
>>>>    		/* impossible cases */
>>>> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
>>>> index bcd9c07..87eb79c 100644
>>>> --- a/include/linux/kprobes.h
>>>> +++ b/include/linux/kprobes.h
>>>> @@ -296,6 +296,8 @@ void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);
>>>>    int disable_kprobe(struct kprobe *kp);
>>>>    int enable_kprobe(struct kprobe *kp);
>>>>
>>>> +void dump_kprobe(struct kprobe *kp);
>>>> +
>>>>    #else /* !CONFIG_KPROBES: */
>>>>
>>>>    static inline int kprobes_built_in(void)
>>>> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
>>>> index ef177d6..f72e96c 100644
>>>> --- a/kernel/kprobes.c
>>>> +++ b/kernel/kprobes.c
>>>> @@ -1141,6 +1141,13 @@ static void __kprobes kill_kprobe(struct kprobe *p)
>>>>    	arch_remove_kprobe(p);
>>>>    }
>>>>
>>>> +void __kprobes dump_kprobe(struct kprobe *kp)
>>>> +{
>>>> +	printk(KERN_WARNING "Dumping kprobe:\n");
>>>> +	printk(KERN_WARNING "Name: %s\nAddress: %p\nOffset: %x\n",
>>>> +	       kp->symbol_name, kp->addr, kp->offset);
>>>> +}
>>>
>>> Since kp->symbol_name + kp->offset = kp->addr, I recommend to show it
>>> as "Kprobe at %s+%x:<%p>\n", kp->symbol_name, kp->offset, kp->addr.
>>
>>
>> Ok I'll fix this, thanks.
>>
>>
>>>> +
>>>>    /* Module notifier call back, checking kprobes on the module */
>>>>    static int __kprobes kprobes_module_callback(struct notifier_block *nb,
>>>>    					     unsigned long val, void *data)
>>>
>>> Thank you,
>>>
> -- 
> Masami Hiramatsu
>
> Software Engineer
> Hitachi Computer Products (America), Inc.
> Software Solutions Division
>
> e-mail: mhiramat@redhat.com
>


  reply	other threads:[~2009-08-27 16:30 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-27  2:31 [GIT PULL] tracing/kprobes: Add dynamic tracepoints + instruction decoder Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 01/18] x86: Instruction decoder API Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 02/18] x86: X86 instruction decoder build-time selftest Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 03/18] kprobes: Checks probe address is instruction boudary on x86 Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 04/18] kprobes: Cleanup fix_riprel() using insn decoder " Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 05/18] x86: Add pt_regs register and stack access APIs Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 06/18] tracing: Ftrace dynamic ftrace_event_call support Frederic Weisbecker
2009-08-27  2:47   ` Li Zefan
2009-08-27  2:56     ` Frederic Weisbecker
2009-08-27 15:07       ` Masami Hiramatsu
2009-08-27  2:32 ` [PATCH 07/18] tracing: Introduce TRACE_FIELD_ZERO() macro Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 08/18] tracing: Add kprobe-based event tracer Frederic Weisbecker
2009-08-27  7:31   ` Ingo Molnar
2009-08-27 13:48     ` Frederic Weisbecker
2009-08-27 15:38       ` Masami Hiramatsu
2009-08-27  2:32 ` [PATCH 09/18] tracing: Add kprobe-based event tracer documentation Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 10/18] tracing: Kprobe-tracer supports more than 6 arguments Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 11/18] tracing: Generate names for each kprobe event automatically Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 12/18] tracing: Kprobe tracer assigns new event ids for each event Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 13/18] tracing: Add kprobes event profiling interface Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 14/18] x86: Fix x86 instruction decoder selftest to check only .text Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 15/18] x86: Check awk features before generating inat-tables.c Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 16/18] tracing/kprobes: Fix format typo in trace_kprobes Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 17/18] tracing/kprobes: Change trace_arg to probe_arg Frederic Weisbecker
2009-08-27  2:32 ` [PATCH 18/18] tracing/kprobes: Dump the culprit kprobe in case of kprobe recursion Frederic Weisbecker
2009-08-27 15:30   ` Masami Hiramatsu
2009-08-27 15:34     ` Frederic Weisbecker
2009-08-27 15:52       ` Masami Hiramatsu
2009-08-27 16:30         ` Frederic Weisbecker [this message]
2009-08-27 16:45           ` Masami Hiramatsu
2009-08-27 16:45             ` Frederic Weisbecker
2009-08-27  3:34 ` [GIT PULL v2] tracing/kprobes: v1 + two fixes Frederic Weisbecker
2009-08-27 15:24   ` Ingo Molnar
2009-08-27 15:40     ` Frederic Weisbecker
2009-08-27 15:59     ` Frederic Weisbecker
2009-08-27 16:17       ` [PATCH] tracing: Undef TRACE_EVENT_FN between trace events headers inclusion Frederic Weisbecker
2009-08-27 16:36         ` [tip:tracing/core] " tip-bot for Frederic Weisbecker
2009-08-27 16:12     ` [GIT PULL v2] tracing/kprobes: v1 + two fixes Masami Hiramatsu
2009-08-27 16:35       ` Ingo Molnar
2009-08-27 16:52         ` Masami Hiramatsu
2009-08-29 11:02           ` Ingo Molnar
2009-08-28 22:13         ` [PATCH -tip tracing/kprobes 1/2] x86: Allow x86-32 instruction decoder selftest on x86-64 Masami Hiramatsu
2009-08-30  1:35           ` Frederic Weisbecker
2009-10-17  9:58           ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-28 22:13         ` [PATCH -tip tracing/kprobes 2/2] x86: Remove unused config macros from instruction decoder selftest Masami Hiramatsu
2009-10-17  9:58           ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-27 15:26   ` [GIT PULL v2] tracing/kprobes: v1 + two fixes Ingo Molnar
2009-09-16  5:30     ` Frederic Weisbecker
2009-08-27  3:34 ` [PATCH 19/18] tracing: Restore the const qualifier for field names and types definition Frederic Weisbecker
2009-08-27 15:07   ` Masami Hiramatsu
2009-08-27  3:34 ` [PATCH 20/18] tracing: Remove unneeded pointer casts Frederic Weisbecker
2009-08-27 15:08   ` Masami Hiramatsu
2009-08-27 15:00 ` [GIT PULL] tracing/kprobes: Add dynamic tracepoints + instruction decoder Masami Hiramatsu
2009-08-27 15:25   ` Frederic Weisbecker
2009-08-27 17:22     ` [PATCH -tip tracing/kprobes 1/6] kprobes/x86: Call BUG() when reentering probe into KPROBES_HIT_SS Masami Hiramatsu
2009-08-28  4:38       ` Ananth N Mavinakayanahalli
2009-08-30  1:25       ` Frederic Weisbecker
2009-10-17  9:56       ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-27 17:23     ` [PATCH -tip tracing/kprobes 2/6] kprobes/x86-64: Allow to reenter probe on post_handler Masami Hiramatsu
2009-08-28  4:39       ` Ananth N Mavinakayanahalli
2009-10-17  9:57       ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-27 17:23     ` [PATCH -tip tracing/kprobes 3/6] kprobes/x86: Fix to add __kprobes to in-kernel fault handing functions Masami Hiramatsu
2009-08-28  4:40       ` Ananth N Mavinakayanahalli
2009-08-30  0:50       ` Frederic Weisbecker
2009-08-30  2:43         ` Masami Hiramatsu
2009-08-30  0:53       ` Frederic Weisbecker
2009-08-30  2:49         ` Masami Hiramatsu
2009-08-30 16:09           ` Frederic Weisbecker
2009-08-31  4:00             ` Masami Hiramatsu
2009-09-01 20:09               ` Masami Hiramatsu
2009-09-02 12:58             ` Masami Hiramatsu
2009-09-03  5:46               ` Frederic Weisbecker
2009-09-04 19:06               ` Frederic Weisbecker
2009-09-04 22:29                 ` Masami Hiramatsu
2009-09-08 16:32                 ` [PATCH tracing/kprobes] x86: Add MMX support for instruction decoder Masami Hiramatsu
2009-09-10 22:57                   ` Frederic Weisbecker
2009-10-17  9:58                   ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-09-08 16:54           ` [RFC PATCH tracing/kprobes] kprobes: Call vmalloc_sync_all() for avoiding in-kernel paging on kprobes Masami Hiramatsu
     [not found]             ` <20090908165438.24437.40931.stgit@dhcp-100-2-132.bos.redhat .com>
2009-09-08 17:03               ` system hang - I suspect a sata problem - 2.6.30.5 debug kernel jeffunit
2009-10-17  9:57       ` [tip:perf/probes] kprobes/x86: Fix to add __kprobes to in-kernel fault handing functions tip-bot for Masami Hiramatsu
2009-08-27 17:23     ` [PATCH -tip tracing/kprobes 4/6] kprobes: Fix to add __kprobes to notify_die Masami Hiramatsu
2009-08-28  4:41       ` Ananth N Mavinakayanahalli
2009-10-17  9:57       ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-27 17:23     ` [PATCH -tip tracing/kprobes 5/6] kprobes/x86-64: Fix to move common_interrupt to .kprobes.text Masami Hiramatsu
2009-10-17  9:57       ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-27 17:23     ` [PATCH -tip tracing/kprobes 6/6] kprobes: Prohibit to probe native_get_debugreg Masami Hiramatsu
2009-08-28  4:41       ` Ananth N Mavinakayanahalli
2009-10-17  9:57       ` [tip:perf/probes] " tip-bot for Masami Hiramatsu
2009-08-27 17:32     ` [GIT PULL] tracing/kprobes: Add dynamic tracepoints + instruction decoder Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090827163000.GB7618@nowhere \
    --to=fweisbec@gmail.com \
    --cc=ananth@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox