intel / intel/confidential-computing.sgx.sdk

Including SGX headers causes wrong alignment of C standard library types

Open
#136 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
2
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Some SGX headers include the file [sgx_ecp_types.h](https://github.com/intel/linux-sgx/blob/a1eeccba5a72b3b9b342569d2cc469ece106d3e9/common/inc/sgx_ecp_types.h#L39). This file does `#pragma pack(push, 1)` and then includes [sgx_tcrypto.h](https://github.com/intel/linux-sgx/blob/a1eeccba5a72b3b9b342569d2cc469ece106d3e9/common/inc/sgx_tcrypto.h#L45). 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:
```c++
#include
#include

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 `#include`s.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.