Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Linux, the way to get rid of boot viruses -- MaDsen Wikholm, mwikholm@at8.abo.fi


devel / comp.arch / Predicting RET misprediction

SubjectAuthor
* Predicting RET mispredictionStefan Monnier
`- Re: Predicting RET mispredictionMitchAlsup

1
Predicting RET misprediction

<jwvlf8h5pjd.fsf-monnier+comp.arch@gnu.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16755&group=comp.arch#16755

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monn...@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.arch
Subject: Predicting RET misprediction
Date: Fri, 14 May 2021 11:37:29 -0400
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <jwvlf8h5pjd.fsf-monnier+comp.arch@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="ea2d874832a9c5172debb835c6f6b45f";
logging-data="21219"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+L3HXVZCsh4YX/0f+NTXhf"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Cancel-Lock: sha1:zQ+sVEC+VEu29H8yg61TBxc4uns=
sha1:Zb6E04LXd7jD6bzJBK9njjY5sno=
 by: Stefan Monnier - Fri, 14 May 2021 15:37 UTC

There's an interesting hack described at:

https://blog.can.ac/2021/03/22/speculating-x86-64-isa-with-one-weird-trick/

where the author causes a misprediction in order to force the processor
to "execute" arbitrary code safely (relying on the speculation mechanism
to keep the code perfectly safe by undoing its effect (save for the
impact on the internal event counters, which is presumably the only
remaining traces of what happened)).

The code he uses to trick the processor into executing code
speculatively is the following:

call x
<speculated code>
x:
lea rax, [rip+z]
xchg [rsp], rax
ret
z:

I can see why the processor would speculatively execute the code after
the `call`, because the `ret`s destination is predicted by the return
address predictor, but given that the prediction for this `ret` will
always fail, I'm surprised there isn't some meta-predictor that
kicks in.

The author also say that the XCHG is important because "if you try the
same with MOV or ADD at the callee site you’ll notice that it doesn’t
work anymore. Could just be the stall caused by the memory locking
implied by XCHG". Which suggests that the processor pays attention
to stack accesses that might invalidate the return address stack
predictor (and just happens not to do that effort for XCHG).

Does anyone know a bit more about what can be expected in terms of when
the return stack predictor is used and when it is not and/or when it is
invalidated?

Stefan

Re: Predicting RET misprediction

<79b660d1-4dd4-4e44-b221-fe13a437af3bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16759&group=comp.arch#16759

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:7f83:: with SMTP id z3mr34709440qtj.239.1621015159320;
Fri, 14 May 2021 10:59:19 -0700 (PDT)
X-Received: by 2002:aca:b387:: with SMTP id c129mr7412086oif.30.1621015159092;
Fri, 14 May 2021 10:59:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Fri, 14 May 2021 10:59:18 -0700 (PDT)
In-Reply-To: <jwvlf8h5pjd.fsf-monnier+comp.arch@gnu.org>
Injection-Info: google-groups.googlegroups.com; posting-host=104.59.204.55; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 104.59.204.55
References: <jwvlf8h5pjd.fsf-monnier+comp.arch@gnu.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <79b660d1-4dd4-4e44-b221-fe13a437af3bn@googlegroups.com>
Subject: Re: Predicting RET misprediction
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Fri, 14 May 2021 17:59:19 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: MitchAlsup - Fri, 14 May 2021 17:59 UTC

On Friday, May 14, 2021 at 10:37:33 AM UTC-5, Stefan Monnier wrote:
> There's an interesting hack described at:
>
> https://blog.can.ac/2021/03/22/speculating-x86-64-isa-with-one-weird-trick/
>
> where the author causes a misprediction in order to force the processor
> to "execute" arbitrary code safely (relying on the speculation mechanism
> to keep the code perfectly safe by undoing its effect (save for the
> impact on the internal event counters, which is presumably the only
> remaining traces of what happened)).
>
> The code he uses to trick the processor into executing code
> speculatively is the following:
>
> call x
> <speculated code>
> x:
> lea rax, [rip+z]
> xchg [rsp], rax
> ret
> z:
>
> I can see why the processor would speculatively execute the code after
> the `call`, because the `ret`s destination is predicted by the return
> address predictor, but given that the prediction for this `ret` will
> always fail, I'm surprised there isn't some meta-predictor that
> kicks in.
>
> The author also say that the XCHG is important because "if you try the
> same with MOV or ADD at the callee site you’ll notice that it doesn’t
> work anymore. Could just be the stall caused by the memory locking
> implied by XCHG". Which suggests that the processor pays attention
> to stack accesses that might invalidate the return address stack
> predictor (and just happens not to do that effort for XCHG).
>
> Does anyone know a bit more about what can be expected in terms of when
> the return stack predictor is used and when it is not and/or when it is
> invalidated?
<
I know back in the Opteron days that the Call Return Stack was a linked list of
return information. We kept it in linked list form* because RETs were speculated
and might have to be recovered and in this case we would downdate the pointers
recover the stack. There was no stack flushing, but if you got out of sequence
it would always mispredict and fall back on HW to recover.

(*) when a CALL was performed, we pushed a SCR entry on the stack using the
front of the CRS free pool and when we returned we pushed the free entry on the
back of the free pool so it had a chance of being recovered.

This was all done with 4-bit pointers which we wrote 8-bits at a time (->next and
->previous)
>
>
> Stefan

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor