Skip to content

Could Unalign::update cause issues for types that are aware of their memory location? Is this a soundness hole? #266

@joshlf

Description

@joshlf

Rust doesn't allow the following code:

#[derive(Copy, Clone)]
#[repr(C, packed)]
struct Unalign<T>(T);

It won't emit a Clone impl - instead, you have to write it yourself, using a T: Copy bound. It occurred to me that they could use the same trick we use in Unalign::update, using ptr::read to move to the stack, calling clone on the now-aligned value, and then mem::forgeting the copy. That would not play nicely with interior mutability (not a problem for us - Unalign::update takes a &mut self), but I realized that it also might cause problems if you have a type whose semantics include its memory location. This could be for soundness reasons (e.g., pinned types) or for safety reasons (user-defined invariants).

Need to think through this more to figure out whether Unalign::update is actually unsound.

cc @djkoloski since you reviewed that PR and might have thoughts

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocking-next-releaseThis issue should be resolved before we release on crates.iocompatibility-breakingChanges that are (likely to be) breaking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions