lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181126200801.GW2113@hirez.programming.kicks-ass.net>
Date:   Mon, 26 Nov 2018 21:08:01 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Josh Poimboeuf <jpoimboe@...hat.com>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Ard Biesheuvel <ard.biesheuvel@...aro.org>,
        Andy Lutomirski <luto@...nel.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        Ingo Molnar <mingo@...nel.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Masami Hiramatsu <mhiramat@...nel.org>,
        Jason Baron <jbaron@...mai.com>, Jiri Kosina <jkosina@...e.cz>,
        David Laight <David.Laight@...LAB.COM>,
        Borislav Petkov <bp@...en8.de>,
        Julia Cartwright <julia@...com>, Jessica Yu <jeyu@...nel.org>,
        "H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH v2 4/4] x86/static_call: Add inline static call
 implementation for x86-64

On Mon, Nov 26, 2018 at 11:56:24AM -0600, Josh Poimboeuf wrote:
> diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c
> index d3869295b88d..8fd6c8556750 100644
> --- a/arch/x86/kernel/static_call.c
> +++ b/arch/x86/kernel/static_call.c
> @@ -7,24 +7,19 @@
>  
>  #define CALL_INSN_SIZE 5
>  
> +unsigned long bp_handler_call_return_addr;
>  
> +static void static_call_bp_handler(struct pt_regs *regs)
> +{
>  #ifdef CONFIG_HAVE_STATIC_CALL_INLINE
> +	/*
> +	 * Push the return address on the stack so the "called" function will
> +	 * return to immediately after the call site.
> +	 */
> +	regs->sp -= sizeof(long);
> +	*(unsigned long *)regs->sp = bp_handler_call_return_addr;
>  #endif
> +}
>  
>  void arch_static_call_transform(void *site, void *tramp, void *func)
>  {
> @@ -52,14 +47,12 @@ void arch_static_call_transform(void *site, void *tramp, void *func)
>  	opcodes[0] = insn_opcode;
>  	memcpy(&opcodes[1], &dest_relative, CALL_INSN_SIZE - 1);
>  
>  	if (IS_ENABLED(CONFIG_HAVE_STATIC_CALL_INLINE))
> +		bp_handler_call_return_addr = insn + CALL_INSN_SIZE;
>  
>  	/* Patch the call site: */
>  	text_poke_bp((void *)insn, opcodes, CALL_INSN_SIZE,
> -		     static_call_bp_handler);
> +		     static_call_bp_handler, func);
>  
>  done:
>  	mutex_unlock(&text_mutex);


like maybe something along the lines of:

struct sc_data {
	unsigned long ret;
	unsigned long ip;
};

void sc_handler(struct pt_regs *regs, void *data)
{
	struct sc_data *scd = data;

	regs->sp -= sizeof(long);
	*(unsigned long *)regs->sp = scd->ret;
	regs->ip = scd->ip;
}

arch_static_call_transform()
{
	...

	scd = (struct sc_data){
		.ret = insn + CALL_INSN_SIZE,
		.ip = (unsigned long)func,
	};

	text_poke_bp((void *)insn, opcodes, CALL_INSN_SIZE,
			sc_handler, (void *)&scd);

	...
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ