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

Add memory zeroizing when needed #239

Merged
merged 1 commit into from
Sep 4, 2020
Merged

Conversation

hug-dev
Copy link
Member

@hug-dev hug-dev commented Sep 1, 2020

Fix #122

@hug-dev hug-dev added the security Issues related to the security and privacy of the service label Sep 1, 2020
@hug-dev hug-dev self-assigned this Sep 1, 2020
@hug-dev hug-dev requested a review from ionut-arm September 1, 2020 17:34
@hug-dev hug-dev marked this pull request as ready for review September 1, 2020 17:34
@hug-dev
Copy link
Member Author

hug-dev commented Sep 1, 2020

Don't hesitate to tell if you think I have missed some data structures!

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off the top of my head I think at least ApplicationName should also be zeroized on drop

@@ -90,6 +90,7 @@ pub fn to_response_status(error: Error) -> ResponseStatus {
#[derive(Serialize, Deserialize)]
pub struct PasswordContext {
pub context: TpmsContext,
/// This value is confidential and needs to be zeroized by its new owner.
pub auth_value: Vec<u8>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be Secret, actually, or does it not work with serializing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, will try to change to it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it not work with serializing

I first tried to put the auth_value in a Secret but it did not work because there is no way to take the ownership out of a Secret and that is needed to build an Auth (through a TryFrom).

Then I thought it would be best to directly use the tss_esapi Auth structure there directly. But that structure does not implement Serialize, Deserialize so it does not work.

I think I will leave how it is right now but we maybe should put the Auth value in the tss crate as a Secret and use it directly from there? It could be done as part of parallaxsecond/rust-tss-esapi#46

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good!

@@ -284,6 +289,8 @@ impl TpmProviderBuilder {
.map_err(|_| {
std::io::Error::new(ErrorKind::InvalidData, "Invalid TCTI configuration string")
})?;
self.tcti.zeroize();
self.owner_hierarchy_auth.zeroize();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@@ -275,10 +276,17 @@ impl Drop for Pkcs11Provider {
if let Err(e) = self.backend.finalize() {
format_error!("Error when dropping the PKCS 11 provider", e);
}
// The other fields containing confidential information should implement zeroizing on drop.
self.slot_number.zeroize();
self.user_pin.zeroize();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this one should probs be stored as a Secret too, and any other variable that stores a password/PIN etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will modify those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added SecretString around the user_pin

@hug-dev
Copy link
Member Author

hug-dev commented Sep 1, 2020

I think at least ApplicationName should also be zeroized on drop

I thought about that but then realised that the application name itself is not really confidential (but the token itself is)? As in, do you think an attacker would benefit from knowing the application name?

Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
@ionut-arm
Copy link
Member

I think at least ApplicationName should also be zeroized on drop

I thought about that but then realised that the application name itself is not really confidential (but the token itself is)? As in, do you think an attacker would benefit from knowing the application name?

I guess it's only "confidential" in the case of DirectAuthentication, though it's still a data buffer so idk... Leave it as is, we can change it if we find something 😱 at some point

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, I think the only thing missing is the ServiceBuilder - for example the PKCS11 pin is passed as .with_user_pin(user_pin.clone())

@hug-dev
Copy link
Member Author

hug-dev commented Sep 2, 2020

I had a look at the code in the ServiceBuilder implementation and for user_pin and owner_hierarchy_auth:

  • they originally live in ProviderConfig which implements Zeroize on drop
  • when they are cloned they are either passed to a structure that will ultimately zeroize them or are zeroize before being cloned

Since ProviderConfig is directly the parsed structure of the config.toml I am not sure if we could use Secret there.

@hug-dev hug-dev merged commit 879da27 into parallaxsecond:master Sep 4, 2020
@hug-dev hug-dev deleted the memory branch September 4, 2020 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Issues related to the security and privacy of the service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory cleanup of sensitive data
2 participants