opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

RFC: Shadow Register

Open tjaychen opened this issue 7 years ago • 24 comments

Shadow Register RFC https://docs.google.com/document/d/1Oiv1ewvxhhk6c8aY2f2bV6tTZMI-zUlLeRZJMmXMBmo/edit?usp=sharing

I've formalized what was discussed into a document, please have a look.

tjaychen avatar Sep 11 '19 21:09 tjaychen

@tjaychen I am new to the topic. Could you please give an example where the use of such a shadow register is useful?

Would the use of a shadow register be to catch unexpected HW behavior or side effects during software development (e.g. a module generating different output than what was expected by software)?

vogelpi avatar Sep 13 '19 08:09 vogelpi

@vogelpi sorry for not responding sooner!

The main purpose of it would actually be to catch glitching attacks to critical register settings (so unexpected HW behavior).

For example if we had a memory region control where 0 represented no access, and all 1's representing varying levels of access, we want to avoid the case of someone being able to glitch it to a bad value without the device knowing.

tjaychen avatar Sep 19 '19 21:09 tjaychen

@eunchan or @tjaychen can you refresh this issue with the current thinking on shadow registers since we've made some progress there.

sjgitty avatar Jan 04 '20 00:01 sjgitty

We will need to figure out a way to bake this into the automated CSR testing framework, which I think should not be too difficult to achieve.

sriyerg avatar Jan 04 '20 00:01 sriyerg

The diagram below (thanks to @eunchan) represents the current thinking. We still need to solicit software feedback. Eunchan I can do that if you're busy with other things. Let me know.

Shadow Register

tjaychen avatar Jan 06 '20 18:01 tjaychen

and yes, to @sriyerg point, I don't think it will be difficult to add this to automated checks, it's more than we need to get sw onboard with the idea.

tjaychen avatar Jan 06 '20 18:01 tjaychen

How did you imagine using update_err and/or storage_err? Case-by-case basis depending on what is held in the regs? Or more generally to create an alert?

On Mon, Jan 6, 2020 at 10:27 AM tjaychen [email protected] wrote:

The diagram below (thanks to @eunchan https://github.com/eunchan) represents the current thinking. We still need to solicit software feedback. Eunchan I can do that if you're busy with other things. Let me know.

[image: Shadow Register] https://user-images.githubusercontent.com/1026250/71838998-09138a00-306f-11ea-87b8-fe0f2d12a340.jpg

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/150?email_source=notifications&email_token=AJBZS7AHYTPUQNWID4DKGC3Q4NZYJA5CNFSM4IVZEX52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIGKDGQ#issuecomment-571253146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBZS7AD6EIPKPNQR6XTI3LQ4NZYJANCNFSM4IVZEX5Q .

cdgori avatar Jan 06 '20 21:01 cdgori

The current thinking is that storage_err is terrible, and must generate an alert. update_err on the other hand, could be a software mistake, so that would be interrupt. Note an update_err should NOT mess up the current value of the storage, so I view that as "still safe".

What do you think?

On Mon, Jan 6, 2020 at 1:41 PM Chris Gori [email protected] wrote:

How did you imagine using update_err and/or storage_err? Case-by-case basis depending on what is held in the regs? Or more generally to create an alert?

On Mon, Jan 6, 2020 at 10:27 AM tjaychen [email protected] wrote:

The diagram below (thanks to @eunchan https://github.com/eunchan) represents the current thinking. We still need to solicit software feedback. Eunchan I can do that if you're busy with other things. Let me know.

[image: Shadow Register] < https://user-images.githubusercontent.com/1026250/71838998-09138a00-306f-11ea-87b8-fe0f2d12a340.jpg

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/lowRISC/opentitan/issues/150?email_source=notifications&email_token=AJBZS7AHYTPUQNWID4DKGC3Q4NZYJA5CNFSM4IVZEX52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIGKDGQ#issuecomment-571253146 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AJBZS7AD6EIPKPNQR6XTI3LQ4NZYJANCNFSM4IVZEX5Q

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/150?email_source=notifications&email_token=AAH2RSXD3HCS55KOQCOTAWDQ4OQRTA5CNFSM4IVZEX52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIG4FUY#issuecomment-571327187, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSRQQJYZVXFH5HLLTVTQ4OQRTANCNFSM4IVZEX5Q .

tjaychen avatar Jan 06 '20 21:01 tjaychen

Thanks @tjaychen and @eunchan for explaining visualizing the purpose. It sounds very reasonable and I think we need to have this in all security relevant IP cores.

vogelpi avatar Jan 08 '20 08:01 vogelpi

Apologies in advance for my lack of "design for security" knowledge. I took at look at this and had a few questions. Was unable to look at the RFC, but was able to see the register transfer diagram.

  1. Regarding the diagram, it was very clear except for the "phase" blob. Assuming this is handling a TLUL register write, it seems this needs to be a flop stage here also to sync up for the comparison, or more likely the register bus is expected to persist for the multi-cycle case, in which case I then understand it.
  2. What is the mindset for "invasive glitch technology" by the attacker? I would imagine that the glitch case is that any data line or any control signal can be flipped on any specific clock cycle, with a low probability that this can be repeated for the next clock cycle. Is this close to the mindset? If the glitch sequence can be repeated, this circuit will not detect the attack.
  3. The circuit then appears to be a counter measure to the above glitch case. My thought was that if the shown circuit works pretty good, then more stages in front of the committed register works even better - lowers vulnerability. If this is true, then the complaint would be extra silicon cost, to which I would think in the grand scheme would be trivial.
  4. I am not familiar with attack recovery, but it seems that both storage_err and update_err would be treated the same. Both would indicate that system is being attacked, with alerts being warranted, and yet both could be recovered by software by retrying the write.
  5. It seems logical that a sw read of the register that was just written would confirm the register being valid, without any special hw. Is it unrealistic to assume that sw will be written this way? Is sw considered more unreliable than hw? Most of these questions are probably for @tjaychen or @cdgori

mwbranstad avatar Jan 08 '20 15:01 mwbranstad

On Wed, Jan 08, 2020 at 07:15:52AM -0800, mwbranstad wrote:

Apologies in advance for my lack of "design for security" knowledge. I took at look at this and had a few questions. Was unable to look at the RFC, but was able to see the register transfer diagram.

  1. Regarding the diagram, it was very clear except for the "phase" blob. Assuming this is handling a TLUL register write, it seems this needs to be a flop stage here also to sync up for the comparison, or more likely the register bus is expected to persist for the multi-cycle case, in which case I then understand it.

phase signal is the output of prim_shadow internal state machine. You can assume phase as an indication of 1st write(value 0)/ 2nd write(value 1).

  1. What is the mindset for "invasive glitch technology" by the attacker? I would imagine that the glitch case is that any data line or any control signal can be flipped on any specific clock cycle, with a low probability that this can be repeated for the next clock cycle. Is this close to the mindset? If the glitch sequence can be repeated, this circuit will not detect the attack.

That's true (@tjaychen @cgori correct me if I am wrong). In order to avoid the detection in prim_shadow, glitch should happen at two consecutive clocks and also should happen at the exact same location, which is assumed very hard to achieve.

  1. The circuit then appears to be a counter measure to the above glitch case. My thought was that if the shown circuit works pretty good, then more stages in front of the committed register works even better - lowers vulnerability. If this is true, then the complaint would be extra silicon cost, to which I would think in the grand scheme would be trivial.

Right. We can have more protections by adding more stages. As you mentioned, it introduces more logic gate (current impl takes 3x more space than the normal MMIO reg). I think current approach is quite good to prevent the glitch attack.

  1. I am not familiar with attack recovery, but it seems that both storage_err and update_err would be treated the same. Both would indicate that system is being attacked, with alerts being warranted, and yet both could be recovered by software by retrying the write.

I assume storage_err is more serious issue, as the software cannot make sure the logic using this shadow register value is already corrupted or not when the software receives an alert. So, it makes more sense to hard reboot or shut-down the system.

In constrast, update_err doesn't mean the commited register value is changed. prim_shadow blocks an update to the committed register if update_err happens. In this case, this interrupt can be an indicator that the software may have a bug (only write once for security related registers). In production, this also can be treated as a security breach, if it is guaranteed that this part of the software clearly followed the two consecutive writes.

  1. It seems logical that a sw read of the register that was just written would confirm the register being valid, without any special hw. Is it unrealistic to assume that sw will be written this way? Is sw considered more unreliable than hw? Most of these questions are probably for @tjaychen or @cdgori

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/lowRISC/opentitan/issues/150#issuecomment-572115190

eunchan avatar Jan 08 '20 17:01 eunchan

Thanks @tjaychen and @eunchan for explaining visualizing the purpose. It sounds very reasonable and I think we need to have this in all security relevant IP cores.

@vogelpi do you see any way how a similar concept might be absorbed into PMP settings inside ibex? Really those registers are just as sensitive since they will perform a large part of the isolation function.. It may be that we cannot without breaking the spec, but we should really think about what we might do there as well.

tjaychen avatar Jan 08 '20 21:01 tjaychen

do you see any way how a similar concept might be absorbed into PMP settings inside ibex?

I am not sure but the only way in which the current proposal would violate the spec is that two successive writes to PMP registers would be needed for every change.

This could be avoided making some CSR instructions (e.g. those writing the PMPs) multicycle. The first cycle would update the staged register and the second the shadow + actual register. Unlike for data interface/LSU where the address and data is valid only during the first cycle (assuming an immediate handshake) CSR instructions use a different "protocol" where address and data remain valid as long as the instruction is executed. Further, address and data directly come out of the register file and instruction decode (I assume we will have additional counter measures there). To complicate the injection of faults, the instruction could even be made longer than two cycles or the data could be inverted in the first cycle (it should just be transparent to firmware).

As for the errors, storage errors would go into the alert handler. Update errors could trigger an illegal instruction exception (probably firmware would retry the update). WDYT?

vogelpi avatar Jan 13 '20 16:01 vogelpi

that sounds good to me! do you want to record this in the list of ibex security measures under consideration? we can then see how we feel this stacks up to other items.

I would say if that it is too difficult, maybe extending from one into two writes isn't 100% necessary, but we should definitely consider some way to sanity check the stored contents and fire an alert if needed.

tjaychen avatar Jan 13 '20 20:01 tjaychen

Thanks for your feedback @tjaychen , I added this to the mentioned document.

vogelpi avatar Jan 14 '20 14:01 vogelpi

About Ibex CSRs: If we're using a multi-cycle write instruction, it will be impossible for a firmware mistake to cause an update error, so I think (in Ibex) an update error should also cause an alert.

rswarbrick avatar May 04 '20 09:05 rswarbrick

Yep, I agree with @rswarbrick . An update error just also just cause an alert inside Ibex (and not just an exception) to keep it transparent for software.

vogelpi avatar May 04 '20 09:05 vogelpi

To all team: the Technical Committee (which has recently spun up, more news later) will be reviewing this RFC on 2020-06-03. Please refresh and record your thoughts on the proposal so that your opinions are registered in advance of that meeting.

sjgitty avatar May 28 '20 21:05 sjgitty

Things to do in DV:

  1. Detect a register is 'shadowed' (update reggen template and DV base register / field classes)
  2. Update DV base class write method to do double writes if shadowed, provide a knob to control it (to test update_err)
  3. Test: verify update on double writes (nothing extra needs to be done, existing CSR tests will handle this with (1) and (2)
  4. New test: verify original value with one write
  5. New test: verify update_err with mismatching writes [To verify storage_err]:
  6. Add support for backdoor CSR accesses
  7. If shadow register, add support for backdoor access to shadow reg and committed reg
  8. New test: randomly choose {shadow, committed} and cause a random bit-flip; verify the alert was generated

The new tests will be built such that they cater to all DUTs (including the full chip) containing shadowed registers. There are quite a few things to accomplish in DV, so the full verification of this feature will take a couple of weeks.

sriyerg avatar May 28 '20 22:05 sriyerg

An update from the Technical Committee. This RFC was deemed to be ready to move to the "approved" status. This indicates that it has had sufficient review to move from RFC proposal to implementation phase. (Clearly in the absence of the TC this has already occurred to some level, which is fine.) It does not mean that all of the technical details were signed off by the TC; those details will continue in the standard PR and review process. I will change the RFC label to Approved at this time.

sjgitty avatar Jun 03 '20 20:06 sjgitty