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

Allocate DRBG additional data pool from non-secure memory #9423

Conversation

bernd-edlinger
Copy link
Member

@paulidale @mspncp how about this?

@bernd-edlinger bernd-edlinger added the branch: master Merge to master branch label Jul 20, 2019
@bernd-edlinger bernd-edlinger force-pushed the alloc_adin_pool_from_non_secure_mem branch 2 times, most recently from 9ce1491 to 50769dc Compare July 20, 2019 11:31
crypto/rand/drbg_lib.c Outdated Show resolved Hide resolved
crypto/rand/drbg_lib.c Show resolved Hide resolved
crypto/rand/rand_lib.c Outdated Show resolved Hide resolved
@paulidale
Copy link
Contributor

Definitely a step in the right direction.

@bernd-edlinger bernd-edlinger force-pushed the alloc_adin_pool_from_non_secure_mem branch from 50769dc to 1bf8253 Compare July 20, 2019 11:53
Copy link
Contributor

@mspncp mspncp left a comment

Choose a reason for hiding this comment

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

First impression is good. Only one remark and one question.

  • Your commit message definitely deserves more text ;-)
  • Is there a particular reason why you go from one extreme (secure memory) to the other (no cleaning at all)? I'd prefer if you would keep the cleaning.

crypto/rand/drbg_lib.c Outdated Show resolved Hide resolved
crypto/rand/rand_lib.c Outdated Show resolved Hide resolved
crypto/rand/rand_lib.c Outdated Show resolved Hide resolved
crypto/rand/rand_lib.c Outdated Show resolved Hide resolved
crypto/rand/rand_lib.c Outdated Show resolved Hide resolved
crypto/rand/drbg_lib.c Show resolved Hide resolved
@bernd-edlinger
Copy link
Member Author

No real reason, but it is odd that the non-initialized memory causes a msan failure.
The idea was that the memory shall be initialized by the entropy that is added, not
by a memset, but the memset can easily hide a bug from valgrind.
In the moment it looks like a compiler-bug.

@bernd-edlinger bernd-edlinger force-pushed the alloc_adin_pool_from_non_secure_mem branch from 1bf8253 to dbf2013 Compare July 20, 2019 13:42
@bernd-edlinger bernd-edlinger force-pushed the alloc_adin_pool_from_non_secure_mem branch 2 times, most recently from 301c7a5 to cc00073 Compare July 20, 2019 14:24
The additional data allocates 12K per DRBG instance in the
secure memory, which is not necessary. Also nonces are not
considered secret.

[extended tests]
@bernd-edlinger bernd-edlinger force-pushed the alloc_adin_pool_from_non_secure_mem branch from cc00073 to efa4add Compare July 20, 2019 14:55
@bernd-edlinger
Copy link
Member Author

Reverted the test code, and zeroized the additional data pool as before.
It is a bit odd that msan raises bogus errors and forces unnecessary initializing.

@mspncp
Copy link
Contributor

mspncp commented Jul 21, 2019

Reverted the test code, and zeroized the additional data pool as before.

From the security perspective, only the erasing of the buffer before freeing it is important. If you prefer malloc to zalloc for performance reasons, and if you manage to fix the asan complaint, I won't mind.

@bernd-edlinger
Copy link
Member Author

Unfortunately I was not able to fix the memory sanitizer at this time,
valgrind did not agree and did never print any warnings at all.

@paulidale
Copy link
Contributor

Did anything come of the suggestion to use the entropy argument to determine secure storage or not?

@bernd-edlinger
Copy link
Member Author

Yes, it still makes sense in case DRBG is created with RAND_DRBG_new:
#9423 (comment)

@bernd-edlinger
Copy link
Member Author

However we agreed, that the public DRBG will not use non-secure memory.

@paulidale
Copy link
Contributor

Thanks for the link. I had to rush through too much today and missed the outcome :(

I agree that the DRBG should be in secure memory in addition to the entropy.

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

I'm assuming that the Travis failures aren't relevant (they didn't appear to be).

@mspncp
Copy link
Contributor

mspncp commented Jul 22, 2019

Did anything come of the suggestion to use the entropy argument to determine secure storage or not?

I agree with @bernd-edlinger. I wasn't aware anymore that we have now two flavors of DRBG: a secure one and an insecure one.

RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent)
{
return RAND_DRBG_new_ex(NULL, type, flags, parent);
}
RAND_DRBG *RAND_DRBG_secure_new_ex(OPENSSL_CTX *ctx, int type,
unsigned int flags, RAND_DRBG *parent)
{
return rand_drbg_new(ctx, 1, type, flags, parent);
}

(In fact, it was me who added the functions in 4f9dabb, but it was only during code cleanup, so I did not really introduce the two flavors.)

So to be consistent, the secure flag should be inherited from the DRBG to its pool, agreed?

@bernd-edlinger
Copy link
Member Author

@mspncp are your concerns resolved ?
If yes, I can go ahead and merge this in the afternoon, so @paulidale can continue with his PR.

@@ -149,7 +149,7 @@ size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
pool = drbg->seed_pool;
pool->entropy_requested = entropy;
} else {
pool = rand_pool_new(entropy, min_len, max_len);
pool = rand_pool_new(entropy, drbg->secure, min_len, max_len);
Copy link
Member Author

Choose a reason for hiding this comment

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

So to be consistent, the secure flag should be inherited from the DRBG to its pool, agreed?

Yes. That happens here.

Copy link
Contributor

@mspncp mspncp left a comment

Choose a reason for hiding this comment

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

Looks good to me now. In particular the locations which I marked explicitly.

@@ -110,7 +110,7 @@ size_t rand_crngt_get_entropy(RAND_DRBG *drbg,
if (crngt_glob == NULL)
return 0;

if ((pool = rand_pool_new(entropy, min_len, max_len)) == NULL)
if ((pool = rand_pool_new(entropy, 1, min_len, max_len)) == NULL)
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

@@ -149,7 +149,7 @@ size_t rand_drbg_get_entropy(RAND_DRBG *drbg,
pool = drbg->seed_pool;
pool->entropy_requested = entropy;
} else {
pool = rand_pool_new(entropy, min_len, max_len);
pool = rand_pool_new(entropy, drbg->secure, min_len, max_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

LTGM

@@ -331,7 +335,7 @@ int RAND_poll(void)
RAND_POOL *pool = NULL;

/* fill random pool and seed the current legacy RNG */
pool = rand_pool_new(RAND_DRBG_STRENGTH,
pool = rand_pool_new(RAND_DRBG_STRENGTH, 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

@bernd-edlinger
Copy link
Member Author

Merged as 1372560. Thanks!

levitte pushed a commit that referenced this pull request Jul 22, 2019
The additional data allocates 12K per DRBG instance in the
secure memory, which is not necessary. Also nonces are not
considered secret.

[extended tests]

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #9423)
@paulidale
Copy link
Contributor

I agree with @bernd-edlinger. I wasn't aware anymore that we have now two flavors of DRBG: a secure one and an insecure one.

I hadn't noticed either. I'm having difficulty thinking of a plausible use case for a non-secure DRBG. Random numbers are fundamental to security and need to be produced in the safest manner possible. Being able to predict future output would be very bad.

I feel that the internal state should always be in secure memory as should the entropy input. I can live with the other inputs not being in secure memory (although it could be argued that the additional input is a kind of weak entropy).

Anyway, this might be for another PR.

@bernd-edlinger
Copy link
Member Author

Was there something with the deterministic ecdsa signature, where a drbg would
be fed with predictable input and produces the deteministic R for the ECDSA?

@paulidale
Copy link
Contributor

Yes, it reuses one of the DRBG constructions.
The reference escapes me at present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants