-
Notifications
You must be signed in to change notification settings - Fork 30
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
Can the pointer alignment situation be improved? #23
Comments
My planned resolution to this, in the fullness of time, is to put each But, I have been putting off re-engineering Abomonation for safety until I learned more about safety from the UB group (essentially: to learn if a safe version would be possible at all). |
We could probably consider alignment at each memcpy, and pre-pend some space before the memcpy if needed. Some care would be required to make sure that at deserialization we make the same decisions, which would probably mean making sure that the decode buffer is similarly aligned to the encode buffer. This is annoying when you are e.g. writing networking code and just get a buffer out from the kernel and would love to avoid a memcpy just to get the alignment better. |
Regarding network data alignment, given that on modern CPUs memory protection is managed at page granularity, I would suspect that network buffers coming from the kernel might be page-aligned. If so, that's more than enough alignment, as long as things like protocol headers and non-abomonated network payloads don't get in the way. Those should have the same alignment as on the sender's side though, so even if they do get in the way it doesn't seem terribly hard to work around it. But given that this page alignment theory is based on hardware implementation details that a Sufficiently Clever Kernel can work around (e.g. by slicing multiple buffers targeted at the same process from a single page), as a paranoid person, I'd probably use a |
By the way, how much do you care about the serialization output being a |
This issue came back in my work recently, as I tried to figure out how to expose a safe interface to abomonation. So here is a tentative plan to resolve the problem without dropping the nice
|
As a first step, it is also possible to skip the (Also, we may actually need something more custom than litteral use of the standard |
FYI, an informational advisory (RUSTSEC-2021-0120) was filed against |
As the docs say, abomonation currently doesn't guarantee correct pointer alignment. This is pretty dangerous, even on x86 as
rustc
might be tempted to generate those evil SIMD instructions that assume the data is aligned and raise an exception otherwise someday.I wonder if there is an API tweak we could use to improve upon this situation?
The text was updated successfully, but these errors were encountered: