futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

WakerRef depends on libstd implementation detail for soundness

Open bjorn3 opened this issue 3 years ago • 4 comments

It depends on the fact that Waker always stores the data of the waker behind a reference and never inline. If data was stored inline, WakerRef could be used to cause a use after free by storing a Mutex<Vec<u8>> in the waker and then for a WakerRef derived from this waker mutate it to force the vec to reallocate and then access the vec stored in the original waker, which is now dangling due to WakerRef storing a copy of the waker rather than a reference.

bjorn3 avatar Jul 23 '22 08:07 bjorn3

Hmm, RawWaker docs say it consisted of a pointer and a vtable, so I thought it would never inline the data...

taiki-e avatar Jul 23 '22 10:07 taiki-e

It doesn't right now, that is why it is sound right now. I don't think it gives any guarantees it will never inline the data, which is why it relies on an implementation detail for soundness. Either WakerRef could be changed, or the docs of RawWaker could be changed to explicitly allow this.

bjorn3 avatar Jul 23 '22 18:07 bjorn3

The API of RawWaker doesn't allow the data to be stored inline (const ()), so I don't think this is an actual issue.

carbotaniuman avatar Jul 24 '22 18:07 carbotaniuman

The current API doesn't and that is why it is fine right now. There is no guarantee that this will remain the same in the future. It makes sense that it will remain the same, but it isn't documented as such.

bjorn3 avatar Jul 25 '22 10:07 bjorn3