[mem] Implement HW support of ECC protection on main memory with byte access
ECC is preferred on main memory, but we also want to have byte-access. Options
- ECC on main memory, software does RMW to avoid byte accesses
- ECC on main memory, hardware does RMW on byte accesses
- parity on main memory, byte accesses are easy
Need software input on the cost of lowRISC/stwg-base#1
Needs to be option 2) or 3) for compliance with the RISC-V spec and with output of standard RISC-V toolchains (an optimising compiler targeting the standard RISC-V instruction set may narrow loads/stores to byte/half-word even if the C input didn't contain any char/short).
[Edit: the above obviously is obviously predicated on the assumption that we stick with a design with no caches]
I prefer option 2) if byte access is needed (and obviously it is needed). Parity seems to be okay but it needs a parity bit per byte, which makes the sram wrapper design a little bit complicated.
I would like to create two SRAM wrapper. One is current one (full datawidth write), and another is byte enabled sram wrapper, prim_sram_be_wrapper (which basically do RMW for byte write access). In RMW case, it won't affect CPU if it returns the completion right away and does RMW at back scene.
@eunchan would you only need the _be_wrapper if it had ECC and byte writes? what if we hold off on the ECC decision until we do some more evaluation? we could live with byte writes for today, then add parity or ECC upon further evaluation?
@eunchan https://github.com/eunchan would you only need the _be_wrapper if it had ECC and byte writes? what if we hold off on the ECC decision until we do some more evaluation? we could live with byte writes for today, then add parity or ECC upon further evaluation?
Sure. We can modify the design for ASIC later. I will assume no parity, SECDED for SRAM for now.
@cdgori
just wanted to check, do we envision ECC as something that would potentially increase the number of access cycles based on whether there is an error in the memory or not? I'm guessing no, but wanted to confirm.
@tjaychen I would assume no. It's generally better if all accesses take the same amount of time. Obviously this probably extends all memory latency by a clock cycle, which could be a perf issue in some cases where there actually is no security impact. Would propose we extend latency of no-error access path for main memory and see if it's a perf issue, then revisit. (Allowing different latency will require very detailed analysis of cases for potential issues.)
@eunchan @sjgitty I think we have NOT implemented ECC on main memory WITH byte access yet, correct? I'll remove the "Type: Question" tag as it seems we are settled on option 2. As an alternative to add'ing extra cycle of latency on no-error access, I think we should evaluate if we can do RMW with ECC calculation in a single cycle, to avoid the extra cycle of latency.
agreed on latency, but perhaps a larger topic is if we even want ECC. I don't personally think for countering glitching the conventional SECDEC is enough. If we are worried about cosmic rays...I don't really think for memory that's something we'd be terribly concerned about.
For non-volatile storage though, this might be a different story.
let's let this sit but deprioritize this to P3 and revisit if/when we have byte-memories with ECC needed.
SECDED will not counter glitching in many/most cases. But for some forms of "lossy" non-volatile storage you need SECDED (or some other correction code, the memory IP designer will dictate this) just to have good reads. It's particularly crucial for very "brittle" objects in the NV storage like symmetric keys (or asymmetric private keys), to the point where you might want multiple copies laid down just in case.
Hi Chris,
Thanks for the info.
What I understand is, it can happen that SRAM can lost more than 6 bits around a point if it is hit by a neutron particle. So, SECDED in this case is not enough definitely.
It, however, is related to the MTBF though. It depends on how much the silicon, more precisely, the SRAM portion can be hit in its life-cycle. More prevalent failure symptom is one bit failure due to incorrect power analysis, unstable power supply, how much the process node shrink down (I saw 2Xnm process without FF is quite fragile to this). So, personally, I didn't see any silicon adopts stronger than SECDED. Probably security industry may use stronger protections.
Also, other than the neutron particle issue, I think the OT silicon probably has a way to detect laser probing or something like that, which gives an option to erase the sensitive information.
On Thu, Oct 31, 2019 at 04:56:12PM +0000, Chris Gori wrote:
SECDED will not counter glitching in many/most cases. But for some forms of "lossy" non-volatile storage you need SECDED (or some other correction code, the memory IP designer will dictate this) just to have good reads. It's particularly crucial for very "brittle" objects in the NV storage like symmetric keys (or asymmetric private keys), to the point where you might want multiple copies laid down just in case.
i think specific to what Chris is saying, we will need to do something around non-volatile storage so we don't get non-security related bricks in the field. If someone actually laser glitches the OTP, and it causes the verification key to go crazy such that the device no longer boots.. that scenario might be out of scope.
For the SRAM cases, my opinion is that we need to have enough defense in the system such that we detect the attack directly (as you say), or that something else will detect that a piece of data / instruction is not quite right. But fully recovering from a faulty instruction I don't really think is necessary.
The issue I have seen is that the anti-fuses or other structures are just not 100% reliable, especially over the lifetime of the part, so various schemes/codes are applied to try to extract a reliable read of the programmed value over the expected life of the device (this is pretty well aligned with Eunchan's comment about MTBF). In order to know what you have to do, you need to talk to the people who designed the NVM macro. (Basic stuff you do: SECDED each copy (or row), use multiple copies with wired-AND/wired-OR type of redundancy as appropriate, cryptographic hash verifying a whole page/region. Next-level stuff: understand the physical layout of the macro and which parts are more robust for reading/programming & assign address locations based on that, use differential storage per bit if the circuit/storage topology permits this.)
Tim's comment is correct though, we just need to avoid non-security bricks (or false-security-event bricks), but if someone has actively glitched the part and it doesn't boot, so what? It's better if we know there's a glitch, trigger the alert and decide based on our current posture what is to be done. (More concrete examples of posture: detecting glitch during personalization process: give up immediately even if it ruins the part, the chance for "badness" is too high to try to recover. Detecting glitch during 3rd/4th-stage firmware load - it might even be ok to try to load&verify again if possible, otherwise just reset. Etc, etc.)
If you are trying to see if there was a glitch, you can just SHA the current "working state" (whatever you think that means at that point) and make sure it's matching the value you expect on each clock tick ;) - (that's only half-not-serious, if something is ultra critical and predictable, this is an approach I have seen used, though it is very painful to do). In that case, we would not have a "recovery" path per se, just a detection and probably go-to-reset-state type of situation.
Our job is a bit tricky here because it is hard/impossible to determine the difference between the naturally-occurring problems and the active fault attack situations. You'd like to recover from a single-bit error in most cases, but you'd like to lock out a determined glitch attack. (Also, remember that the "DED" part of SECDED can be overwhelmed by large numbers of bit-flips, as is considered pretty common in glitch attacks. So more serious/cryptographic checksumming becomes important if you want to know that something was glitched, since hash functions are much more robust against this type of attack, but also way more expensive computationally/latency-wise.)
On Fri, Nov 1, 2019 at 5:30 PM tjaychen [email protected] wrote:
i think specific to what Chris is saying, we will need to do something around non-volatile storage so we don't get non-security related bricks in the field. If someone actually laser glitches the OTP, and it causes the verification key to go crazy such that the device no longer boots.. that scenario might be out of scope.
For the SRAM cases, my opinion is that we need to have enough defense in the system such that we detect the attack directly (as you say), or that something else will detect that a piece of data / instruction is not quite right. But fully recovering from a faulty instruction I don't really think is necessary.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/76?email_source=notifications&email_token=AJBZS7CWBC7ZBQ22SYAD7SDQRTCZRA5CNFSM4ISTJY4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC4PGWI#issuecomment-548991833, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBZS7HM6RKVKUUTVGTOCQTQRTCZRANCNFSM4ISTJY4A .
@tjaychen @msfschaffner I think there has been some thinking on this issue recently, can you update this issue with the current status?
In terms of implementation, we now have prim_ram_1p_adv as a wrapper available for such functionality, and prim_ram_2p_adv as an example how to implement some of the ECC/Parity functionality, not yet considering write masks.
@imphil thanks Phil will do. Sorry I need to document the memory scrambling / ecc / parity discussion we did a couple of months ago.
I just have not gotten to it. It is in a way..somewhat on-hold because I am hoping to get some security lab guidance to make sure it is okay.
assign to myself to documentation purposes
@tjaychen no worries, we just got reminded of this one today when talking about the icache, but there's nothing blocked at the moment by this issue.
Not the solution, but an implementation step towards it, is in https://github.com/lowRISC/opentitan/pull/2418
Was thinking about this a bit in some other contexts, and it would be good if these DED checkers (and/or parity checkers) had a "easy" mechanism to fire an alert (pre-built alert sender?) since we could consider them like a form of glitch detector.
this issue is quite stale now.
Just for the sake of closure, we opted for scrambling + parity on the main sram.
This is because we determined that it was important for have a fast (single cycle) working memory for the processor, and the potential latency of ECC piling up, in the absence of something like a dcache (other security holes) just was not worth it.
I'm closing this now, if anyone objects, please feel free to re-open.