Skip to content

HWAddressSantizer header needs a function to generate tags for end-users #73578

Open
@spectecjr

Description

@spectecjr

To simplify adding HWASan support to custom allocators, particularly on architectures which have specific requirements surrounding the implementation/type of tags, it would be useful if hwasan_interface.h had a function to generate a unique memory tag from a pointer (maybe XOR'd with the current CPU cycle counter value to reduce the chance of ABA errors/use after free).

The implementation might look something like the following pseudocode:

#if ARM
inline unsigned char __hwasan_generate_tag(const volatile void* x)
{
    // ARM64 MTE tags are only 4-bits
    // Use current CPU counter as an entropy-source.
    return (unsigned char)( (uint64_t)x  ^ READ_CYCLECOUNTER_INTRINSIC() ) & 0x0F;
}
#else
    return (unsigned char)( (uint64_t)x  ^ READ_CYCLECOUNTER_INTRINSIC() ) & 0xFF;
#endif

Adding this to the API would have the benefit of both satisfying any current or future hardware requirements portably and with forward compatibility, as well as reducing the confusion for new devs on how to generate a suitable tag. (Most devs for the existing API will probably shift and mask the lower bits of the pointer, which isn't a robust solution given the aforementioned issues).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions