News for hackers. Stuff that matters.
Re:sudo and su Being Rewritten in Rust for Memory Safety by zh3 on Saturday April 29, 2023 @01:33PM (#35755087)
This seems worthwhile at first sight; another implementation (in a different language) gives us more choice and time will tell on the CVE count:user ratio.
Re:sudo and su Being Rewritten in Rust for Memory Safety by anthk on Saturday April 29, 2023 @01:46PM (#35755251)
Find an error on the Rust runtime and then the whole security collapses down as a house of cards.

It's bad to think on security by just using a language.

Re:sudo and su Being Rewritten in Rust for Memory Safety by smt88 on Saturday April 29, 2023 @02:00PM (#35755386)
No one is saying they should switch languages and stop all other security work.
Re:sudo and su Being Rewritten in Rust for Memory Safety by hulitu on Saturday April 29, 2023 @02:01PM (#35755404)
No need for errors. Just a compromised package on crates.io.

It's funny how rust is praised as secure without any code audit.

Re:sudo and su Being Rewritten in Rust for Memory Safety by iknowstuff on Saturday April 29, 2023 @02:12PM (#35755514)
Yeah your single header libs from pastebin get so many audits by comparison.

https://github.com/RustSec/rustsec/tree/main/cargo-audit

https://mozilla.github.io/cargo-vet/

Besides, every dependency is locked.

Re:sudo and su Being Rewritten in Rust for Memory Safety by haswell on Saturday April 29, 2023 @02:21PM (#35755599)
Security means many things, and supply chain vulnerabilities are just one of many factors to evaluate when considering languages.

Rust improves or eliminates some issues, but that does not imply that other issues are magically solved.

Re:sudo and su Being Rewritten in Rust for Memory Safety by fnordpiglet on Saturday April 29, 2023 @02:37PM (#35755757)
I don’t think people generally say secure, they say safe. Safe is necessary but insufficient for secure. The existing implementations assume safety by diligence. Rust promises safety by construction. That’s useful. But, to your point, insufficient. People that say secure when they mean safe are just wrong.
Re:sudo and su Being Rewritten in Rust for Memory Safety by lalaithion on Saturday April 29, 2023 @01:56PM (#35755348)
I mean, the same is true with the C runtime.
Re:sudo and su Being Rewritten in Rust for Memory Safety by ittan on Saturday April 29, 2023 @02:03PM (#35755433)
Isn't "C Runtime" inaccurate?

Wouldn't it be the static or dynamic linked libraries for the particular program in question?

Re:sudo and su Being Rewritten in Rust for Memory Safety by pjmlp on Saturday April 29, 2023 @02:08PM (#35755483)
Nope, what do you think calls into main(), does floating point emulation, handles signals on non UNIX platforms, provides threading support?
Re:sudo and su Being Rewritten in Rust for Memory Safety by dahfizz on Saturday April 29, 2023 @03:01PM (#35755973)
The term "runtime" is overloaded here. The C runtime is not what people usually mean when they say a language has a runtime.

There is a crt.0 "C Runtime" object. This is code that is literally run "at runtime". When you execute a binary, the C runtime is the first thing executed to setup the stack and call main().

This is just a bit of assembly that runs before main(). It shares ~nothing in common with "runtime" languages like Python or Java where the runtime is alive during the whole program's execution.

The C run time does not handle floats or threads or anything like that. Software floats are dealt with by the compiler and threading is implemented as its own library (either in userspace or built into the kernel).

Re:sudo and su Being Rewritten in Rust for Memory Safety by pjmlp on Saturday April 29, 2023 @03:41PM (#35756375)
I guess you can educate Microsoft on that then.

https://learn.microsoft.com/en-us/cpp/c-runtime-library/c-ru...

It doesn't matter what people think, rather the CS point of view of a language runtime is.

That library is the runtime.

Re:sudo and su Being Rewritten in Rust for Memory Safety by lanstin on Saturday April 29, 2023 @04:39PM (#35756931)
Libraries and crt0.o and the like. Libgcc_s ; but it isn’t a runtime in the sense that some magic is doing GC or scheduling for routines. ABI that describes what the assembly should be doing, it isn’t a thing doing stuff.
Re:sudo and su Being Rewritten in Rust for Memory Safety by pjmlp on Saturday April 29, 2023 @05:10PM (#35757229)
Runtime is whatever a programming language needs to support its execution, as per CS compiler theory.
Re:sudo and su Being Rewritten in Rust for Memory Safety by dahfizz on Saturday April 29, 2023 @03:07PM (#35756051)
There is a code object called "C Runtime" (crt0.o)[1].

This was a good name at the time. Its a bit of code that gets executed literally "at runtime". When you run a program, this object gets invoked to setup the stack and call main(). Its just a bit of assembly.

Then, decades later, languages like Java overloaded the term "runtime" to refer to their interpreter / vm. This causes confusion to this day, evidently.

[1] https://en.wikipedia.org/wiki/Crt0

Re:sudo and su Being Rewritten in Rust for Memory Safety by hulitu on Saturday April 29, 2023 @02:02PM (#35755414)
> I mean, the same is true with the C runtime.

My c compiler does not connect to internet during compiling.

Re:sudo and su Being Rewritten in Rust for Memory Safety by overthrow on Saturday April 29, 2023 @02:31PM (#35755695)
Nor does the Rust compiler.

Rust's build system, Cargo, does however. And many C build systems do as well, e.g. https://cmake.org/cmake/help/latest/guide/using-dependencies...

Re:sudo and su Being Rewritten in Rust for Memory Safety by steveklabnik on Saturday April 29, 2023 @03:05PM (#35756025)
Optionally. Cargo doesn’t have to connect to the internet, and even has command line switches to fail if it tries to.
Re:sudo and su Being Rewritten in Rust for Memory Safety by hulitu on Saturday April 29, 2023 @04:39PM (#35756927)
Good to know.
Re:sudo and su Being Rewritten in Rust for Memory Safety by hulitu on Saturday April 29, 2023 @04:39PM (#35756924)
Thank you for the tip. I shall do

ifconfig eth0 down

before compiling to avoid such issues.

Re:sudo and su Being Rewritten in Rust for Memory Safety by some_furry on Saturday April 29, 2023 @02:07PM (#35755463)
What do you do if a dependent .so isn't found?

Do you not have to install said dependency from the Internet and start (at least part of) the compile over?

Re:sudo and su Being Rewritten in Rust for Memory Safety by MattPalmer1086 on Saturday April 29, 2023 @02:48PM (#35755849)
Rust doesn't have a runtime.

Nobody is suggesting that a language solves all security issues.

It does have much better memory safety than C, which is the cause of the majority of security issues.

Re:sudo and su Being Rewritten in Rust for Memory Safety by duped on Saturday April 29, 2023 @03:07PM (#35756048)
Rust has a minimal runtime (0), and links to libc by default which brings in the libc runtime (so it's not like C is any better). Except that the Rust runtime is written in Rust, which is nice for memory safety.

(0) https://prev.rust-lang.org/en-US/faq.html#does-rust-have-a-r...

Re:sudo and su Being Rewritten in Rust for Memory Safety by MattPalmer1086 on Saturday April 29, 2023 @03:12PM (#35756104)
Well, opinions in the Rust community clearly differ:

"Rust is blazingly fast and memory-efficient: with no runtime or garbage collector" [0]

I guess it depends on what you mean by a runtime. Panic handlers and initialisation code is a pretty small runtime.

[0] https://www.rust-lang.org/

Re:sudo and su Being Rewritten in Rust for Memory Safety by samus on Saturday April 29, 2023 @03:14PM (#35756121)
Even if there are error, the impact of each error would not be higher than if it occurred in libc or any other language runtime.
Re:sudo and su Being Rewritten in Rust for Memory Safety by 3a2d29 on Saturday April 29, 2023 @02:11PM (#35755502)
Yeah agree with this, will be interesting to see.

I assume the more unsafe rust used, the more the CVE numbers will appear like C and C++. People like to say unsafe means "I checked this and this is fine, compiler" and isn't a bad thing but I feel that's inaccurate since the whole point of rust is that people struggle to write safe code even when they are really checking. I feel unsafe rust is way more "I really hope this is right, but I have minimized it to just this area out of necessity, since it likely isn't."

I would like to see how much CVEs go down over time. The fact sudo is being rewritten suggests that even after long periods of use, security issues popping up is still a common-ish problem?

Re:sudo and su Being Rewritten in Rust for Memory Safety by arp242 on Saturday April 29, 2023 @03:11PM (#35756093)
> security issues popping up is still a common-ish problem?

It seems to average out at a bit over 1 per year over the last 20 years, based on [1]; is that "a lot"? I guess?

It's worth pointing out that while there certainly are memory-related C-style issues, quite a few are logic errors because all of this is rather subtle once you start adding features beyond what e.g. "doas" does. For example the recent "Sudoedit can edit arbitrary files"[2] is a somewhat subtle interaction between sudoedit, environment variables, and flag parsing. Previously there was [3] and [4] from 2004 and 2010.

Will memory safety be a benefit? Of course it will. But I think these kind of issues are the real challenge here. A drop-in replacement for "sudo" is useful, but I have to wonder if it wouldn't be better to rethink the approach from first principles, taking 40 years of sudo lessons in to account. It's also surprisingly easy to shoot yourself in the foot with a wrong sudoers file, which is not strictly a security issue in sudo as such but also something that can probably be improved on?

That 2023 sudoedit bug has been in sudo since 1.8, released in 2011, and Todd has been maintaining sudo since 1994, and he's actually pretty good as well as experienced with this kind of stuff. Yet he still missed it, as did everyone else, for well over ten years. It seems there are far more structural problems in the entire approach that go well beyond "C is not memory safe". That's certainly an issue, but in a way seems almost banal compared to the deeper issues.

[1]: https://www.sudo.ws/security/advisories/

[2]: https://www.sudo.ws/security/advisories/sudoedit_any/

[3]: https://www.sudo.ws/security/advisories/sudoedit_escalate2/

[4]: https://www.sudo.ws/security/advisories/sudoedit/

Re:sudo and su Being Rewritten in Rust for Memory Safety by duped on Saturday April 29, 2023 @03:17PM (#35756147)
That's a really good point that I feel like isn't talked about enough. Unsafe rust is a lot harder to write correctly than bog standard C, because you have to uphold the invariants to avoid undefined behavior (1). It's why there's a whole ebook about it (2).

That doesn't mean it's impossible to write correct unsafe code, it's just not as obvious as "trust me bro I know better than borrowck." You can't actually elide the invariants Rust upholds, you just have to take over from the compiler when it can't prove them.

(1) https://doc.rust-lang.org/reference/behavior-considered-unde...

(2) https://doc.rust-lang.org/nomicon/

Re:sudo and su Being Rewritten in Rust for Memory Safety by snovv_crash on Saturday April 29, 2023 @03:47PM (#35756457)
Another critical consideration of this is that if you make a mistake in unsafe rust code it could manifest itself as a 'bug' in the 'safe' rust code due to invariants that the safe code depends on not being upheld. It is literally undefined behaviour, in the "rm -rf / and insult your mother" sense.
Re:sudo and su Being Rewritten in Rust for Memory Safety by lamontcg on Saturday April 29, 2023 @04:18PM (#35756741)
Why would sudo/su need a lot of tricky unsafe code?
Re:sudo and su Being Rewritten in Rust for Memory Safety by AnIrishDuck on Saturday April 29, 2023 @05:31PM (#35757408)
Using grep, it looks like they mostly use unsafe code to interface with existing C libraries. In those cases it's roughly as tricky as writing C in the first place IMO, so still probably a net win.
Re:sudo and su Being Rewritten in Rust for Memory Safety by Gigachad on Sunday April 30, 2023 @12:20AM (#35759662)
So over time we can trim this down as more C libraries are upgraded to Rust.
Re:sudo and su Being Rewritten in Rust for Memory Safety by ChancyChance on Saturday April 29, 2023 @02:19PM (#35755574)
How would I find the CVE's on sudo/su? I opened up mitre.org and cve.org, but searches for sudo/su brought up hundreds of issues (or more), and most of them were not about sudo/su. (It's a bit like searching for "The The"'s music on early Google.)
Re:sudo and su Being Rewritten in Rust for Memory Safety by arp242 on Saturday April 29, 2023 @02:33PM (#35755721)
There's [1], which I think is comprehensive from 2001 up to today.

[1]: https://www.sudo.ws/security/advisories/