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

OE/mbedTLS related memory allocation problems #825

Open
wants to merge 7 commits into
base: oe_port
Choose a base branch
from

Conversation

wintersteiger
Copy link
Contributor

While trying to extract attestation evidence (the endorsements part to be precise) via oe_get_evidence, OE calls mbedTLS functions, which in turn call calloc and not oe_calloc (here, where mbedtls_calloc == calloc). This ends up calling sgx-lkl-musl's calloc, which ultimately complains that there's no memory because it hasn't been initialized yet. I had hoped this problem would go away after the user/kernel-space separation, but it's still there. I suspect that there could be a solution in just reordering the libraries on the command-line, but I haven't had any luck so far. What's the recommended solution for this type of problem?

@davidchisnall
Copy link
Contributor

If this is from the OE version of mbedTLS, it sounds like an upstream bug, can we fix it there to define mbed_malloc as oe_malloc and similar?

@wintersteiger
Copy link
Contributor Author

That definition is in mbedTLS and there are lots of copies of #define mbedtls_calloc calloc all over their codebase. (Yes, OE's mbedTLS, but that makes no difference here.) Most of them seem to be guarded by #ifdef MBEDTLS_PLATFORM_C, which could potentially allow us to override the relevant function names, but I have no idea what other consequences that would entail.

@wintersteiger
Copy link
Contributor Author

Yeah, I think that's a viable solution, digging deeper.

@mikbras
Copy link
Collaborator

mikbras commented Sep 10, 2020

In the OE SDK, the mismatch is never a problem because oelibc forwards malloc to oe_malloc. But SGX-LKL replaces oelibc with its own version of libc in the kernel, which results in the mismatch.

Perhaps we can make oe_malloc (and friends) weak in OE, and define our own versions of these that call equivalent functions in libc.

@wintersteiger
Copy link
Contributor Author

@mikbras sure, that sounds like a good idea. I was able to work around my immediate problem with mbedTLS, but it would be great if we could get a more general solution to this.

Signed-off-by: Christoph M. Wintersteiger <[email protected]>
Signed-off-by: Christoph M. Wintersteiger <[email protected]>
Signed-off-by: Christoph M. Wintersteiger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants