C++ already gives us a tool for pointer zapping
C++ already gives us a tool for pointer zapping
Posted Oct 16, 2024 14:17 UTC (Wed) by tialaramex (subscriber, #21167)In reply to: C++ already gives us a tool for pointer zapping by tialaramex
Parent article: Zapping pointers out of thin air
Notice that if thread 2 interrupts us and replaces A with C while we're setting and checking the hazard pointer (so A isn't yet protected by the HP), but A and C had the same address, we end up learning that we successfully made a HP pointing at C (even though we asked for a HP pointing to A) which is the new first item, and we connect B to C not A (even though mechanically that's identical) and our compare exchange succeeds. We didn't invoke Undefined Behaviour, although we did do what looks like needless work reading a value twice - the work wasn't needless because the second read made our code correct (and in other circumstances would stop us in our tracks when there's a real problem to be fixed and we should try again).
In CHERI, this case works properly, despite A and C having distinct magic provenance bits, the checks all work and the correct pointer is stored in B, so long as the code was written very carefully. And I believe MIRI can check this is correct (in Rust) despite the fact most programmers do not have any CHERI test hardware.
Sorry I'll stop now, this was rattling in my head.
