DynamoRIO / DynamoRIO/dynamorio

AARCHXX: Potential priv TLS layout issue

Open
#6,225 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
3.2k
Forks
629
Avg merge
2d 15h
Merged PRs (30d)
31

Description

During the porting of RISCV64, I found an issue with the private TLS layout on the AARCHXX side. But I'm not sure about this, so here is an issue for further discussion.

Namely, in [loader_linux.c#L343](https://github.com/DynamoRIO/dynamorio/blob/master/core/unix/loader_linux.c#L343) and [loader_linux.c#L400](https://github.com/DynamoRIO/dynamorio/blob/master/core/unix/loader_linux.c#L400), dr_tp calculation seems incorrect.

Similar to RISC-V, ARM/Aarch64 uses the Variant I TLS layout, while x86 uses Variant II.

![Variant I](https://github.com/DynamoRIO/dynamorio/assets/15257961/03504329-03ce-4fe1-8c27-09037814073b)

![Variant II](https://github.com/DynamoRIO/dynamorio/assets/15257961/7d12e539-de7c-43e5-95b9-defca0b7c049)
> https://www.uclibc.org/docs/tls.pdf

So for AARCHXX, at line 343, `dr_tp` should be calculated as: `dr_tp = dr_tp + TLS_PRE_TCB_SIZE;`, at line 400, should be: `dr_tp = dr_tp - TLS_PRE_TCB_SIZE;`.

For RISC-V, refer to https://github.com/DynamoRIO/dynamorio/pull/6147, at line 343, `dr_tp` should be calculated as: `dr_tp = dr_tp + TLS_PRE_TCB_SIZE + sizeof(tcb_head_t);`, at line 400, should be: `dr_tp = dr_tp - TLS_PRE_TCB_SIZE - sizeof(tcb_head_t);`. The RISC-V part will be submitted as a new PR once this issue is confirmed.

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.