News for hackers. Stuff that matters.
Re:Beej's Guide to C Programming by saagarjha on Monday February 27, 2023 @09:42AM (#34956959)
> CHERI doesn't make much sense in Rust

CHERI was obviously designed for C and C++, but that doesn't mean it doesn't make sense to use with Rust. Capabilities are generally useful primitives, and allow you to do things like eliminate bounds checks because they are not handled by the hardware.

Provenance is kind of weird in that it is very underspecified and compilers have mostly been flying by "do whatever feels right" for many years, which has mostly worked until recently, when people decided to really sit down and hammer out proper rules for the things people expect to work. CHERI has accelerated those efforts because whatever gets picked for provenance is going to be implemented on that platform and they would like capabilities to line up with whatever they decide. In a sense, this is the opposite problem, where C decided to not really specify behavior at all and now needs to clean up its act, rather than overspecifying and being unable to adapt to new hardware. It's good that it's being cleaned up but mostly aligned with what people have already been doing.

Re:Beej's Guide to C Programming by tialaramex on Monday February 27, 2023 @12:45PM (#34959503)
> Capabilities are generally useful primitives, and allow you to do things like eliminate bounds checks because they are not handled by the hardware.

Mmm. What does the actual performance look like? We can surprisingly often trim the actual performance of real software to exactly the same as no bounds checks, but while being sure it's in bounds, and so any approach that's more expensive needs a justification. In C and C++ that justification is pretty obvious, in Rust it's a tougher sell.

If it helps WUFFS can emit high performance C number crunching code that is definitely bounds safe, regardless of whether it includes what appears to be any actual bounds checking, if CHERI exhibits overhead for that code compared to no CHERI - which I think it does, that's a price for CHERI that isn't giving any benefit and you'd expect similar for a high quality Rust port to a platform with CHERI modulo Aria's suggested way forward.

> Provenance is kind of weird in that it is very underspecified and compilers have mostly been flying by "do whatever feels right" for many years, which has mostly worked until recently

I don't agree that it "mostly worked". Until Rust the main consumers of optimising compilers which heavily rely on provenance shenanigans were C and C++ and in both languages you could just scare off the repeated bug reports resulting from such shenanigans by pointing at DR/260 in which WG14 basically says "Yes pointer provenance is a thing" but declines to specify how it could possibly work and leaves it to compilers to do whatever they want. Those bug reports do exist, they just got closed NOTABUG.

Only Rust finally starts asking what the LLVM IR actually means and there are a lot of awkward questions resulting from that, continuing to this day. I think it would have been a lot easier to keep kicking the ball into the long grass (as WG21 agreed to do yet again this year for C++ itself) if there wasn't a language with a whole lot of users asking these awkward questions.

Re:Beej's Guide to C Programming by saagarjha on Monday March 06, 2023 @02:17AM (#35038323)
> What does the actual performance look like?

Hard to say, production hardware isn’t out yet. Anyways, I think you misunderstand my point, CHERI is definitely designed for running C/C++ code but obviously people will want to run Rust on it. In that scenario capabilities are “free” because they exist by default (just like MMUs give you protection for no cost because they’re always on for modern OSes), so Rust can work with it.

> If it helps WUFFS can emit high performance C number crunching code that is definitely bounds safe

WUFFS is cool but it’s not really meant for general-purpose code.

> Until Rust the main consumers of optimising compilers which heavily rely on provenance shenanigans were C and C++ and in both languages you could just scare off the repeated bug reports resulting from such shenanigans by pointing at DR/260 in which WG14 basically says "Yes pointer provenance is a thing" but declines to specify how it could possibly work and leaves it to compilers to do whatever they want.

I think this lacks context. The compilers of yesteryear and even mostly the compilers of today can’t do much with provenance, because doing optimizations on it often requires global program analysis that is infeasible to perform. The examples that people knew were problematic were almost all centered around surprising compilation results in small snippets showing things like “off the end” pointers having the same bit pattern as the address of the stack object next to it, but comparing different. The responses to bug reports like these was not that provenance was broken but mostly “the standard doesn’t really want you doing stuff like this anyways, so go away”.

The actual legitimate use of provenance mostly did work, which was stuff like pointer tagging and stuffing (requiring round trips through various integer representations) for language runtimes and the like. Authors of that code typically worked really close to the hardware to questions like “does this pointer have provenance” doesn’t really mean much to them, they’d expect that it compiled to a load instruction like they expected and for the most part compilers would play it conservative and assign arbitrary provenance to operations like that. The exploration of “hmm, maybe we should specify this better” is a recent phenomenon that was done mostly independently of Rust the language but obviously a lot of those people were involved because the compiler/LLVM community is comprised of Rust people too.