Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ubsan] load of misaligned address in ripple/ours/src/ripple/basics/SlabAllocator.h #4528

Closed
seelabs opened this issue May 18, 2023 · 0 comments · Fixed by #4531
Closed

[ubsan] load of misaligned address in ripple/ours/src/ripple/basics/SlabAllocator.h #4528

seelabs opened this issue May 18, 2023 · 0 comments · Fixed by #4531

Comments

@seelabs
Copy link
Collaborator

seelabs commented May 18, 2023

Issue Description

The undefined behavior sanitizer is reporting misaligned load and stores in the slab allocator.

Steps to Reproduce

Run the unit tests with the undefined behavior sanitizer (-Dsan=undefined)

Actual Result

The following runtime errors were reported in the SlabAllocator: (current branch: 629ed5c)

ripple/ours/src/ripple/basics/SlabAllocator.h:79:57: runtime error: store to misaligned address 0x7f91cdc002a4 for type 'uint8_t *', which requires 8 byte alignment
ripple/ours/src/ripple/basics/SlabAllocator.h:118:24: runtime error: load of misaligned address 0x7f91d03ffda4 for type 'uint8_t *', which requires 8 byte alignment
ripple/ours/src/ripple/basics/SlabAllocator.h:118:24: runtime error: load of misaligned address 0x7f91c5dff67c for type 'uint8_t *', which requires 8 byte alignment
ripple/ours/src/ripple/basics/SlabAllocator.h:139:52: runtime error: store to misaligned address 0x7f91c9bffbbc for type 'uint8_t *', which requires 8 byte alignment

seelabs added a commit to seelabs/rippled that referenced this issue May 22, 2023
Unaligned load and stores are supported by both intel and arm CPUs,
however, this is UB in C++. Replacing this with a `memcpy` fixes the
undefined behavior and the compiled assembly code is equivalent to the
original (so there is no penalty to using memcpy).
@intelliot intelliot linked a pull request May 24, 2023 that will close this issue
seelabs added a commit to seelabs/rippled that referenced this issue May 30, 2023
Unaligned load and stores are supported by both intel and arm CPUs,
however, this is UB in C++. Replacing this with a `memcpy` fixes the
undefined behavior and the compiled assembly code is equivalent to the
original (so there is no penalty to using memcpy).
intelliot pushed a commit that referenced this issue May 31, 2023
Misaligned load and store operations are supported by both Intel and ARM
CPUs. However, in C++, these operations are undefined behavior (UB).
Substituting these operations with a `memcpy` fixes this UB. The
compiled assembly code is equivalent to the original, so there is no
performance penalty to using memcpy.

For context: The unaligned load and store operations fixed here were
originally introduced in the slab allocator (#4218).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant