rust-lang/unsafe-code-guidelines

Provenance for zero-sized accesses?

Closed this issue · 2 comments

Is provenance required in order to perform zero-sized accesses? Following up on rust-lang/rust#116677 (comment), I understand that it is sound (e.g. per the ptr module docs) to perform a zero-sized load or store using a pointer derived from any non-zero integer literal. Since integers do not have provenance, this implies that zero-sized accesses do not require valid provenance. Is that correct?

I believe this is covered by the FCP on zero-sized accesses #472 (which was approved but IIRC still has some implementation work to avoid LLVM miscompilations). All zero-sized accesses are allowed, including those with invalid provenance or no provenance. The ptr module docs have an exception for provenance to deallocated memory, but hopefully this can be removed at some point.

The status quo is that zero-sized accesses require either valid provenance or no provenance.

rust-lang/rust#117945 tracks changing this to allowing any provenance.