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

[PAL] Fix memory PAL regression test for UBSan #2003

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pal/regression/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,22 @@ static void memfault_handler(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* contex
PalProcessExit(1);
}

/* Disable AddressSanitizer: this code tries to trigger a memory fault by accessing memory that's
* supposed to be inaccessible, but SGX PAL poisons such memory. */
/*
* Disable AddressSanitizer: this code tries to trigger a memory fault by accessing memory that's
* supposed to be inaccessible, but SGX PAL poisons such memory.
*
* Also disable UndefinedBehaviorSanitizer's complaint about "Indirect call of a function through a
* function pointer of the wrong type". UBSan expects all functions which can be indirectly called
* to be instrumented with two magic metadata values, located right-before the function in address
* space. The below code does *not* add metadata (it simply allocates some pages and copies machine
* code at the beginning of the first page). Instead of adding UBSan-required metadata, we simply
* disable this particular check (it's a test after all, not core Gramine functionality). For more
* info, see https://maskray.me/blog/2022-12-18-control-flow-integrity#fsanitizefunction.
*/
__attribute_no_sanitize_address
#ifdef UBSAN
__attribute__((no_sanitize("function")))
#endif
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
Expand Down