intel / linux-sgx

Intel SGX for Linux*
https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/linux-overview.html
Other
1.32k stars 543 forks source link

Including SGX headers causes wrong alignment of C standard library types #963

Open prandla opened 1 year ago

prandla commented 1 year ago

Some SGX headers include the file sgx_ecp_types.h. This file does #pragma pack(push, 1) and then includes sgx_tcrypto.h. That file includes stdlib.h, which will thus be included with the pragma pack still active. This will cause every struct defined in stdlib.h to have an alignment of 1. Notably, that includes pthread_mutex_t and pthread_cond_t, for which an alignment of 1 will cause errors.

As a more concerete example, the following assertion fails:

#include <sgx_dh.h>
#include <mutex>

static_assert(alignof(std::mutex) == 8);

while it passes when the sgx include is removed, or when the include order is swapped.

The fix for this would be to move the #pragma pack after the include. If it's also necessary for tcrypto.h types, it should be added to tcrypto.h separately, after any #includes.

llly commented 1 year ago

Thanks a lot. Will fix it