News for hackers. Stuff that matters.

dethinking

Re:Unsoundness in Pin on Friday November 29, 2019 @12:18PM (#21665558)
TIL, and since it’s buried a bit:

> A capsule is a Rust struct and associated functions. Capsules interact with each other directly, accessing exposed fields and calling functions in other capsules. Trusted platform configuration code initializes them, giving them access to any other capsules or kernel resources they need. Capsules can protect internal state by not exporting certain functions or fields.

> ...

> Rust’s language protection offers strong safety guarantees. Unless a capsule is able to subvert the Rust type system, it can only access resources explicitly granted to it, and only in ways permitted by the interfaces those resources expose. However, because capsules are cooperatively scheduled in the same single-threaded event loop as the kernel, they must be trusted for system liveness. If a capsule panics, or does not yield back to the event handler, the system can only recover by restarting.

I take it from the present discussion that that might not be as good of an idea as they think.

Worth noting that they also have process isolation on top, but it doesn’t seem to be motivated by any potential insecurity of the type system.

Re:Unsoundness in Pin on Friday November 29, 2019 @12:09PM (#21665484)
I think I originally had “piece of a type signature”, but I didn’t actually want to figure out which piece, so I fudged it. The point is well taken, I oughtn’t pretend I have a Rust parser in my head :)
Re:Unsoundness in Pin on Friday November 29, 2019 @11:54AM (#21665395)
Yes, it’s a type signature. It looks typical of Rust internals, but it would be very verbose for user code.

You’re not wrong to find it illegible; apart from the syntax, that phrase invokes the concepts of lifetimes, mutability, borrowing, and traits, none of which have straightforward semantic analogues in other common languages.

But FWIW they’re primitive concepts in Rust. A typical Rust user wouldn’t read or write code that looks like that very much, but they would know what it means, if that makes any sense.

Edit: Seeing sibling comments about whether this snippet actually parses, I guess I should amend this to say that a typical Rust user has an idea of what it’s supposed to mean :)

Re:Unsoundness in Pin on Friday November 29, 2019 @11:24AM (#21665217)
Not sure if you caught it, but Ralf does address this somewhat in the thread:

> Good question. We even had a sketch of a formal model for pinning, but that model was always about the three separate pointer types (PinBox<T>/PinMut<T>/Pin<T>). The switch to the generic Pin was done without formal modelling.

> Actually trying to prove things about Pin could have helped, but one of our team actually did that over the summer and he did not find this issue. The problem is that our formalization does not actually model traits. So while we do have a formal version of the contract that Deref/DerefMut need to satisfy, we cannot even state things like "for any Pin<T> where T: Deref, this impl satisfies the contract"

That does sound scary, but I think the point is that this is a known blind spot in the formal model. It also has a known solution; the trait ought to be unsafe, so that the implementor takes responsibility for upholding the contract. The issue with Pin is it’s using an existing, safe trait, on the informal assumption that it couldn’t be unsoundly aliased by users. (Of course that turns out to be false.)

So you can look at that and say “an unsound feature got into the stdlib without passing formal verification”, and that’s true, speaking to a lack of concern for formalization.

On the other hand, you could look at it and say “the unsoundness of this feature is well isolated by formal methods and leakage at this interface is not the end of the world”, which is also true, and speaks to the utility of the formal work that has been done.

It seems clear to me that the answer for Rust is “balance”. Formal verification is important not not to have, and things that can’t be verified shouldn’t be allowed. But formal verification takes up time when everything could be working 100% in production, and the alternative is likely even less sound formally, so it’s better to build an API now with some known risks than to wait for something known to be risk-free.

Whatever your personal philosophy is, it seems clear that toeing that line has been instrumental to Rust’s success.