Hacker News new | ask | show | jobs
by tialaramex 51 days ago
I think what's going on is that you've half understood the situation with CHERI as of a few years ago and now you're trying to explain your half-understanding to me confidently as if you're correcting me.

As I said, these types are the same width as an address on the target but a CHERI pointer isn't just an address, that's why they are so wide.

Maybe start here: https://doc.rust-lang.org/std/ptr/index.html#strict-provenan...

1 comments

No, I usually follow language and opsem discussions. While CHERI discussions are not something I follow closely, unless you have an explicit link I'm pretty sure I didn't miss something that important.

The strict provenance APIs or the "Rust has provenance" RFC are not relevant here (more precisely, they help clarify the options but do not solve the problem).

The problematic statement is still in The Reference (https://doc.rust-lang.org/reference/type-layout.html):

> Pointers to sized types have the same size and alignment as `usize`.

Which just cannot be guaranteed on CHERI with 64-bit `usize`.

There are discussions like there were before, and it's pretty clear that we'll have to give up either performance or possibly quite a lot of compatibility, but no decision.

I was not aware of that line in The Reference so that's interesting.

I suppose one of the things you could do, at least on Morello, is treat it entirely as Arm64 in all your Rust but offer some CHERI flavouring in FFI for people who had to do their memory safety in hardware. In such a world that statement is just true.

Can you roundtrip a pointer as `MaybeUninit<usize>`? This is implied by this statement (and other rules of the language). And people rely on it.

You can make CHERI a non-conforming target. In fact we already have some (did you know x86-32 is a non-conforming target?). This is one of the leading options. The question is whether we don't give up too much existing code by that. No existing target is that incompatible.

> Can you roundtrip a pointer as `MaybeUninit<usize>`?

AIUI Strict Provenance rules imply that you can't expect any such tricks to work unless the target promised they would work.

You say "People rely on it" and I must ask: How many people and how sure are you that they actually can't live with Strict Provenance ?

That's not true. Strict provenance says that you can not roundtrip a pointer via `usize` (with transmutes and not casts). You can via `MaybeUninit<usize>`. One of the fundamental properties of the language that is even specified explicitly (https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.h...) is that `MaybeUninit` preserves the exact Abstract Machine bytes, including provenance.
This manifestly can't work. Even if you can language lawyer your way to asserting that the words say this must work, it can't actually work in practice so the words are just wrong and I think other language lawyers will say that you must have understood the words wrong because "I'm correct, Up is actually Down" isn't helping anybody.