mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: peterz@infradead.org
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: "Eddy_Wu@trendmicro.com" <Eddy_Wu@trendmicro.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Paul McKenney <paulmck@kernel.org>
Subject: Re: x86/kprobes: kretprobe fails to triggered if kprobe at function entry is not optimized (trigger by int3 breakpoint)
Date: Tue, 25 Aug 2020 16:15:21 +0200	[thread overview]
Message-ID: <20200825141521.GA1362448@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200825225954.2202d28b449f2354d5c88070@kernel.org>

On Tue, Aug 25, 2020 at 10:59:54PM +0900, Masami Hiramatsu wrote:
> On Tue, 25 Aug 2020 15:30:05 +0200
> peterz@infradead.org wrote:
> 
> > On Tue, Aug 25, 2020 at 10:15:55PM +0900, Masami Hiramatsu wrote:
> > 
> > > > damn... one last problem is dangling instances.. so close.
> > > > We can apparently unregister a kretprobe while there's still active
> > > > kretprobe_instance's out referencing it.
> > > 
> > > Yeah, kretprobe already provided the per-instance data (as far as
> > > I know, only systemtap depends on it). We need to provide it for
> > > such users.
> > > But if we only have one lock, we can avoid checking NMI because
> > > we can check the recursion with trylock. It is needed only if the
> > > kretprobe uses per-instance data. Or we can just pass a dummy
> > > instance on the stack.
> > 
> > I think it is true in general, you can unregister a rp while tasks are
> > preempted.
> 
> Would you mean the kretprobe handler (or trampoline handler) will be
> preempted? All kprobes (including kretprobe) handler is running in
> non-preemptive state, so it shouldn't happen...

I was thinking about something like:


	for_each_process_thread(p, t) {
		if (!t->kretprobe_instances.first)
			continue;

	again:
		if (try_invoke_on_locked_down_task(t, unhook_rp_inst, tp))
			continue;

		smp_function_call(...);

		if (!done)
			goto again;
	}

So then for each task that has a kretprobe stack, we iterate the stack
and set ri->rp = NULL, remotely when the task isn't running, locally if
the task is running.

I just need to change the semantics of try_invoke_on_locked_down_task()
a bit -- they're a tad weird atm.

> > Anyway,. I think I have a solution, just need to talk to paulmck for a
> > bit.
> 
> Ah, you mentioned that the removing the kfree() from the trampline
> handler? I think we can make an rcu callback which will kfree() the
> given instances. (If it works in NMI)

Yes, calling kfree() from the trampoline seems dodgy at best. When
!ri->rp rcu_free() is a good option.

  reply	other threads:[~2020-08-25 14:15 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-24 12:02 Eddy_Wu
2020-08-24 14:14 ` Peter Zijlstra
2020-08-24 16:18   ` Eddy_Wu
2020-08-24 18:15   ` Masami Hiramatsu
2020-08-25  7:36     ` peterz
2020-08-24 15:54 ` Masami Hiramatsu
2020-08-24 16:41   ` Eddy_Wu
2020-08-25  6:15     ` Masami Hiramatsu
2020-08-25  8:33       ` Eddy_Wu
2020-08-25 11:06       ` [PATCH] kprobes/x86: Fixes NMI context check on x86 kernel test robot
2020-08-25 12:09       ` x86/kprobes: kretprobe fails to triggered if kprobe at function entry is not optimized (trigger by int3 breakpoint) peterz
2020-08-25 13:15         ` Masami Hiramatsu
2020-08-25 13:30           ` peterz
2020-08-25 13:59             ` Masami Hiramatsu
2020-08-25 14:15               ` peterz [this message]
2020-08-25 14:10             ` peterz
2020-08-25 14:19               ` Masami Hiramatsu
2020-08-27  9:02           ` peterz
2020-08-26  7:07         ` Eddy_Wu
2020-08-26  8:22           ` Masami Hiramatsu
2020-08-26  9:06             ` Masami Hiramatsu
2020-08-26 10:00               ` Masami Hiramatsu
2020-08-26 10:25                 ` peterz
2020-08-26 13:36                   ` Eddy_Wu
2020-08-26 13:51                     ` Masami Hiramatsu
2020-08-26  9:01           ` peterz
2020-08-26  9:21             ` peterz
2020-08-26  8:31         ` Masami Hiramatsu
2020-08-25 12:20       ` [PATCH] kprobes/x86: Fixes NMI context check on x86 kernel test robot
2020-08-25 12:25       ` kernel test robot

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=20200825141521.GA1362448@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Eddy_Wu@trendmicro.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®