News for hackers. Stuff that matters.
Re:Rust Malware Staged on Crates.io by fleventynine on Friday August 25, 2023 @11:26AM (#37262784)
It would be nice to see some sort of sandboxing for these. I would love it if cargo had a mechanism to run all build actions for a crate inside a firecracker vm.

That said, most build systems can access everything the user has access to, so it's not really a regression from the industry standard.

And Rust's typesystem on its own isn't enough to protect against malicious crates, even if you ban all unsafe code, procedural macros, build.rs, and filesystem/network APIs. Several soundness issues were found in previous versions of the standard library that allow a malicious crate to take advantage of undefined behavior to run arbitrary machine code. It seems likely to me that there are similar unknown issues lurking in today's standard library or compiler.

If you care about security, you have to audit your dependencies very carefully, no matter what language you are using.

Re:Rust Malware Staged on Crates.io by bitwize on Friday August 25, 2023 @11:53AM (#37263135)
If you're not sandboxing, you're asking to get pwned.
Re:Rust Malware Staged on Crates.io by goku12 on Friday August 25, 2023 @12:07PM (#37263315)
> I would love it if cargo had a mechanism to run all build actions for a crate inside a firecracker vm

Why not go in the other direction? A tool that can set up a VM with source code and build tools based on a declarative file? That could work for any language - not just Rust. Sort of like a completely local CI system.

Re:Rust Malware Staged on Crates.io by oneshtein on Friday August 25, 2023 @01:15PM (#37264348)
Who will verify VM, your local CI, and produced binary?
Re:Rust Malware Staged on Crates.io by goku12 on Friday August 25, 2023 @01:55PM (#37264866)
The idea of the microVM is to isolate the build system from the host. Your question is beyond the scope of the original problem.
Re:Rust Malware Staged on Crates.io by remram on Friday August 25, 2023 @04:20PM (#37266534)
You're describing Vagrant.
Re:Rust Malware Staged on Crates.io by goku12 on Friday August 25, 2023 @11:22PM (#37269679)
Ah! You're right. I wonder if vagrant is enough to mitigate these concerns.
Re:Rust Malware Staged on Crates.io by zer8k on Friday August 25, 2023 @12:38PM (#37263766)
> If you care about security, you have to audit your dependencies very carefully

The problem is Cargo is yet another iteration of the npm-ization (maven-ization?) of code. It requires a BDFL or a team of such BDFLs to proactively police the repos in order to prevent trivial supply chain attacks. Your statement misses the point that not only do people NOT do this it's now trivial to avoid it with Cargo.

This is not the same security risk that is present if you use git submodules and build with a makefile. The key difference is ease of use. Cargo, like NPM and to some extent Maven, are so easy to use you've accidentally created a massive attack surface.

The result will likely be yet another incarnation of JFrog or the like. Code will be audited, built into dylibs, and then pinned via some enterprise supply chain manager. This is a big lift for companies who might otherwise switch to Rust for new projects quicker.

Cargo is my main gripe with Rust almost all the time. So many people say "you can just build manually with rustc!" but this is not true. It's not as simple. Again, it would also be one thing if Cargo was just the package manager but it's also the build management system, test framework, etc. It's the ecosystem. It not only introduces supply chain attacks. It also introduces other attacks directly from the owners such as vengeful removal of packages, changes in CoC that ban certain libraries, etc. I don't like it. Of all package managers, it makes me feel the worst.

Re:Rust Malware Staged on Crates.io by wredue on Friday August 25, 2023 @12:53PM (#37264005)
The issue is that if your language doesn’t NPM-ize your packages, developer write you off as not modern enough.

The simple fact is that this seems to be what most developers want, AND this is not limited to JavaScript developers.

Re:Rust Malware Staged on Crates.io by howinteresting on Friday August 25, 2023 @12:58PM (#37264100)
The ease of use outweighs the security concerns for most reasonable people.
Re:Rust Malware Staged on Crates.io by empath-nirvana on Friday August 25, 2023 @12:57PM (#37264094)
> Several soundness issues were found in previous versions of the standard library that allow a malicious crate to take advantage of undefined behavior to run arbitrary machine code. It seems likely to me that there are similar unknown issues lurking in today's standard library or compiler.

Even without any soundness issues or bugs or security flaws, people can just plain write malicious code. Rust prevents a lot of common _mistakes_, but people can also use it to write completely "safe" worms that are guaranteed not to have use-after-free errors, data races and unexpected panics.

I don't think there's any way to get around the social aspects of software security for most developers ("trusting _people_ not code")

Re:Rust Malware Staged on Crates.io by binary132 on Friday August 25, 2023 @01:38PM (#37264629)
And yet hardly anyone ever makes this argument against sandboxing the code we download on demand every single day while browsing the internet.

I have started to believe we should think of open-source software as not so different, and sometimes even as less trustworthy in certain ways since we typically don’t sandbox it.

How many of your tools have telemetry? How many of your drivers do? How many download and execute stuff on the fly?

Re:Rust Malware Staged on Crates.io by tentacleuno on Sunday August 27, 2023 @04:36AM (#37280657)
That's completely different, though. JavaScript is sandboxed (and a lot of effort goes into ensuring that), while build-time macros (and runtime code) runs on the machine in an unrestricted manner. Not sure what your point is.
Re:Rust Malware Staged on Crates.io by fleventynine on Friday August 25, 2023 @05:28PM (#37267257)
> Even without any soundness issues or bugs or security flaws, people can just plain write malicious code. Rust prevents a lot of common _mistakes_, but people can also use it to write completely "safe" worms that are guaranteed not to have use-after-free errors, data races and unexpected panics.

The idea here is that if the "evil crate" is prevented by the compiler to call out into any os functionality or use unsafe, the worst it can do is return bogus values, mutate anything it has a &mut reference to, and leak heap memory. And if the toolchain were perfect, that might be achievable.

This was the promise that Java Applets made, which wasn't achievable due to the JVM being too bug-prone.

Re:Rust Malware Staged on Crates.io by remram on Friday August 25, 2023 @01:18PM (#37264392)
Why would macros need sandboxing if the crate build doesn't have any? What is your threat model?

Without proc macros, running `cargo build` or `cargo check` can already do anything via `build.rs` scripts. Without that, you still run arbitrary code from crates.io if you do `cargo run` or `cargo test`.

Re:Rust Malware Staged on Crates.io by louislang on Friday August 25, 2023 @01:19PM (#37264398)
We're actively working on this with our sandbox (https://github.com/phylum-dev/birdcage). We've wrapped the likes of pip, yarn, and npm already and are making moves to similarly provide support for cargo.

Currently comes as part of the Phylum CLI (https://github.com/phylum-dev/cli), so that doing something like:

    phylum npm install <somePkg>
Will reach out to the Phylum API to ask what we know about it (e.g., does the source have characteristics congruent with malware?), if that passes it'll then install the package from within the confines of the sandbox with limited disk, network and env access (as defined by allowed resources in the TOML file).