News for hackers. Stuff that matters.
Re:PL/Rust 1.0: now a trusted language for Postgres by lexicality on Sunday April 09, 2023 @10:44AM (#35503167)
only when using `unsafe` which this forbids
Re:PL/Rust 1.0: now a trusted language for Postgres by tyingq on Sunday April 09, 2023 @11:29AM (#35503654)
I don't know much about rust, so it seemed odd to me that just forbidding unsafe would make for a reasonable sandbox. At least for the postgres concept of "trusted language", that's supposed to mean things like closing off access to the filesystem. Not just typical file io calls either, but more obscure stuff like sendfile().

I do see that rust access to sendfile() would be via a syscall, which is in the unsafe category...so perhaps that's not the best example.

But it does make me curious how comprehensive a sandbox PL/Rust is providing, beyond just forbidding unsafe.

Re:PL/Rust 1.0: now a trusted language for Postgres by iudqnolq on Sunday April 09, 2023 @11:50AM (#35503857)
pl/rust is its own target platform, so they provide their own standard library*. The IO stuff all panics, for example. (In Rust a panic should be used to indicate invariant failure. pl/rust catches panics and converts them to postgres errors).

In Rust you'd normally be able to link c code, but calling c requires unsafe because you have to manually ensure the c code upholds any relevant Rust invariants.

> But it does make me curious how comprehensive a sandbox PL/Rust is providing, beyond just forbidding unsafe.

They also hook the compiler and try and detect shenanigans. It's not perfect, but it's pretty thought out.

*Technically the Rust standard library builds on top of a lower-level io module, which is all you have to replace.

Re:PL/Rust 1.0: now a trusted language for Postgres by gpm on Sunday April 09, 2023 @12:52PM (#35504390)
More than just forbidding unsafe, but not enough to make this secure against competent adversaries by their own admission. They argue postgres itself isn't secure against competent adversaries so this doesn't matter too much.

https://tcdi.github.io/plrust/plrust.html#what-about-rust-co...

Rust keeps a list of soundness bugs via a tag on github - they're pretty common:

https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Ais...

Re:PL/Rust 1.0: now a trusted language for Postgres by yarg on Sunday April 09, 2023 @08:05PM (#35507683)
Read the article, they specify that they use a compiler target that restricts system access.

As I read it, it seemed that the unsafe prohibition was more about the safety of the code and not the security of the system.

Re:PL/Rust 1.0: now a trusted language for Postgres by formalLogicGirl on Sunday April 09, 2023 @11:47AM (#35503823)
And there is also an alternative implementation to Rust std that blocks, among others, filesystem access via std::fs https://github.com/tcdi/postgrestd
Re:PL/Rust 1.0: now a trusted language for Postgres by chrismorgan on Sunday April 09, 2023 @12:34PM (#35504245)
This implementation blocks file system access and is thus not vulnerable, but note that in Rust in general you can actually violate safety on some platforms without any `unsafe` by modifying magic files like /proc/self/mem. This is a known issue but considered unfixable (because the technical solution of marking opening a file as unsafe would cause far more trouble than it could ever hope to solve).
Re:PL/Rust 1.0: now a trusted language for Postgres by IshKebab on Sunday April 09, 2023 @12:52PM (#35504380)
It's more of an interesting fact than an issue to be fixed.