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] [day] [month] [year] [list]
Message-ID: <a096ca52-0ee9-79c6-5514-7b0af39c9bba@iogearbox.net>
Date:   Thu, 22 Feb 2018 10:20:24 +0100
From:   Daniel Borkmann <daniel@...earbox.net>
To:     Eric Dumazet <eric.dumazet@...il.com>,
        Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc:     ast@...nel.org, torvalds@...ux-foundation.org,
        netdev@...r.kernel.org
Subject: Re: [PATCH bpf] bpf, x64: implement retpoline for tail call

On 02/22/2018 04:53 AM, Eric Dumazet wrote:
> On Wed, 2018-02-21 at 19:43 -0800, Alexei Starovoitov wrote:
>> On Wed, Feb 21, 2018 at 07:04:02PM -0800, Eric Dumazet wrote:
>>> On Thu, 2018-02-22 at 01:05 +0100, Daniel Borkmann wrote:
>>>
>>> ...
>>>
>>>> +/* Instead of plain jmp %rax, we emit a retpoline to control
>>>> + * speculative execution for the indirect branch.
>>>> + */
>>>> +static void emit_retpoline_rax_trampoline(u8 **pprog)
>>>> +{
>>>> +	u8 *prog = *pprog;
>>>> +	int cnt = 0;
>>>> +
>>>> +	EMIT1_off32(0xE8, 7);	 /* callq <set_up_target> */
>>>> +	/* capture_spec: */
>>>> +	EMIT2(0xF3, 0x90);	 /* pause */
>>>> +	EMIT3(0x0F, 0xAE, 0xE8); /* lfence */
>>>> +	EMIT2(0xEB, 0xF9);	 /* jmp <capture_spec> */
>>>> +	/* set_up_target: */
>>>> +	EMIT4(0x48, 0x89, 0x04, 0x24); /* mov %rax,(%rsp) */
>>>> +	EMIT1(0xC3);		 /* retq */
>>>> +
>>>> +	BUILD_BUG_ON(cnt != RETPOLINE_SIZE);
>>>> +	*pprog = prog;
>>>
>>> You might define the actual code sequence (and length) in 
>>> arch/x86/include/asm/nospec-branch.h
>>>
>>> If we need to adjust code sequences for RETPOLINE, then we wont
>>> forget/miss that arch/x86/net/bpf_jit_comp.c had it hard-coded.
>>
>> like adding a comment to asm/nospec-branch.h that says
>> "dont forget to adjust bpf_jit_comp.c" ?
>> but clang/gcc generate slightly different sequences for
>> retpoline anyway, so even if '.macro RETPOLINE_JMP' in
>> nospec-branch.h changes it doesn't mean that x64 jit has to change.
>> So what kinda comment there would make sense?
> 
> I was thinking of something very explicit :
> 
> /* byte sequence for following assembly code used by eBPF
>    call ...
>    ...
>    retq
> */
> #define RETPOLINE_RAX_DIRECT_FOR_EBPF                         \
>        EMIT1_off32(0xE8, 7);    /* callq <set_up_target> */   \
>        /* capture_spec: */                                    \
>        EMIT2(0xF3, 0x90);       /* pause */                   \
>        EMIT3(0x0F, 0xAE, 0xE8); /* lfence */                  \
>        EMIT2(0xEB, 0xF9);       /* jmp <capture_spec> */      \
>        /* set_up_target: */                                   \
>        EMIT4(0x48, 0x89, 0x04, 0x24); /* mov %rax,(%rsp) */   \
>        EMIT1(0xC3);             /* retq */                    \
> 
> Might be simply byte encoded, (array of 17 bytes)
> 
> Well, something like that anyway...

Okay, sounds fine. Will respin, thanks Eric!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ