-
Notifications
You must be signed in to change notification settings - Fork 3
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
Document when tags are preserved when copying memory #12
Comments
This sounds good; three further thoughts:
|
A further note from the meeting earlier today: We should also be documenting whether memory-mapping APIs produce tag-enabled mappings, whether by default or as a result of additional flags/arguments/etc. For example, we probably want tags enabled for MAP_ANON mappings by default with mmap(2) (as is the case today), but System V shared memory mappings should not (but we probably want an option/flag to enable it). |
Tagging @bsdjhb @brooksdavis @arichardson @jrtc27. |
Attemping to answer one part of the question: struct s {
uint64_t a;
uint64_t b;
void * __capability c;
};
void init_from_other(struct s *dst, struct s *src)
{
memcpy(&dst->b, &src->b, sizeof(struct s) - offsetof(struct s, b));
} One could imagine a more restricted C implementation (e.g. with strict sub-object bounds) that didn't preserve tags with unaligned starts, but for existing systems code this probably must work. I think I've convinced myself that |
A lot of memcpy calls are emitted by the compiler (e.g. for assignments) and those would copy the entire object. For these cases it would make sense to emit a call to a memcpy variant that doesn't preserve tags on unaligned starts. |
@arichardson has done some work looking at compiler generated copies in the context of improved inlining (CTSRD-CHERI/llvm-project#506). We probably do want many of them to be tag-clearing, but de-facto C requires copying in all sorts of awkward places. For example:
requires a tag-preserving memcpy because we can't know what's actually being stored in |
We could try to make this distinction for C++20 (or maybe it's 17) code by only treating std::byte as potentially tag-bearing and assuming that char is actually a string. However, I feel this could be rather risky and it's safer to assume that all of |
As long as a |
By and large, the current approach used by CHERI LLVM is to preserve capability tags when copying memory if it is valid for the source to contain capabilities. While it is clearly the case in some situations (e.g. during a struct assignment if the struct contains capability types), this is not obvious in general.
It would be very helpful for the guide to document:
memcpy()
, struct assignment, implicit copy constructor, etc.).The text was updated successfully, but these errors were encountered: