Is there something I am missing?
Such that a value can appear in a register that is inconsistent with the branch state that was resolved?
I like the idea of a small fully associative L0 cache for the results of speculated loads such that cache line eviction (cache side-effects) for speculated ops only happen / become visible during retirement, just like register side effects. It’s only necessary to use this L0 for loads after unresolved branches until the point that the branch is resolved i.e. a place to hide the results of mis-predicted loads.Is that possible?
--
You received this message because you are subscribed to a topic in the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/a/groups.riscv.org/d/topic/isa-dev/8ejNKIqFChw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to isa-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/3350FE55-388A-4199-A6E5-F9C6B8862DCF%40mac.com.
I posted a proposal on the FreeBSD lists, which suggests a
countermeasure of keeping sensitive information in non-cacheable memory.
This should defeat the meltdown attack, and should repel the spectre
attack with very high probability. Obviously, this only works if you
correctly store sensitive information in these non-cacheable pages.
The real thing this technique is accomplishing (rather crudely, but I
have to work with what's there) is to prevent certain memory locations
from being used in speculative execution. A better way would be to do
this directly: mark pages as "sensitive" which ends up making its way
into the pipeline as a flag on registers. Then, no operation on any
sensitive value gets launched until it's guaranteed to commit.
--
You received this message because you are subscribed to a topic in the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/a/groups.riscv.org/d/topic/isa-dev/8ejNKIqFChw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/CA%2B%2Bfp8yDHcDHBTUoyfK99qRDKHxQ1o9SSH3LcZziDy-dp2oKaA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/5A501DA4.8080209%40gmail.com.
Jonas Oberhauser wrote:
To be honest I understand only for the DRAM selection state and the branch predictor why they are really bad. For the others the window of attack seems to be too small to do anything useful. Is that assumption wrong?
The correctness of that assumption will depend on microarchitectural details, such as maximum speculation depth. Speculating that Intel processors have the greatest maximum speculation depth is reasonable and would explain the observation that Intel processors are much more severely affected.
Such a remote operation would need to cause all speculation past that load to be abandoned.If all we had to do was prevent effects to the cache, one could speculatively load only in case
1) nothing will be evicted (no cache contention)
2) no other cache will need to make a transition
3) the loaded data is clean
LRs are different; speculative LRs that lock a cacheline can be timed by an attacker.
If a remote operation is observed that will invalidate condition 3) while still speculating, one needs to abort and retry (or wait for the speculation to complete).
Also, any cachelines speculatively loaded would need to be invalidated if speculation is abandoned.
This could require several additional columns in the cache to store a "speculation checkpoint" number, to allow partial invalidation of speculated execution, analogous to transaction savepoints in PostgreSQL.
Limiting speculative loads to data already cached could be an interesting option and meets your condition (1) by definition.I guess the branch predictor can ignore speculative training data (only train at retirement), and if one never speculatively loads from DRAM, that problem can also be avoided.
I believe that you are mistaken about interrupts in RISC-V: an interrupt causes some instruction to take an interrupt exception and trap. The interrupt trap (as "move pc to ?epc") can be inserted into the decoded instruction stream ahead of (almost) any instruction and the fetch unit repointed to *tvec. (I say almost any because some implementations might choose to hold off interrupts in LR/SC sequences.) The "interrupted" instruction is not executed at all. Which instruction takes the exception is unspecified, so as long as the "trap marker" appears correctly in the fetched instruction stream, the fetch unit can simply start fetching from the address in *tvec some time after the interrupt arrives.The difficulty of course lies in the fact that these may be things that happen very often, making the performance penalty unbearable. Every instruction speculates on not being interrupted, and you typically want to fetch before resolving that speculation.
In high-performance (=low-latency) systems, some interrupt timing will effectively leak all the way to user space and may provide side channels associated with storage hardware, for example. On the other hand, interrupt timing is or has been a source of entropy for the Linux RNG, so at least the Linux devs seem to expect interrupts to be random. If interrupts can be made predictable by an attacker, poisoning the state of the Linux kernel RNG to cause predicatble keys to be generated might be possible.I still hope HW interrupts (/IPIs) are not a problem because they are too unpredictable, or at least can be made somewhat unpredictable, or at least that attackers can not normally exploit those interrupts (e.g., time them). I don't know if that hope is realistic.
Jonas Oberhauser wrote:I would add that speculative execution should end at this point -- once any speculated instructions have been canceled, it is certain that a wrong path has been taken somewhere.
If all we had to do was prevent effects to the cache, one
could speculatively load only in case
1) nothing will be evicted (no cache contention)
2) no other cache will need to make a transition
3) the loaded data is clean
LRs are different; speculative LRs that lock a cacheline can
be timed by an attacker.
If a remote operation is observed that will invalidate
condition 3) while still speculating, one needs to abort and
retry (or wait for the speculation to complete).
Such a remote operation would need to cause all speculation past
that load to be abandoned.
Yes, what I meant by abort was even more severe -- retry the whole speculative sequence. You are right that only that load needs to be retried.
The reason for not making a speculation abort all or nothing is that some of the speculated instructions might still be able to commit.Hm, I didn't think about that -- I thought it would be an all or nothing, but you're right, if a nested inner speculation/speculative load is detected as incorrect first, only those loads have to be invalidated.
Right now the best we can do is discuss and find ideas that can be evaluated using models or maybe even actual hardware.
Yes, and I think you (or someome else) suggested something like it before. I'm just not sure what the performance penalty is, so I'm trying to carve out as much space as possible.
Jonas Oberhauser wrote:
Interrupts have latency, so the processor can simply decide that the interrupt applies to the Nth instruction from now and take the interrupt trap then.
It's possible that I misunderstood something or used the wrong term but generally speaking in HW, many interrupts cause speculative instruction fetch, e.g., in a pipeline, an interrupt can not be detected in the early stages, but to avoid bubbles, one already fetches from pc, pc+4, pc+8, ... This has an effect on the cache, even if at a later stage the interrupt is detected and those instructions architecturally speaking never have been fetched.
This is distinct from synchronous exceptions that are expected to cause precise traps. (user ISA section 1.3 "Exceptions, Traps, and Interrupts") Synchronous exceptions will require flushing the pipeline, since execution must resume at the trap handler instead of continuing after the instruction that raised the exception. On the other hand, since ECALL *always* raises an exception, an implementation *can* speculate through ECALL and into the trap handler. (Is it really speculation if it is always correct?)
Generally, RISC-V instructions fall into three categories:
(1) Always raises exception: ECALL, EBREAK, illegal instructions
(2) Never raises exception: RVI computational instructions
(3) Conditionally raises exception: memory access, privileged instructions
Note that control transfer instructions can be either (2) or (3) depending on the implementation -- while instruction misalignment and instruction access faults are possible, whether they occur (microarchitecturally speaking) at JAL/JALR or on the following instruction fetch is left to the implementation. (My reading of the user ISA spec suggests that *epc must point to the offending JAL/JALR for instruction misalignment faults, but microarchitectures can achieve that by adjusting the generated link value after the fact.)
I think that this is a different type of side channel. How is speculative execution part of this attack?
Now using an indirect branch with some register R, one can read out the value of R (e.g., by timing instruction fetches, or by sharing the cachelines in a data cache and observing state changes). If one manages to put a secret value into R before the indirect branch, the attack is complete.
The Spectre indirect branch poisoning attack causes the processor to assume an attacker-controlled value for R and speculate execution from that address. The speculative execution is canceled when the processor later gets the real value for R. (Presumably, R is loaded from memory just before the indirect jump that uses R.)
You seem to be confusing terms -- RISC-V does not have exact interrupts, but _exceptions_ are expected to be exact and are expected to cause _precise_ traps. Which instruction gets a pending interrupt exception is not specified, however.
This is definitely true for exact SW interrupts. I now realize HW interrupts can avoid this speculation by draining the pipe. I was under the impression that RISCV has some exact SW interrupts, but I may be wrong.
For software interrupts in RISC-V, the ?SIP bit can be set, and an interrupt occurs at some unspecified future time. Hardware can, of course, make that future time convenient, for example, after "runahead fetch" has retrieved the first cacheline of the trap handler. (Or initiate fetching the trap handler and continue non-speculative execution until either (1) an I-cache miss or (2) the first cacheline of the trap handler is ready. In case (1), stall and wait for (2). In case (2), take the interrupt trap.)
Fortunately, in RISC-V, the major opcode (for 32-bit instructions) is sufficient to sort an instruction into category (1)/(2)/(3) and the memory access instructions are all in one corner of the opcode table.
The problem is that early on in the pipeline it is often impossible to tell whether the instruction may be of a type that traps or not, so you might potentially have to delay speculative instruction fetch from DRAM after every instruction. That sounds really bad.
How can speculative instruction fetch itself leak data? Instruction fetch is linear and therefore completely predictable in the absence of control-transfer instructions. Program code is assumed to be known to the attacker, so what can leak?Maybe these attacks are not possible in practice because nobody has such code where an instruction might trap right before an indirect branch in just the right configuration, but I would not count on it.
Jonas Oberhauser wrote:Those are not my terms: they are from the RISC-V ISA spec. These particular nuances of "exception", "interrupt", and "trap" should probably be considered unique to RISC-V, although the ISA spec mentions in commentary that "exception" and "trap" align with IEEE-754.
Thanks for the detailed explanation and disambiguation of the terms.
I guess what I meant then (in the terms you use above) is any exception, not just an interrupt.
Now using an indirect branch with some register R, one can
read out the value of R (e.g., by timing instruction fetches,
or by sharing the cachelines in a data cache and observing
state changes). If one manages to put a secret value into R
before the indirect branch, the attack is complete.
I think that this is a different type of side channel. How is
speculative execution part of this attack?
HW fetched and executed the indirect branch (by that I mean: fetched the jumped-to instruction), which has to be rolled back because an earlier instruction had an exception which was not detected when executing the indirect branch.
This is not one of the published Spectre attacks, then, but possibly something new. ("Fun"... the second time in this thread a possible attack has been found "near" the recently-published attacks.)
In this case, the indirect branch target is known non-speculatively, but the indirect branch itself is in the "shadow" of something that prevents it from actually being executed (either a Meltdown-like delayed exception or a mispredicted conditional branch). This could be an "if (object->flags.use_vtable) { object->ops->some_method(...) } else { global_version_of_some_method(...) }" construction, but that would be very strange code and could only leak whatever the slot in whatever replaces "ops" in objects that lack local method tables actually holds.
Or is this another means to exploit the indirect branch poisoning attack: cause the hardware to speculate an indirect jump destination that points to another indirect jump that uses the register that happens to contain a sensitive value.
Of course, odds are that the sensitive value will not point to an executable page, so forbidding speculation past an access violation kills this attack dead except for leaking valid control flow.
(Presumably, a PTE walk that results in a page fault does not affect the TLB state.)
The Spectre indirect branch poisoning attack causes the processor
to assume an attacker-controlled value for R and speculate
execution from that address. The speculative execution is
canceled when the processor later gets the real value for R. (Presumably, R is loaded from memory just before the indirect jump
that uses R.)
No, the attacker controls the exception, not R. HW speculates that no exception is taken and loads R and fetches from the cacheline pointed to by R. The exception is later detected and the branch discarded.
Now the attacker measures which cacheline was fetched from by the indirect branch, thereby deducing the content of R.
I still see no way for an attacker to gain from this. The attacker gets the contents of R, I grant, but R must be a valid code pointer, since the attacked program jumps to it (and does not crash in the case where the attacker has not arranged an unexpected diversion of control flow). Assuming the attacker knows the attacked program code, how does this leak anything useful? It only breaks ASLR if the attacker already has access to the attacked program's address space, to observe which cacheline was fetched.
Yes, going forward, BTBs will have to be flushed or tagged to prevent an attacker training a victim's predictor. That by itself mitigates any Spectre attack, save the scenario where the attacker is the victim (e.g., a sandboxed JIT running with supervisor permissions)
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/CAFAhBRnmPyPrYtZDMinb4fQ6tYmm_qR5sijxaBxTrMpEDv%2BtTw%40mail.gmail.com.
At 8:56 PM -0800 1/7/18, Christopher Celio wrote:
>Yes, going forward, BTBs will have to be flushed or tagged to prevent an attacker training a victim's predictor. That by itself mitigates any Spectre attack, save the scenario where the attacker is the victim (e.g., a sandboxed JIT running with supervisor permissions).
Or we need to mark changes to BTB entries as themselves speculative and be able to roll them back?
>
>-Chris
>
>
>
>
>> On Jan 7, 2018, at 8:49 PM, Jacob Bachmeyer <jcb6...@gmail.com> wrote:
>>
>> Christopher Celio wrote:
>>> Many high-performance processors use a Branch Target Buffer to predict the instruction type well before decode has occurred. You can even let the Fetch Unit feed its own predictions into itself, fetching instructions entirely on its own, never actually seeing the instruction bits it is fetching.
>>>
>>
>> Perhaps speculating instruction decode is simply going too far? Or at least, we need to ensure that the Branch Target Buffer is partitioned along hardware-enforced security boundaries, so that process A cannot influence predictions in process B, otherwise Jonas Oberhauser's indirect branch target leak may prove to be quite useful after all -- and prove to not actually require an indirect branch at the targeted location in the target process. (*OUCH!*)
>>
>> I have a vague outline of such an attack, where an attacker influences branch prediction of "phantom" branches to alter the timing of another VM in a cloud. If the attacker can trick the branch predictor to use the register of the attacker's choice instead of an actual instruction in the target, the speculated branch could leak sensitive information after all. The primary mitigating factor I see in that attack is that the indirect branch target leaked must be part of the target's normal control flow... but if the "leaky" branch does not have to actually exist in the target, that no longer applies.
>>
>>
>> -- Jacob
>
>--
>You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+unsubscribe@groups.riscv.org.
>To post to this group, send email to isa...@groups.riscv.org.
>Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
-Capacity to use some bits in the address space to mark the "domain" in which the application runs. This is more for single address space protection.Currently, the CPU has no way to know if the code in thread one should not leak to thread two.
-The 2nd thing that we may want to consider is to decrease the quality of the timers at user mode as a way to mitigate timing changes detection.This paper talks about "fuzzy" time as a way to mitigate (not solve, but mitigate)
On Monday, January 8, 2018 at 1:11:01 PM UTC-6, Jose Renau wrote:-Capacity to use some bits in the address space to mark the "domain" in which the application runs. This is more for single address space protection.Currently, the CPU has no way to know if the code in thread one should not leak to thread two.Seems easier to just use ASID?
-The 2nd thing that we may want to consider is to decrease the quality of the timers at user mode as a way to mitigate timing changes detection.This paper talks about "fuzzy" time as a way to mitigate (not solve, but mitigate)The attacker can just use software-timed loops. As stated before, it doesn't have to work all the time since you can repeat the attack many times.
At 8:56 PM -0800 1/7/18, Christopher Celio wrote:
>Yes, going forward, BTBs will have to be flushed or tagged to prevent an attacker training a victim's predictor. That by itself mitigates any Spectre attack, save the scenario where the attacker is the victim (e.g., a sandboxed JIT running with supervisor permissions).
Or we need to mark changes to BTB entries as themselves speculative and be able to roll them back?
>
>-Chris
>
>
>
>
>> On Jan 7, 2018, at 8:49 PM, Jacob Bachmeyer <jcb6...@gmail.com> wrote:
>>
>> Christopher Celio wrote:
>>> Many high-performance processors use a Branch Target Buffer to predict the instruction type well before decode has occurred. You can even let the Fetch Unit feed its own predictions into itself, fetching instructions entirely on its own, never actually seeing the instruction bits it is fetching.
>>>
>>
>> Perhaps speculating instruction decode is simply going too far? Or at least, we need to ensure that the Branch Target Buffer is partitioned along hardware-enforced security boundaries, so that process A cannot influence predictions in process B, otherwise Jonas Oberhauser's indirect branch target leak may prove to be quite useful after all -- and prove to not actually require an indirect branch at the targeted location in the target process. (*OUCH!*)
>>
>> I have a vague outline of such an attack, where an attacker influences branch prediction of "phantom" branches to alter the timing of another VM in a cloud. If the attacker can trick the branch predictor to use the register of the attacker's choice instead of an actual instruction in the target, the speculated branch could leak sensitive information after all. The primary mitigating factor I see in that attack is that the indirect branch target leaked must be part of the target's normal control flow... but if the "leaky" branch does not have to actually exist in the target, that no longer applies.
>>
>>
>> -- Jacob
>
>--
>You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+unsubscribe@groups.riscv.org.
>To post to this group, send email to isa...@groups.riscv.org.
>Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
>To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/4AF2D83D-7C4F-41E8-9218-AB5736B91E82%40eecs.berkeley.edu.
--
**************************************************
* Allen Baum tel. (908)BIT-BAUM *
* 248-2286 *
**************************************************
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/p06240813d67a0a9e77aa%40%5B192.168.1.50%5D.