Hacker News new | ask | show | jobs
by tgma 17 days ago
As much as everyone is getting allergic to Rust migrations that sometimes make little sense, keeping network-facing daemons in C is just asking for it at this point. It's time to start seriously migrating to web servers like ferron.sh or https://xinproxy.com or whatnot.
19 comments

I now run all my network facing C code via fil-c. I have limited needs (ssh, static file server), but for those it works very well. I personally am more in favour of making existing battle tested C safer via fil-c or formal verification, than I am of rewriting the world in rust.

New code means new bugs, and losing the many years of accumulated bug fixes and hardening present in many critical pieces of our infra by rewriting in rust is not a desirable tradeoff. The new world we live in where fv has become many orders of magnitude cheaper also makes rust seem much less attractive.

Fil-C is also a great solution, albeit with different performance trade-offs.
In theory, scpptool provides another solution with different performance, compatibility and portability trade-offs. Unlike Fil-C, it is not "fanatically compatible" with existing C code. But in theory, with maybe some minor adjustments to the code (and maybe less-minor adjustments to the build system), you can auto-translate your existing C code base to an essentially memory-safe subset of C++ at build-time [1].

While generally more of a hassle than Fil-C, the scpptool approach provides an incremental path to optimal performance (for performance-sensitive sections of the code) via migration to a (statically-enforced) memory-safe subset of C++. And unlike Fil-C, the scpptool solution essentially maintains the portability of the original code, as well as its deterministic performance and resource usage (i.e. no GC). It also supports ABI compatibility via "unsafe"/"check-suppression" annotations. The scpptool approach is not so much an alternative to Fil-C, as it is an optional path forward for C (or C++) code bases that may (or may not) be already using Fil-C for memory safety.

[1] https://github.com/duneroadrunner/SaferCPlusPlus-AutoTransla...

What good is a car that goes 1000 miles per hour if it has no brakes?

It's time for performance above everything else to die, especially on anything and everything that gets anywhere close to untrusted data.

If performance is a critical factor, then formal verification of many c programs is probably cheaper than a rewrite in rust these days. There are still limits (especially around concurrency and syscall modelling), but given the money and energy being poured into the field at the moment, I would be surprised if those remain serious obstacles for long.
In many cases the performance is not that important, for example, SSH is often used to transmit mere kilobytes of text per second and I would prefer a safe SSH to a faster unsafe SSH. Or take mDNS, it servers several requests per minute max.
This sounds like a fantastic solution, especially for non-high-volume stuff. Would you consider writing down your setup and experiences? I'm sure it'll be a hit on this site!
Same, made a fil-c fork of nginx a while back, saved me from many RCEs https://github.com/remixer-dec/filc-nginx Don't have the tokens to maintain it though :(
fv?
Formal verification.
formal verification?
I've reached the same conclusion myself. Many of the recent exploits seem like edge-cases that the author acknowledged 10-20 years ago but didn't predict that tools would eventually be able to chain together 100k network requests in order to trigger a buffer overflow.
Who exactly are the people behind xin...?

The project isn't currently open source and there's next to nothing on the site to reassure you who's behind the server gateway you'd be running.

Googling the company in the footer produces this, but it also doesn't have much: https://www.signeen.com

If we're suggesting alternative web servers, I have had a pleasant experience with caddyserver (Go). It's been around 10+ years, has essentially transparent TLS certificate provisioning, and its config syntax is easy to understand. Even using AI to help vet configs, it's readable. It's packaged everywhere and has lots of plugins for things, though I only need the base package for my frontend proxy usecase.
Nginx and C have been around for decades. Migrating to new, poorly tested (in the real world) software does not seem an improvement at all.
Nobody is saying that it needs to be rushed. Cloudflare started moving towards Rust more than a decade ago and (shortly after heartbleed happened) and progressively rolled bits out over the course of years. I'm sure there were problems here and there but it's hardly been a drag on them.

And parts of that involved specifically replacing Nginx in their architecture, so it's hardly irrelevant here.

https://blog.cloudflare.com/20-percent-internet-upgrade/

https://blog.cloudflare.com/how-we-built-pingora-the-proxy-t...

> With those assurances we can focus more on how a change to our service will interact with other services or a customer's origin. We can develop features at a higher cadence and not be burdened by memory safety and hard to diagnose crashes.

> When crashes do occur an engineer needs to spend time to diagnose how it happened and what caused it. Since Pingora's inception we’ve served a few hundred trillion requests and have yet to crash due to our service code.

> In fact, Pingora crashes are so rare we usually find unrelated issues when we do encounter one. Recently we discovered a kernel bug soon after our service started crashing. We've also discovered hardware issues on a few machines, in the past ruling out rare memory bugs caused by our software even after significant debugging was nearly impossible.

I mean, a lot of nginx use cases can be handled by e.g caddy - which does have significant real world deployment.
Given the volume and depth of testing possible with AI these days I'd say the decades of testing isn't that expensive to reproduce, especially if it's an OSS project with a public bug tracker.
If you're using NGINX to run your PHP applications, consider eliminating everything other than PHP itself:

https://news.ycombinator.com/item?id=50551504

xinproxy has a pretty restrictive license, but I'll give ferron.sh a closer look.
But rust is not a silver bullet. Rust compiler still has memory corruption bugs. Rust is only memory safe by design not by implementation. Borrow checker allows unsafe code without using unsafe keyword.
It isn't perfect. But it is still way better than c.
> Borrow checker allows unsafe code without using unsafe keyword.

is this just the continuation of the previous point (compiler/borrow checker can have bugs), a nod that you can import unsafe dependencies, or is there a soundness gap in rust that I'm not aware of?

Yes compiler/borrow checker bugs. Rust has a few unexplored right now.
No one is expecting a silver bullet. The absence of a silver bullet shouldn't prevent people moving towards better solutions.
this is just a perfection fallacy. silver bullets don’t need to be perfect in every single way to be silver bullets. and rust is as much of one as anything.
You can still die in a car accident while wearing a seatbelt, too.
As someone that was a developer for a long time what is the problem with C? How does going to rust mitigate this? Why is having the stuff in C a security challenge?
It's very easy to accidentally write buffer overflows, use-after-frees or other memory-safety bugs in C. Modern tooling can probably catch some of these better than in the days of yore but the fundamentals of the language are still the same.

If e.g. the standard array type in a language has built-in bounds checks that error out when you try to write to an index that's outside of the array, you can't trivially create buffer overflows simply by writing to the wrong index or by trying to write n + 10 bytes into an n-byte array.

But C in itself has no guardrails against something like

  char buffer[100];
  strcpy(buffer, some_user_supplied_string_with_200_chars);
Of course most memory safety bugs aren't trivial like that since C programmers have hopefully learned to avoid the simple mistakes. But there can be more complicated and difficult to spot cases, and C has no guardrails against those either.
Some people think it's fundamentally impossible for C to be correct or memory safe
Fundamentally impossible? No.

Practically impossible? Yes.

SQLite is probably the most thoroughly tested and carefully developed C library in history and they still found a handful of memory safety bugs every year.

Rust is memory safe at the cost of being harder to write, but with AI, it's actually really easy to write it because AI's loove strict compilers. So now that AIs can just find 0-days before things are even released (so I'm told), it makes a lot of sense to do bun[1]-style rewrites to Rust with AI.

1: https://bun.com/blog/bun-in-rust

If a bug is found before its released... Then that's not a 0-day?

The name refers to the number of days since public release. "Exploitable 0 days since release". If you found a bug before release, then that's... Just a bug picked it up in normal development lifecycle.

I read 0 days like "Exploitable 0 days since _discovery_". Also, it's only a bug in the normal lifecycle if the discoverer tells the developer making it. If they discover it and then have hours and days to perfect a program that exploits it, then starts running immediately when it is deployed or released, that's a new kind of "zero day". Makes you want to start differentiating what "0 days" mean, though.
If AI found it, then the discoverer has told the dev, though, right? So it _is_ in the normal lifecycle. So it can't be a zero-day.
The ai told the hacker. The hacker discovered it with his AI before the developer released by examining his git branch.

I think that's the fundamental disconnect in the conversation here. You think I'm talking about the dev because it's not released yet but just because it isn't tagged and released doesn't mean it's not done in the open where hackers can see it and their AI can scan it.

is xinproxy open source? the website only has binaries and I couldn't find anything on github
Ferron is opensource. xin isn't yet.
See Morris worm, and when it took place, afterwards check Multics security assement done by the DoD versus UNIX.

Additionally, check what the inventors themselves of UNIX and C did after being done with them, and what they did afterwards in terms of operating systems and programming languages.

Yet, some folks are more attached to C than the inventors themselves.

So what is the solution, rewrite in Rust?
The solution was not to take C into widespread use in first place.

Note that even C creators, first came up with Alef for Plan 9, which did not work out due to lack of automatic resource management (on Rob Pike's own words), and then Limbo for Inferno, which by then meant C main purpose was the OS itself and DisVM/JIT implementation.

Even on classical UNIX, there used to be a tendency that many userspace tools were to be written on top of scripting like AWK, sed, tr, Perl,... not everything to be C.

In terms of systems programming safety that people wonder about Zig, was already there in languages like JOVIAL, PL/I and NEWP, among others, a decade before C came to be.

The solution is not to write new code in C, unless there is no alternative, like coding on UNIX/POSIX kernels (UNIX based on Ada or Pascal dialects like did not fair that well, e.g. Domain/OS).

Not everything has to be Rust, it can be Ada, Modula-2 (now on GCC), D, Swift, FreePascal/Delphi, Zig, Odin, C++ (proper C++ with standard library, not code C with C++ compiler), C# AOT, Java AOT, Go, .... whatever depending on the use case.

Sure, using a closed source proxy from a company nobody has ever heard of... That's a good idea...

Ferron seems much better, but I'm also not convinced that it's really production ready

This looks like someone prompted "rewrite nginx in rust, make no mistakes" in an afternoon and is now distributing it as a closed-source binary. Might as well just do it yourself.
It's a bit political to say that C is the fault here, I'd venture the radical position that this was an Nginx issue.
No idea what the code is like, but the AI-generated landing page makes xinproxy an immediate "no thanks" for me.
xin seems to be closed source and ai generated. Before even worrying about exploits, how is someone supposed to ascertain that xin's implementation is correct? Sure Rust might not have any memory safety issues, but other logic vulnerabilities may exist. 'Claude make no mistakes?'

Caddy, Traefik, or even Envoy may be better choices.

Haven't you heard? These vulnerabilities are just AI marketing stunts. And also, the Bun rewrite to rust was a marketing stunt, those things don't work. There's no way Bun is running on Rust from a couple month AI powered rewrite, that would shatter my preconceived worldview about what the future looks like. /s
I'd hate to interrupt all the Rust fans sucking each other off again, but no one has yet mentioned the RCE relies on ASLR being disabled, which is basically non-existent nowadays. Another nothingburger CVE with a silly name and it's only Wednesday.
Software doesn’t generally get checked for bugs until it has users. These new web servers mostly have that going for them rather than the language.
It is true that mileage is a good proxy for finding bugs, but this is isomorphic to the fundamental differences between testing v. verification. You can prove absence of classes of bugs with verification. Obviously there can be other logic bugs in newer software. No question. The issue is the memory-corruption bugs in socket-facing daemons can have catastrophic consequences, especially in light of chaining kernel vulnerabilities which defeats the privilege drop that nginx does.

So I'd say it is about a more holistic risk-analysis not just handwaving "all code can have bugs, duh!"

A more holistic risk-analysis would also need to consider the fact that a high-performance webserver written in Rust may also have memory safety issue due to use of "unsafe" features or unsafe dependencies, may be affected by memory safety issues in the standard library, may also have catastrophic logic errors, may be more affect by supply chain risks due to the use of a language-level package manager, and may have a larger patch gap.
Which is like complaining that Python is unsafe because it is written in C.

That is a far smaller surface as seen by research into incorporating rust in Android leading to none of the high profile vulnerabilities C and C++ led to previously.

Not in the slightest. It's like pointing out that a Python script calling out to binaries written in C doesn't have the memory safety of Python's GC. Which is obviously the case, and if you're a serious developer it's a failure point you're very mindful of.

On the Android point, I remember those metrics were highly flawed and didn't account for the inequality of substructural type ergonomics in different contexts. You can get very nice metrics by rewriting things that fit to the grain of safe Rust, which gives you an inaccurate picture of how much unsafe code is "real world". LLMs have changed the field here, but it's worth pointing out that blog post you're referencing was more self-congratulatory marketing than serious science.

Also problematically, I remember it being highly misleading in that the actual observed result was lower severity in vulnerabilities, but a very minimal effect on the total number over all. That's certainly significant, but it wasn't how it presented itself, which is rather problematic if you expect people to take it seriously as objective research.

Measurements probably real, but not worth citing. It's not like on their own blog they're under usual academic journal pressures to overclaim results, p-hack, and engage in other misleading behaviors.

By research you mean blog posts by Google?
What specifically distinguishes the empirical research presented in Google’s blog posts, for example the one linked below, from your definition of research?

https://blog.google/security/rust-in-android-move-fast-fix-t...

A more holistic risk-analysis would also need to consider the fact that wearing seatbelts in motor vehicles still leaves drivers vulnerable to drive-by shootings, may be affected by massive boulders crashing on top of the vehicle, driving off a bridge, or gas explosions, and costs more to produce.
In my view, the Rust argument is more like that driving (in C) can not possible be safe because there is always the inherent risk of steering into an obstacle, so we have to abandon it completely and only use the local public rail system (which entirely eliminate this class of steering errors). But this is argument made based on the state of the technology in 1950s without considering that seatbelts and other modern techniques, driver tests, speed limits can make driving a lot safer (as seen today when compared to the 1950s).

Seatbelts are more comparable to activating bounds checking in C compared to switching to another language. because they are a minor inconvenience with a huge positive security effects, but do not eliminate all risk. Rust is more like switching to public rail system, because it does eliminate certain risks completely (all related to steering), but not others, and then also limits you in various way, so you may still need to use a car for the final meters (e.g. C or "unsafe" Rust).

And this comparison is consistent with the idea that the public rail system really is safer to use with regard to traffic accidents, so captures the idea that Rust actually has safety benefits. But IMHO the framing and marketing is highly misleading.

how does rust limit you? it seems to be one of the most versatile languages ever. it's genuinely used for everything from the linux kernel to webservers, desktop and mobile apps, even frontend ui in the browser. no other language has that usage (maybe swift?). saying rust is a rail system and c is a car makes zero sense, if anything rust is a flying car because it is used in situations where c is not, whereas rust is used everywhere c is used.

any serious engineering discipline eliminates the possibility of human error wherever possible, especially when it results in dangerous effects. and yet in software there are people who prefer exposing others to those dangerous effects because of a personal preference for a 50 year old tool.

This argument is cope.

In theory, that could be possible. In practice, there have been many many case studies demonstrating the opposite and not that many case studies demonstrating in favor of your argument.

e.g. Cloudflare replaced Nginx with Pingora: https://blog.cloudflare.com/how-we-built-pingora-the-proxy-t...

> With those assurances we can focus more on how a change to our service will interact with other services or a customer's origin. We can develop features at a higher cadence and not be burdened by memory safety and hard to diagnose crashes.

> When crashes do occur an engineer needs to spend time to diagnose how it happened and what caused it. Since Pingora's inception we’ve served a few hundred trillion requests and have yet to crash due to our service code.

> In fact, Pingora crashes are so rare we usually find unrelated issues when we do encounter one. Recently we discovered a kernel bug soon after our service started crashing. We've also discovered hardware issues on a few machines, in the past ruling out rare memory bugs caused by our software even after significant debugging was nearly impossible.

The CVE counts for new parts of the Linux kernel written in Rust are much lower than the (recent) CVE counts for even mature, years old parts of the Linux kernel written in C, to say nothing of the historical record.

There is basically no meaningful part of the kernel written in Rust from which one could conclude this. There is now binder, but this was only recently merged and I am not sure what data there is about it (and how it would compare to new C code written with a focus on memory safety).