Skip to content

Memtag ABI Extension to ELF violates idempotency requirement #399

Description

@EliaGeretto

The "ELF for the Arm® 64-bit Architecture (AArch64)" states that:

5.7.19 Idempotency
All RELA type relocations are idempotent. They may be reapplied to the place and the result will be the same. This allows a static linker to preserve > full relocation information for an image by converting all REL type relocations into RELA type relocations.

(https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#idempotency)

The extended R_AARCH64_RELATIVE, as defined in "Memtag ABI Extension to ELF", violates the idempotency principle because it uses the place P to store the tag offset. Once the relocation is performed the first time, that information is lost, so it cannot be reapplied:

ELF64 Code Name Base Operation MemtagABI Extended Operation
1027 R_AARCH64_RELATIVE Delta + A LDG(Delta + A + *P) - *P

(https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst#relocation-operations)

The interest in preserving the idempotency principle comes from baremetal targets. The only way to deploy memory tagging on a self-relocating target is relocating once with zero tags to perform the initialization required for virtual memory, apply the tags, and then relocate again with randomized tags. If the idempotency is not preserved, it is necessary store a copy of the tag offsets somewhere else and then reuse them.

Unfortunately, at a first glance, it seems impossible to preserve backwards compatibility when the tag offset is not zero, unless the tag offset is stored "off band". It seems that one bit of information would be enough to tell the loader to "fetch the tag from the previous 16 bytes granule", if end pointers are the only concern. However, this single bit of information can only be stored using a new relocation type given that both the addend field and the place cannot be touched to preserve backwards compatibility and idempotency.

It is worth noting that the "PAuth ABI Extension to ELF" has a similar issue, since it uses the place P to store the signature schema. The main difference with Memtag relocations is that PAuth introduces new relocations types, which provide more flexibility. The proposed workaround there is to ask the platform to decide whether to sacrifice either half the addend or idempotency, by storing the schema in P. See #398. This proposed workaround, however, does not address directly the issue of a PAuth relocation that also requires a tag offset (points to one off the end of a tagged object). One of the bits in the PAuth schema could be used for this. This should probably be addressed in one, or both, the documents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions