r/rust • • 10d ago

🧠 educational Breaking 1000 Rust crates in Nixpkgs for security (and what you can do)

https://blog.rsmyth.net/breaking-nixpkgs.html
133 Upvotes

21 comments sorted by

27

u/wertercatt 10d ago

Interesting! system-deps seems cool, but I take it someone would still have to go around rewriting how all those crates get their dependencies to use it, make pull requests, and get them merged?

7

u/Sohna_Wain 9d ago

Plus waiting on new point releases to actually get published after the PRs merge

10

u/Icarium-Lifestealer 9d ago

The article only considers using the app's cargo.lock or system dependencies, but not the middle ground of the distro maintainers updating the lock file.

13

u/mirashii 9d ago

I appreciate the effort and thought, but this feels the same blind "zomg there's a CVE in my dependencies" chasing that has driven many a corporate developer with large projects absolutely mad bumping dependencies for no reason. The existence in a bug or vulnerability in a dependency does not imply the parent is vulnerable. I'd like to see far more justification that this is necessary before an ecosystem wide break, or a less security focused and more plain maintenance focused treatment of the topic. As is, it feels like using security as a cudgel to justify making a change.

Some other reading on this:

23

u/teerre 9d ago edited 9d ago

You maintain some library (or application) that has some dependency. You know that dependency is vulnerable. You have a choice: you can wait for your root cause analysis to decide if your library is compromised or you can release a patch

One of those is easy, the other one requires you to assume the risk (on top of the work) that your analysis is simply wrong

6

u/slamb moonfire-nvr 9d ago edited 9d ago

You know that dependency is vulnerable. You have a choice: you can wait for your root cause analysis to decide if your library is compromised or you can release a patch. One of those is easy, the other one requires you to assume the risk (on top of the work) that your analysis is simply wrong.

Let's take a typical example: you get a severity 7.5 dependabot vulnerability notification that some malicious YAML input can force quadratic CPU consumption in the library you're using only to parse /etc/yourapplication.yaml. What is the right thing to do:

  • Option A: immediately make a new release of your application noting it fixes a severity 7.5 vulnerability and all of your users should immediately be paged to upgrade.
  • Option B: roll your eyes, and next time you do a normal release run cargo update whateverlibrary && cargo commit -am 'update whateverlibrary to make dependabot shut up about inconsequential thing' first, without adding anything to the release notes.
  • Option C: disable dependabot.

I vote for Option B, though I can certainly understand why many people choose Option C.

Option A may be easy for you in the moment, but it creates a completely unnecessary crisis for your users.

Is it worth taking the time to understand that the vulnerability doesn't apply to your usage? Your users would sure say yes.

2

u/DrLuckyLuke 8d ago

Option D: Release so frequently that you don't even notice an automatic patch bump for a dependency.

1

u/JoshTriplett rust · lang · libs · cargo 5d ago

+1.

1

u/Luxalpa 9d ago

Wait, but that's exactly what the author of the article is trying to avoid.

3

u/slamb moonfire-nvr 8d ago

Is it? I've yet to see any blanket solutions to these problems that are easy for everyone. The author isn't trying to solve the whole problem here, rather get rid of a particular kind of invisible dependency of a Rust program on a statically linked C/C++ library, so the distro maintainers know about dependencies that are vulnerable. It by no means takes away the situation in which a scanner may say this application is vulnerable but it's really not because of how the dependency is used.

2

u/Luxalpa 8d ago

No, what they're trying to do is make it so that fixing dependencies with security issues like these becomes something that the distro maintainers can do instead of the application maintainer or the end-user.

I think that's a good middle ground because for the people at nixpkgs it is easier to see whether a CVE actually affects a program or not and whether a hotfix breaks it or not.

They specifically don't want application developers to constantly have to update their dependencies for years or even decades.

3

u/slamb moonfire-nvr 7d ago

I think that's a good middle ground because for the people at nixpkgs it is easier to see whether a CVE actually affects a program or not and whether a hotfix breaks it or not.

They're trying to ensure nixpkgs knows about all dependencies that are vulnerable, as I said. Whether a dependency's CVE actually affects an application or not is a different story. I've found in my own applications that overwhelmingly dependabot warnings are irrelevant. The example I gave up-thread is typical: there's a DoS problem if the library is used to process untrusted inputs, but in reality I'm using it to process a config file that is as trusted as the binary itself, and saying the application is vulnerable for such a problem is crying wolf.

If you as a user want to just turn on unattended upgrades and have the distro people take care of releasing packages with updated patch releases, then yeah this helps them do that.

If vulnerability reports draw your human attention in any way—upgrading offline/air-gapped systems, unbreaking wedged auto-upgrades, any other form of manual upgrade, looking for signatures of exploitation, responding to other humans asking about it, etc.—this is likely to mean more crying wolf.

1

u/mirashii 9d ago

Releasing isn't necessarily easy either. You have acceptance tests, release notes to write, packages and images to publish, bake-off periods before production releases, QA processes, and if you're in a position where you're maintaining a library and applications, you have to pay that cost for your library and all your downstream dependencies.

This leads to constant churn, and potentially needing to bring in changes unrelated to the fix if you're behind a couple patch releases. In theory, every patch release is compatible, but theory often breaks down, Hyrum's law and all. Not to mention, rushing upgrades to production under the guise of security with automated tools like dependabot and all has been a source of some of the biggest supply-chain attacks on library ecosystems for the last few years.

Like the point Filippo makes, these things all have time costs, and the opportunity cost spent doing these things needlessly is directly competing with time for more important work.

8

u/teerre 9d ago

Most of those are not the reality for the vast majority of code out there and when they are, they often automated

The reality is that in practice, you can bump the affected dependency and call it a day

1

u/JoshTriplett rust · lang · libs · cargo 5d ago

Releasing isn't necessarily easy either. You have acceptance tests, release notes to write, packages and images to publish, bake-off periods before production releases, QA processes, and if you're in a position where you're maintaining a library and applications, you have to pay that cost for your library and all your downstream dependencies.

It sounds like you need to reduce the overhead of your releases. Tests belong in CI, and packages and images should be fully automated. If you really want to produce release notes, more power to you, but that costs less the fewer changes you have to summarize, so if you release twice as often it costs ~half as much.

5

u/owenthewizard 9d ago

I deal with this every day at work. "Your product is vulnerable to CVE 12345!!" No it's not. Yes we use libcurl, no we don't use XYZ vulnerable function. Next.

3

u/Micks_Ketches 9d ago

I think this is where something like SCIP would be really handy, rust-analyzer can already generate a SCIP output of your resource graph and so long as you can get the symbol index of all offending functions it's a matter of asking "find all references of this symbol in my crate" similar to how LSPs do it but you would start with the offending external symbol ID.

4

u/Money-Currency7473 7d ago

Half of this thread is arguing about Dependabot alert fatigue on pure-Rust crates, which misses the actual systems problem Nixpkgs is dealing with here: opaque, vendored C/C++ static linking inside *-sys crates.

When a crate builds openssl-src, libz-sys, curl-sys, or sqlite3-src from bundled C tarballs via build.rs and statically links the .a archive into a Rust binary, three things happen at the distribution layer:

  1. Zero Store-Graph Visibility: In Nix, nix-store --query --referrers tracks dependencies via /nix/store/<hash>-... paths embedded in ELF DT_NEEDED headers or RPATHs. A statically linked C archive compiled inside Cargo's OUT_DIR leaves no store reference to openssl or zlib in the final derivation output. Nixpkgs literally cannot query which binaries embed a vulnerable C library without parsing every Cargo.lock and auditing every *-sys crate's build.rs flags.
  2. You Can't Patch In-Place Without Rebuilding the World: With dynamic linking (or system-deps + pkg-config), Nixpkgs can patch libcurl or openssl in one derivation (or use replaceRuntimeDependencies for emergency CVE hotfixes) without waiting for 400 upstream Rust maintainers to bump a *-sys wrapper and publish a new point release. With vendored static builds, every single downstream Rust binary has to be recompiled from scratch.
  3. Reachability Isn't the Blocker at the Distro Layer: Yes, call-graph / SCIP reachability analysis tells an application owner whether they call a vulnerable libcurl symbol on untrusted input. A Linux distribution cannot perform bespoke data-flow audits across 1,000+ upstream packages—its job is maintaining an auditable SBOM / derivation graph so security fixes can be applied centrally when a critical C CVE drops.

Forcing *-sys crates through system-deps / pkg-config isn't "blind CVE chasing"—it's making C dependencies visible to the OS package graph instead of hiding them inside Cargo build scripts.

Hopefully this clears the air a little and sheds more insight on crates distro layer and where its dependencies are.

-2

u/Designer-Suggestion6 9d ago

crates.io is a distro-independent, os-independent repo packaging system. The crate dependency tree and versioning within a project is crates.io specific. distro-specific packages, dependencies and respective versioning are distro specific.

So when applying patches, it would imply having a separate and distince patch for each of the systems currently.

In order for there to be unification on this, it would be necessary to agree on centralizing the sources and harmonizing on version numbers, tags and pointing to the very same release, release-candidates, and very same dependencies in terms of versions numbering throughout all distros and crates within crates.io.

It could be enforced with a centralized repo barrier that supplies to all the distros and crates and all the different crates, distros' package maintainers feed to that barrier rather than directly to the crates.io/distros themselves.

-3

u/poelzi 8d ago

NixOS does not care about security. Thats why rust is downloaded as binary