Live-Patching Archive on
 help / color / Atom feed
From: Peter Zijlstra <>
To: Jann Horn <>
	Alexei Starovoitov <>,
	Daniel Borkmann <>,
	Steven Rostedt <>,
	KP Singh <>,
	Andy Lutomirski <>,
	kernel list <>,
	the arch/x86 maintainers <>,
	Josh Poimboeuf <>,
	Ingo Molnar <>
Subject: Re: BPF tracing trampoline synchronization between update/freeing and execution?
Date: Mon, 6 Jan 2020 17:56:54 +0100
Message-ID: <> (raw)
In-Reply-To: <>

On Mon, Jan 06, 2020 at 05:39:30PM +0100, Jann Horn wrote:
> Hi!
> I was chatting with kpsingh about BPF trampolines, and I noticed that
> it looks like BPF trampolines (as of current bpf-next/master) seem to
> be missing synchronization between trampoline code updates and
> trampoline execution. Or maybe I'm missing something?
> If I understand correctly, trampolines are executed directly from the
> fentry placeholders at the start of arbitrary kernel functions, so
> they can run without any locks held. So for example, if task A starts
> executing a trampoline on entry to sys_open(), then gets preempted in
> the middle of the trampoline, and then task B quickly calls
> BPF_RAW_TRACEPOINT_OPEN twice, and then task A continues execution,
> task A will end up executing the middle of newly-written machine code,
> which can probably end up crashing the kernel somehow?
> I think that at least to synchronize trampoline text freeing with
> concurrent trampoline execution, it is necessary to do something
> similar to what the livepatching code does with klp_check_stack(), and
> then either use a callback from the scheduler to periodically re-check
> tasks that were in the trampoline or let the trampoline tail-call into
> a cleanup helper that is part of normal kernel text. And you'd
> probably have to gate BPF trampolines on

ftrace uses synchronize_rcu_tasks() to flip between trampolines iirc.

  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06 16:39 Jann Horn
2020-01-06 16:56 ` Peter Zijlstra [this message]
2020-01-06 22:29   ` Alexei Starovoitov
2020-01-07  8:28   ` Petr Mladek
2020-01-07  9:03     ` Petr Mladek

Reply instructions:

You may reply publically 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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Live-Patching Archive on

Archives are clonable:
	git clone --mirror live-patching/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 live-patching live-patching/ \
	public-inbox-index live-patching

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone