On Tue, 2017-03-21 at 22:26 -0700, Jethro Beekman wrote:
In order to provide the ability to debug enclaves independently of
their
programming model, while supporting live attach (meaning the debugger
might not have seen enclave creation), a debugger needs to following
capabilities for a debugged process:
1) Identify enclaves
a) Given a page, identify it as an enclave page
b) Given an enclave page, find that enclave's base address
c) Given a particular enclave, find the TCSes
d) Given a particular enclave, get the attributes/miscselect
2) Read/write enclave memory
3) Find debugging symbols for enclaves
I think (1)(a) and (1)(b) can be done using /proc/[pid]/maps, but I'd
like confirmation. I think the following is true: If a page is in a
memory range that is listed as mapped from the sgx device, it is an
enclave page.
This will generally hold true for applications built with the Intel
SDK, but
there is nothing that prevents an application from holding onto memory mapped to
/dev/sgx without an associated enclave. Even with the Intel SDK there will be
(very small) windows where this isn't true, e.g. between mmap and ioctl to
create the enclave.
There might even be legitimate use cases where an application maps more memory
to /dev/sgx than it currently needs, e.g. an application that launches multiple
instances of an enclave on-demand might keep multiple unused mappings available.
From a memory range that is listed as mapped from the sgx
device, you can compute the enclave base address as (start-offset).
(1)(b) could be
especially problematic for applications that create multiple
enclaves, e.g. if several enclaves are contiguous in virtual memory.
(2) is supported already by the driver using the ptrace interface.
(1)(c) is necessary to find the SSAs and (1)(d) is necessary to
determine SSAFRAMESIZE and make sense of the data in the SSAs. What
would be the best way to expose this information? Best I can think of
currently is a dedicated file in /proc/[pid] where the driver exposes
this information which was originally provided at enclave creation time.
I like the idea of exposing a small amount of debug information in /proc/[pid],
even if some of the information could theoretically be derived from other
sources. This would also be a convenient location to dump statistics such as
EPC usage, a la /proc/[pid]/smaps.
I don't think (3) can universally be done without help from the user
program. Yes, it might be possible to learn something from ELF headers
but Linux does not generally have a requirement that user processes must
have valid ELF information in their memory mappings. Most current
userspace debug symbol loading is based on filenames. SGX does not
provide any record of where enclave memory came from. Perhaps the create
ioctl could include some user data that is later exposed again in the
same proc file mentioned above. Frameworks and toolchains could
establish a convention regarding this user data to find symbols.
Hmm, assuming we can't come up with a more clever method of providing additional
debug information, I would prefer adding a dedicated ioctl command over
expanding any of the existing commands. I don't think we want to pollute the
functional commands with debug information, especially since any information
would be completely optional (and unverifiable). This would also give the user
program some amount of flexibility over when the debug information is provided.
Because any debug information would be purely optional, the debug command struct
could also be designed in such a way that future versions could provide backward
compatibility, e.g. by defining reserved fields in the initial version.
--
Jethro Beekman | Fortanix
_______________________________________________
intel-sgx-kernel-dev mailing list
intel-sgx-kernel-dev(a)lists.01.org
https://lists.01.org/mailman/listinfo/intel-sgx-kernel-dev