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

cheribsdtest: Add tests in anticipation of c18n where function pointers are wrapped by default #2299

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

dpgao
Copy link
Contributor

@dpgao dpgao commented Jan 26, 2025

Add test for global integer variables containing function addresses.
Also increases the length of signal_returncap because c18n with default-wrapped trampolines requires that.

dpgao added 2 commits January 26, 2025 16:14
When library-based compartmentalisation causes every function pointer to
be wrapped in a trampoline, signal handlers return back to a trampoline
rather than sigcode. The length return address capability is thus
increased to account for this.
@dpgao dpgao requested a review from jrtc27 January 27, 2025 12:42
@@ -82,3 +84,20 @@ CHERIBSDTEST(fptr_canon_dlfunc,

cheribsdtest_success();
}

CHERIBSDTEST(fptr_canon_scalar,
"Check that function pointers are canonical when cast to scalar")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with LLD, please don't use the term scalar. A capability is still a scalar (contrast with a vector of capabilities).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this isn't about casting, this is about loading from memory where the value in memory is an integer address that's been relocated, rather than a pointer.

@@ -267,6 +267,8 @@ CHERIBSDTEST(signal_returncap,
CHERIBSDTEST_VERIFY2(v == CHERI_CAP_USER_CODE_LENGTH,
"length 0x%jx (expected <= 0x%jx)", v,
(uintmax_t)CHERI_CAP_USER_CODE_LENGTH);
#elif defined(CHERIBSD_C18N_TESTS)
CHERIBSDTEST_VERIFY2(v <= 0x300, "length 0x%jx (expected <= 0x300)", v);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, rather the PR’s title is a bit misleading.

* This function must only be referenced as a scalar.
*/
void
cheribsdtest_dynamic_dummy_func_scalar_only(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m aiming to test the ‘lazy-trampolines’ that come with default-wrapped function pointers. To do this you’d need to first resolve an integer address to the function, then resolve a capability, and make sure that a) they are equal and b) the latter is a tagged capability. (I haven’t actually tested (b) here because that would assume the existence of CHERI. To avoid using ifdefs maybe we can just call the function?)

The new function is needed to provide this ordering of symbol resolution.

{
}

ptraddr_t cheribsdtest_dynamic_dummy_func_scalar_address =
Copy link
Member

@jrtc27 jrtc27 Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we model this on cheribsdtest_dynamic_get_dummy_fptr and have it be a static local that's returned? That is:

ptraddr_t
cheribsdtest_dynamic_get_dummy_fptr_addr(void)
{
	static volatile ptraddr_t addr = (ptraddr_t)&cheribsdtest_dynamic_dummy_func;
	return (addr);
}

@dpgao dpgao changed the title cheribsdtest: Add tests for global function pointers that are cast to integers cheribsdtest: Add tests in anticipation of c18n where function pointers are wrapped by default Jan 28, 2025
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 this pull request may close these issues.

2 participants