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

Load of misaligned address in yh_util_import_wrapped() #414

Open
invd opened this issue Aug 20, 2024 · 6 comments
Open

Load of misaligned address in yh_util_import_wrapped() #414

invd opened this issue Aug 20, 2024 · 6 comments

Comments

@invd
Copy link

invd commented Aug 20, 2024

During fuzzing, I've found the following with -fsanitize=undefined:

runtime error: load of misaligned address 0x7b025caee261 for type 'uint16_t' (aka 'unsigned short'), which requires 2 byte alignment

at the code position in yh_util_import_wrapped():

*target_id = ntohs(*((uint16_t *) (response + 1)));

This is undefined behavior (UB) and therefore a bug.

yh_util_import_rsa_wrapped() appears to have a second instance of this pattern that is also triggered:

*target_id = ntohs(*((uint16_t *) (response + 1)));

@invd invd changed the title load of misaligned address in yh_util_import_wrapped() Load of misaligned address in yh_util_import_wrapped() Aug 21, 2024
@invd
Copy link
Author

invd commented Jan 4, 2025

@aveenismail @qpernil can you confirm this issue?

@aveenismail
Copy link
Member

@invd Apologies for the very late response. There is now a PR containing a fix for this issue.

#445

@aveenismail
Copy link
Member

I should probably explain more about #445:

The response data is now stored using pragma pack 1, so it will still be unaligned, but so are the responses to all other commands and elsewhere in the code. But since non of the other commands are triggering this error, using pragama pack 1 might be sufficient to solve you fuzzer issue.

Is this only a fuzzing issue or are you encountering this in your regular use?

@invd
Copy link
Author

invd commented Jan 8, 2025

@aveenismail I encountered this while fuzzing on an x86_64 system, with different compiler versions such as clang-16 and clang-20 (snapshot). Based on the code, I suspect the undefined behavior would also be present and detectable on corresponding builds with -fsanitize=undefined during actual use of the relevant functions.

I've also updated my fuzzer code to the newest commit 3dd15f3 and can confirm the issue is still present there, as observed in at least one variant.

@aveenismail
Copy link
Member

And it's triggered only in yh_util_import_wrapped() and yh_util_import_rsa_wrapped()? Not any other functions, say like import_key() or yh_util_sign_attestation_certificate() for example?

@qpernil
Copy link
Contributor

qpernil commented Jan 9, 2025

3dd15f3 is part of #444, not #445. Would you be able to test with the changes in #445 ? Also, this looks like a false positive to me, the x86 and x86_64 architectures can handle unaligned memory accesses fine. So can most ARM architectures, such as Apple Silicon. So it is a bit puzzling to me that you get this, for two reasons: The processor can handle unaligned; plus there are lots of other unaligned accesses that should also be flagged..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants