Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[otbn] Check seed_valid bit of OTP scrambling interface #13201

Closed
vogelpi opened this issue Jun 14, 2022 · 9 comments · Fixed by #20688
Closed

[otbn] Check seed_valid bit of OTP scrambling interface #13201

vogelpi opened this issue Jun 14, 2022 · 9 comments · Fixed by #20688
Assignees
Labels
Component:RTL Earlgrey-PROD Candidate Temporary label to triage issues into Earlgrey-PROD Milestones Hotlist:Security Security Opinion Needed IP:otbn Priority:P2 Priority: medium triaged-security

Comments

@vogelpi
Copy link
Contributor

vogelpi commented Jun 14, 2022

@ctopal noted that inside OTBN, the seed_valid bit of the OTP scrambling interface is currently not used. We register the bit received from OTP but then don't do anything with it.

If that bit isn't set, it means OTP has used an all-zero constant to derive the scrambling key. Meaning the key is not really safe to use. My understanding is that the first OTBN secure wipe requesting new scrambling keys is anyway initialized after setting up the entropy complex, so this bit should always be set unless something fishy is going on. I suggest to change the OTBN design such that a recoverable error is triggered when receiving a scrambling key with seed_valid low.

Any thoughts @mundaym , @GregAC , @msfschaffner ?

@tjaychen
Copy link

I thought the seed valid was more related to whether a particular seed was burned and locked in the otp.
If that's the case, I don't necessarily think it has to be an error, because maybe during testing we have yet to setup otps yet.

it would make sense to indicate this as a status though, and perhaps instead of the default 0, some kind of random fixed constant that can be parameterized.

@GregAC
Copy link
Contributor

GregAC commented Jun 16, 2022

I think what @tjaychen suggests is most sensible. We may want to trigger the dmem/imem secure wipe when the bit is 0 for some testing/bring-up reason. Also all recoverable errors currently only occur during software execution. So a recoverable error during execution adds new error behaviour which adds more DV work which I'd rather avoid if at all possible.

@msfschaffner
Copy link
Contributor

So this bit was intended to provide some more info on provisioning status.
If the bit is zero, the key is still ephemeral and thus ok to use - but the seed to parameterize the KDF itself has not been provisioned yet and is thus set to zero.

I don't think we want to error on that, since we may (as @tjaychen pointed out) want to run some OTBN tests before the key seeds are provisioned.

It would however be good to expose this to SW via a CSR in a similar way as this has been done in the SRAM_CTRL so that SW could double check this:

{ bits: "4"
name: "SCR_KEY_SEED_VALID"
desc: '''
Set to 1 if the scrambling key has been derived from a valid key seed in OTP.
If !!STATUS.SCR_KEY_VALID is set to 1, !!STATUS.SCR_KEY_SEED_VALID should be 1
except for cases where the scrambling key seeds have not yet been provisioned to
OTP. In such a case, the scrambling key is still ephemeral (i.e., it is derived
using entropy from CSRNG), but a default all-zero value is used as the key seed.
''',
resval: 0,
}

@msfschaffner
Copy link
Contributor

msfschaffner commented Jun 22, 2022

@tjaychen I think the scrambling key is not set to zero inside OTBN in that case.
If we wanted to set the key seed to a random netlist constant, we would have to change that inside the OTP_CTRL KDI...

@msfschaffner msfschaffner added this to the Project: M3 milestone Sep 21, 2022
@GregAC GregAC added the Type:FutureRelease Not relevant to currently planned releases/milestones label Feb 24, 2023
@GregAC GregAC modified the milestones: Discrete: M3, Backlog Feb 24, 2023
@GregAC
Copy link
Contributor

GregAC commented Feb 24, 2023

I think the conclusion here it's there's no major security concern though exposing the seed valid to SW for OTBN could be useful, though I think we should only consider this for a future release @vogelpi any thoughts?

@GregAC GregAC added the Triaged label Feb 24, 2023
@msfschaffner msfschaffner added the Earlgrey-PROD Candidate Temporary label to triage issues into Earlgrey-PROD Milestones label Oct 6, 2023
@msfschaffner msfschaffner added the Hotlist:Security Security Opinion Needed label Nov 7, 2023
@msfschaffner msfschaffner modified the milestones: Backlog, Earlgrey-PROD.M3 Nov 7, 2023
@johannheyszl
Copy link
Contributor

@jadephilipoom PTAL: The current understanding is, that there is no security concern because either an OTP read or ephemeral seed is used for scrambling, but it might be useful for SW to understand if an ephemeral or OTP based seed is used. IMO this probably does not help much and we could close as not planned.

@johannheyszl johannheyszl added triaged-security and removed Milestone:D3 Type:FutureRelease Not relevant to currently planned releases/milestones labels Dec 12, 2023
@jadephilipoom
Copy link
Contributor

As currently written, OTBN drivers (for both silicon creator and cryptolib) always wipe IMEM/DMEM before loading any application to OTBN, so they would refresh the scrambling key before use anyway. I also don't see a security issue here.

@vogelpi
Copy link
Contributor Author

vogelpi commented Dec 19, 2023

Okay, thanks for your input everybody (and sorry for my ultra late response). I agree that there are no security concerns then. I agree that it's not necessary to change the RTL of either OTBN or OTP. In both cases it wouldn't add much.

But I do think we should add some notes to the OTP documentation on this (similar to what we have in the SRAM controller, namely that keys are still ephemeral). I'll take care of this.

@vogelpi vogelpi self-assigned this Dec 19, 2023
vogelpi added a commit to vogelpi/opentitan that referenced this issue Dec 20, 2023
In the past, there have been misunderstandings whether scrambling keys
having seed_valid = 0 are safe to be used at all. As it turns out, they
are. This commit adds this information to the interfaces section of the
otp_ctrl documentation.

This resolves lowRISC#13201.

Signed-off-by: Pirmin Vogel <[email protected]>
@vogelpi
Copy link
Contributor Author

vogelpi commented Dec 20, 2023

I just filed a PR to update the otp_ctrl documentation with the outcome of this discussion. See #20688.

vogelpi added a commit that referenced this issue Dec 21, 2023
In the past, there have been misunderstandings whether scrambling keys
having seed_valid = 0 are safe to be used at all. As it turns out, they
are. This commit adds this information to the interfaces section of the
otp_ctrl documentation.

This resolves #13201.

Signed-off-by: Pirmin Vogel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component:RTL Earlgrey-PROD Candidate Temporary label to triage issues into Earlgrey-PROD Milestones Hotlist:Security Security Opinion Needed IP:otbn Priority:P2 Priority: medium triaged-security
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants