News for hackers. Stuff that matters.
Re:Simple Linux kernel memory corruption bug can lead to com... by chc4 on Wednesday October 20, 2021 @01:39AM (#28927143)
Rust would help with bugs like the initial memory unsafety. Half the blog post is about resilience even in the face of memory unsafety though, especially since the entire point is that there only has to be one bug, in any legacy subsystem, to exploit the entire kernel. Using Rust doesn't magically add any of those defense-in-depth mitigations and pessimistic sanity checks.
Re:Simple Linux kernel memory corruption bug can lead to com... by lmm on Wednesday October 20, 2021 @05:10AM (#28928481)
Resilience is impossible in C-family languages, given undefined behaviour. Any defence-in-depth checks you add can only be triggered once you're already in an undefined state, so the compiler will helpfully strip them out (this has already happened in Linux and is the reason they build with -fno-delete-null-pointer-checks, but C compilers have very little appetite for broadening that kind of thing).
Re:Simple Linux kernel memory corruption bug can lead to com... by IshKebab on Wednesday October 20, 2021 @05:17AM (#28928527)
That seems like a weird way to do it. Wouldn't it be better to have compile errors if the compiler figures out that it can remove a null check?
Re:Simple Linux kernel memory corruption bug can lead to com... by flohofwoe on Wednesday October 20, 2021 @06:17AM (#28928927)
The "inconvenient truth" with Undefined Behaviour is that it provides essential wiggle room for the compiler to implement some optimizations that wouldn't be possible with a stricter specification. Of course the downside is that sometimes the compiler goes too far and removes critical code (which AFAIK is still a hot discussion topic how much compilers should be allowed to exploit UB for optimizations).
Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @09:52AM (#28930686)
Because that was the only way for C to catch up with stuff that was being done in languages like PL.8.

So compiler optimizers get to take advantage of UB for that last mile optimization, which in a language like C always expect the developer to be a ISO C expert, and when they aren't or are too tired trying to meet project deadlines, surprises happen.

"Oh, it was quite a while ago. I kind of stopped when C came out. That was a big blow. We were making so much good progress on optimizations and transformations. We were getting rid of just one nice problem after another. When C came out, at one of the SIGPLAN compiler conferences, there was a debate between Steve Johnson from Bell Labs, who was supporting C, and one of our people, Bill Harrison, who was working on a project that I had at that time supporting automatic optimization...The nubbin of the debate was Steve's defense of not having to build optimizers anymore because the programmer would take care of it. That it was really a programmer's issue.... Seibel: Do you think C is a reasonable language if they had restricted its use to operating-system kernels? Allen: Oh, yeah. That would have been fine. And, in fact, you need to have something like that, something where experts can really fine-tune without big bottlenecks because those are key problems to solve. By 1960, we had a long list of amazing languages: Lisp, APL, Fortran, COBOL, Algol 60. These are higher-level than C. We have seriously regressed, since C developed. C has destroyed our ability to advance the state of the art in automatic optimization, automatic parallelization, automatic mapping of a high-level language to the machine. This is one of the reasons compilers are ... basically not taught much anymore in the colleges and universities."

-- Fran Allen interview, Excerpted from: Peter Seibel. Coders at Work: Reflections on the Craft of Programming

Re:Simple Linux kernel memory corruption bug can lead to com... by lmm on Wednesday October 20, 2021 @08:44PM (#28938825)
It's not "essential". On realistic code it's single-digit percentages at most. But it's essential for winning compiler benchmarks, so you'll never get C compilers to stop doing it.
Re:Simple Linux kernel memory corruption bug can lead to com... by rcxdude on Wednesday October 20, 2021 @05:50AM (#28928757)
You would have a huge number of false positives, because if you're doing a bunch of null checking defensively you're going to be doing it redundantly a lot.
Re:Simple Linux kernel memory corruption bug can lead to com... by IshKebab on Wednesday October 20, 2021 @06:34AM (#28929053)
Right, but if the compiler has proved that you don't need those null checks then you can simply remove them. If you think you do need them then it's a sign you've screwed up somewhere and should fix it!
Re:Simple Linux kernel memory corruption bug can lead to com... by DSMan195276 on Wednesday October 20, 2021 @09:45AM (#28930602)
The problem is that it's not that simple. A NULL check might only become redundant after various rounds of inlining and optimizing, and the same NULL check could be redundant in one usage and necessary in the other. It's also very likely that changes to other parts of the code will make a previously 'redundant' NULL check now necessary, and obviously you're unlikely to get a warning in that direction.
Re:Simple Linux kernel memory corruption bug can lead to com... by _flux on Wednesday October 20, 2021 @06:48AM (#28929151)
> Right, but if the compiler has proved that you don't need those null checks then you can simply remove them.

This can be the case now, but then later someone adds new code that you did need that null check.

> If you think you do need them then it's a sign you've screwed up somewhere and should fix it!

Hm, so instead of

> Wouldn't it be better to have compile errors if the compiler figures out that it can remove a null check?

you wanted the opposite: warn when a null check is there and was actually required :).

Not sure if this is a working solution either. Maybe if it was behind a macro, JUST_CHECKING_IF_NULL(x)..

Re:Simple Linux kernel memory corruption bug can lead to com... by IshKebab on Wednesday October 20, 2021 @08:48AM (#28930007)
Yeah sounds like the best solution is explicit checks that the compiler understands - REDUNDANT_NULL_CHECK(...), REQUIRED_NULL_CHECK(...).

I mean obviously the solution is to use a sane language but you know...

Re:Simple Linux kernel memory corruption bug can lead to com... by vlovich123 on Wednesday October 20, 2021 @08:17AM (#28929764)
Did you read the last part of the article? It explicitly says that Rust (or some other kind of languages guarantees) would absolutely remove the need for more complex runtime measures. Additionally, such checks stop the exploit chain early before it’s able to pick up steam.
Re:Simple Linux kernel memory corruption bug can lead to com... by ncmncm on Wednesday October 20, 2021 @12:35PM (#28932758)
It speculates that Rust would help. That is very far from demonstrating that Rust would actually help.

Rust would certainly not help in this instance, because nobody is writing pty handling code in Rust. I.e., using Rust in place B does not help with bugs in place A. Any expectation that Linux would get more secure if some new code were Rust is optimistic to the point of fantasy.

The best possible outcome of allowing Rust in kernel code is that the kernel would not become even more insecure as a result of the added Rust code. That would be good, by itself, even if not what we really want. But whether even that would be achieved in practice is still to be demonstrated.

Re:Simple Linux kernel memory corruption bug can lead to com... by smoldesu on Wednesday October 20, 2021 @01:41PM (#28933546)
The best possible outcome of allowing Rust in kernel code is being able to guarantee type safety, memory safety and perfect concurrency where it's applied. Those 3 pain points are where C fails right now, and it's part of the reason why scheduling on Linux feels 'worse' than Windows or even MacOS at times.
Re:Simple Linux kernel memory corruption bug can lead to com... by ncmncm on Wednesday October 20, 2021 @02:39PM (#28934386)
I.e., exactly what I just said, but longer.
Re:Simple Linux kernel memory corruption bug can lead to com... by vlovich123 on Wednesday October 20, 2021 @08:53PM (#28938899)
I think the point is that as Rust is able to tackle more parts of the kernel, existing code can start to be rewritten in it.
Re:Simple Linux kernel memory corruption bug can lead to com... by atoav on Wednesday October 20, 2021 @02:13AM (#28927343)
But it might remove another hole in the swiss cheese security model, which can be worth it.
Re:Simple Linux kernel memory corruption bug can lead to com... by skavi on Wednesday October 20, 2021 @02:16AM (#28927357)
Do we know what the performance impact of adding all these checks is?
Re:Simple Linux kernel memory corruption bug can lead to com... by habibur on Wednesday October 20, 2021 @02:42AM (#28927518)
Huge. Only checking array bounds on every access degrades performance considerably.

But I am waiting for the Rust-OS to complete -- if one is under construction now. We can check how that stands when released.

Re:Simple Linux kernel memory corruption bug can lead to com... by volta83 on Wednesday October 20, 2021 @04:30AM (#28928195)
> Huge. Only checking array bounds on every access degrades performance considerably.

Citation needed, since all evidence points to the contrary.

Could you please point us to a Rust application (there are hundreds of thousands at this point) that gets noticeably faster when disabling bound checks?

In servo, a whole web browser written in Rust, the cost of doing this was negligible, to the point that it was barely measurable (1-3%, noise levels for such a big app).

Same for Firefox which has a substantial amount of Rust.

Go ahead and give Fuchsia a try. You can enable bound checks for a substantial part of Android's user space and not really notice it.

Same for Redox, or any operating system kernel written in Rust.

You have many large applications to choose from, so please, just point us to 1 for which this is the case.

---

Compared with other mitigations already in the kernel, that can cost you up to 50% perf, and that people seem to be ok with, bound checking all the array accesses seems like a no brainer, given that ~70% of CVE are caused by memory issues.

When most people think about bound checking all array accesses, they think, for some "i can only think inside the box" reason, that this happens on hardware, for every memory access.

But that is not how Rust works. Rust adds bound checks "in Rust", and the Rust compiler and LLVM are really good at removing duplicates, hoisting many bound checks out of a loop into a single bound check at the beginning of the loop, etc.

People also think that this is an all or nothing approach, but Rust allows you to manually access without bound checks and do the hoisting manually. So if you find a function in which this makes a big difference, you can just fix the performance issue there manually.

Re:Simple Linux kernel memory corruption bug can lead to com... by tialaramex on Wednesday October 20, 2021 @05:00AM (#28928415)
For the optimisation, the compiler will even reason that e.g. iterating over the vector necessarily involves knowing the size of the vector and stopping before the end, so it doesn't need to add the bounds check at all because that's redundant. This is easier in Rust because the compiler knows nobody else can be mutating this vector while you're iterating over it - that's forbidden in the language.

So, in general, the idiomatic Rust "twiddle all these doodads" compiles to the same machine code as the idiomatic C++ for that problem, even though Rust bounds checked it and C++ didn't care. Lots of Rust checks are like this, they compile away to nothing, so long as what you did is necessarily correct. The Option<NonZeroU64> stuff a few days ago is another example. Same machine code as a C++ long integer using zero as a signal value, but with type safety.

Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @07:52AM (#28929576)
Same applies when using C++ with bounds checking enabled, but the FUD regarding bounds checking is deep.
Re:Simple Linux kernel memory corruption bug can lead to com... by tialaramex on Wednesday October 20, 2021 @10:07AM (#28930815)
What happens about mutation in the C++ case though? Maybe I should just try it in Godbolt instead of bothering people on HN.
Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @10:15AM (#28930903)
What mutation?

Naturally this only kind of works when everyone on the team goes safety first.

Doing some C style coding will just bork it, similarly to any unsafe block or FFI call in other better suited languages.

But in the subject of making juice with lemons, is way better than plain C.

Re:Simple Linux kernel memory corruption bug can lead to com... by tialaramex on Wednesday October 20, 2021 @01:16PM (#28933247)
Right, so long as there isn't mutation, we're golden, which is why the machine code is the same.

This is, after all, why Godbolt was first invented as I suspect you know (Matt Godbolt wondered if C++ iterators really do produce the same machine code as a hand-rolled C-style for loop, and rather than just trust an expert he built the earliest Compiler Explorer to show that yes, with real C++ code you get the same machine code, any time spent hand-rolling such loops is time wasted)

Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @03:51PM (#28935408)
Yeah, but since there are domains where C++ is unavoidable, this is the best we can do.

By the way, this should be a nice update about the state of affairs on Android (I am yet to watch it).

"Improving Memory Safety in Android 12 Using MTE"

https://devsummit.arm.com/en/sessions/57

Re:Simple Linux kernel memory corruption bug can lead to com... by tialaramex on Wednesday October 20, 2021 @07:49PM (#28938414)
I don't understand what you mean by "domains where C++ is unavoidable" in this context. C++ is a choice, presumably usually a reasonable choice, but a choice, so if they wanted to people could avoid it.

Memory tagging (which is what MTE is about) reminds me of ASLR and password entropy requirements. They're slightly raising the bar which is not something I have much time for. I prefer to put the effort in to solve problems permanently so I can worry about something else instead. Whether that's a practical opportunity here is unclear though, and I think Rust is a big part of finding out.

Re:Simple Linux kernel memory corruption bug can lead to com... by Measter on Wednesday October 20, 2021 @09:25AM (#28930372)
I did once have a bizarre situation where removing a bounds check that always succeeded degraded performance by over 30%.

The bounds check wasn't being elided either. I checked and it was there in the assembly, so I figured that the function is so hot that an unchecked access might help things. Apparently not. The only thing I can think of is that the reduction in code-size for that function had an unintended effect elsewhere, either for the optimizer or that it resulted in a hot bit of code crossing a cache line?

Re:Simple Linux kernel memory corruption bug can lead to com... by rini17 on Wednesday October 20, 2021 @04:26PM (#28936002)
Or the always succeeding check helped CPU's branch predictor substantially.
Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @04:54AM (#28928360)
I have used C++ since 1993 with bounds checking enabled, it hardly has ever mattered.

The very few cases where it actually mattered for project delivery acceptance, were proven with a profiler, and fixed on those single cases only.

Most of the time it is just cargo cult taken from C into other languages.

Multics had a better DoD security profile assessment than UNIX, thanks to PL/I being bounds checked by default.

Mac OS used Object Pascal until they decided to switch to C++ around 1992, it also hardly impacted their sales, using a language with bounds checking.

Re:Simple Linux kernel memory corruption bug can lead to com... by throwaway81523 on Wednesday October 20, 2021 @03:56AM (#28927982)
> Huge. Only checking array bounds on every access degrades performance considerably.

I have not found this, at least in application code. There is usually at most a few percent different between v[i] and v.at(i) (the latter checks bounds) with C++ std::vector, for example. So I almost always use .at() these days, and it does catch bugs.

Re:Simple Linux kernel memory corruption bug can lead to com... by scns on Wednesday October 20, 2021 @04:19AM (#28928123)
Well, there is the rub. The safe thing to do is more verbose, the unsafe way is in muscle memory. Rust did it the other way around deliberately. But that is easy if you do a new design and don't need to retrofit a safe solution. No snark intended.
Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @09:54AM (#28930712)
That is why one should always enable the compiler switches that turn operator[]() into at(), and then only disable them on case by case scenario, if proven worthwhile to do so.
Re:Simple Linux kernel memory corruption bug can lead to com... by gpderetta on Wednesday October 20, 2021 @04:42AM (#28928290)
wouldn't compiling with _GLIBCXX_ASSERTIONS or the corresponding for your compiler of choice be a better solution? It will also catch quite a few more issues (dereferencing null smart pointers, empty optionals, etc.), while being still relatively lightweight.
Re:Simple Linux kernel memory corruption bug can lead to com... by throwaway81523 on Wednesday October 20, 2021 @05:07PM (#28936634)
Thanks, I didn't know (or didn't remember) about this, but it's not clear from the docs that it bounds checks []. I don't find it difficult to use .at(). I'll try the debug mode too, but when I bother writing something in C++ it's usually because I actually care about its speed, so I don't want the overhead to be too bad.

https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros...

Re:Simple Linux kernel memory corruption bug can lead to com... by pjmlp on Wednesday October 20, 2021 @07:54AM (#28929591)
Not the OP, that is my approach, keep on the bounds checking settings from VC++ also in release builds.

And before STL was a thing, all the custom types I had were bounds checked by default.

Re:Simple Linux kernel memory corruption bug can lead to com... by fabianhjr on Wednesday October 20, 2021 @02:59AM (#28927623)
AFAIK RedoxOS has been bootable for a while now. (Though, a very simple new OS)

https://www.redox-os.org/

[dead]
Re:Simple Linux kernel memory corruption bug can lead to com... by scns on Wednesday October 20, 2021 @04:29AM (#28928187)
I have a problem with the classification of traits as mental disorders, which may be a huge boon in the right situation. A friend of mine could be classified as compulsive/obsessive. He works as an airplane mechanic. I would rather ride a plane that he worked on, than his "normal" colleague, who talked to someone else while refilling a tank with pure oxygen, walking away and having his arm catch fire from a static discharge. No snark intended.
Re:Simple Linux kernel memory corruption bug can lead to com... by okamiueru on Wednesday October 20, 2021 @03:14AM (#28927707)
I'm sure if that was the management attitude that would have welcomed them, it is a win-win situation.
Re:Simple Linux kernel memory corruption bug can lead to com... by bbarnett on Wednesday October 20, 2021 @03:23AM (#28927764)
Employers don't need zealots or evangelists, they need realists, and people ready to work.

Not prattle on endlessly about the latest fad.

Rust has some pluses. Yet the evangelism, with the "it fixes everything" lunacy circulating, taints rust, makes legitimate and sane advocates look like nutjobs.

I don't have the time to sort the wheat from the chaff, so when I see a big deal made about rust on a resume, odds are it's a zealot, and into the bin with 'em.

Re:Simple Linux kernel memory corruption bug can lead to com... by okamiueru on Wednesday October 20, 2021 @03:35AM (#28927835)
You are expressing widely different things though. You said you would consider out right rejecting someone and question their mental health for having rust on their resume.

Having a tool on a resume, or listing experience with tools, should certainly not be interpreted as someone being a rust zealot, evangelist, "pratting on endlessly", and all the rest of the examples you gave. So, maybe you initially wrote something different to what you actually meant.

[dead]
Re:Simple Linux kernel memory corruption bug can lead to com... by okamiueru on Wednesday October 20, 2021 @04:09AM (#28928057)
I'm not sure to what extend you are being facetious, so I'll take it at face value. Rust doesn't particularly attract "crazies", and nor are software developers mostly crazies. So, I believe your criteria is exceptionally bad at filtering those kinds of developers out. Hiring good people is challenging enough as it is without doing the job poorly. My advice, unwarranted as it is, is to revise your preconceptions.
Re:Simple Linux kernel memory corruption bug can lead to com... by Azsy on Wednesday October 20, 2021 @06:37AM (#28929084)
Obviously the top comment is dumb, but please keep on doing this.

Nobody is going to be happy if you hire someone who knows rust.

> "As a shortcut for filtering out new people and ideas, i will filter them on the most annoying person that has tried them".

At least your partially honest with how many divergent ideas someone working with you is allowed to have.

Re:Simple Linux kernel memory corruption bug can lead to com... by throwaway81523 on Wednesday October 20, 2021 @03:58AM (#28927992)
I think that says more about you than it does about the rusters.
Re:Simple Linux kernel memory corruption bug can lead to com... by kwertyoowiyop on Wednesday October 20, 2021 @08:40AM (#28929944)
Certain people didn’t appreciate your sense of humor! :-)
Re:Simple Linux kernel memory corruption bug can lead to com... by andy_threos_io on Wednesday October 20, 2021 @10:25AM (#28931002)
+1000
Re:Simple Linux kernel memory corruption bug can lead to com... by vadfa on Wednesday October 20, 2021 @03:44AM (#28927895)
>It's almost at the point, where if I see rust on a resume, I'll figure the dev has a mental disorder and skip them.

I figured that one out when I tried to join the rust discussion server on discord and saw the server photo.

Re:Simple Linux kernel memory corruption bug can lead to com... by Cryptonic on Wednesday October 20, 2021 @02:41AM (#28927510)
Well, denialists often think that the normal guys have mental disorders. The Rust kernel will come one day. Not doing it in the face of todays massive cyber security threads is madness. Even Windows and MacOS will be rewritten in Rust Ahahahahahahahahhahddahhadad runs in circles
Re:Simple Linux kernel memory corruption bug can lead to com... by kwertyoowiyop on Wednesday October 20, 2021 @09:00AM (#28930116)
After we have rewritten everything in Rust, we will also have to delete all code, stored anywhere, that was written in C/C++. Storing such code will be considered a Thought Crime and punished by exile to the Radioactive Wastelands.