Live data from Hacker News

Rust for Embedded Systems: Current state, challenges and open problems

arxiv.org

61–70 of 159 posts

Re: Rust for Embedded Systems: Current state, challenges and open problems

#61

Earlier quoted context omitted.

>the people comfortable with the language are all the ones that don't know about the problems. Or the ones writing code where security doesn't matter, like HFT and video games (the former have no users, and the latter are basically impossible to make crack-resistant even if they're written entirely in Rust).

Complicated video games, especially ones with transactions or multi-player aspects, require a lot more security code than you might expect.

Is video game security an entire subfield of its own? I imagine there are categories of exploits in video games which simply don’t exist in other areas of software

Re: Rust for Embedded Systems: Current state, challenges and open problems

#62
post #59

Earlier quoted context omitted.

> 2. there are tools to convert c to rust (I dont know if I'd trust this..) The core C specification by itself isn't all that complicated of a language; a C-to-Rust transpiler is a pretty doable project. The main issues here are that a) a lot of the code you'd likely want to convert is likely to be reliant on non-standard extensions b) there's a lot of undefined behavior which you probably want to have somewhat more…

> C-to-Rust transpiler is a pretty doable project. It's been done, but what comes out is terrible Rust. Everything is unsafe types with C semantics. An intelligent C to Rust translator would be a big win. You'd need to annotate the input C with info about how long arrays are and such, to guide the translator. It might be possible to use an LLM to analyze the code and provide annotations. Usually, C code does have arr…

> It's been done, but what comes out is terrible Rust. Everything is unsafe types with C semantics.

The idea behind the current c2rust tool is that you'd do a one-shot conversion to Rust and then gradually do refactoring passes over the barely-Rust code to convert it to correct C code. The focus is on preserving semantics of C over writing anything close to idiomatic (cue a + b being translated to a.wrapping_add(b) all the time, e.g.). Which is an approach, but I'm not sure it ends up providing any value over "set your system to compile both C and Rust into a final image and then slowly move stuff from the C to the Rust side as appropriate" in practice.

> Usually, C code does have array length info; it's just not in a form that the language ties to the array itself.

This is actually why C23 made VLA support semi-mandatory: it enables you to describe a function signature as

  int write_to_device(size_t len, char buf[len])
and C23 compilers are required to support that, even in absence of full VLA support! The intent of making this support mandatory was to be able to use that as a basis for adding better bounds-checking support to the language and compilers. (Although, as you noticed, there is an order-of-declarations issue compared to the typical idiomatic expression of such APIs in C, and the committee has yet to find a solution to that).

Re: Rust for Embedded Systems: Current state, challenges and open problems

#63

Earlier quoted context omitted.

Complicated video games, especially ones with transactions or multi-player aspects, require a lot more security code than you might expect.

Is video game security an entire subfield of its own? I imagine there are categories of exploits in video games which simply don’t exist in other areas of software

Yes. Basically cheats and anti-cheats became their own thing security-wise and huge amounts of effort are spent (by both sides) on this cat and mouse game.

Although both cracking (as in "software cracking") and cheats were very similar security fields back in the day (both boiled down to reverse engineering) cheating has diverged enough (due to modern anti-cheats and anti-piracy becoming very different countermeasures) that I'd consider them vastly different nowadays.

Some categories of exploits unique to games:

- Aim hacking (pointing the mouse cursor to enemy heads)

- Recoil/spread cheats (mouse compensating for weapon recoil or bullet spread)

- Botting/botfarming (playing resource-intensive games automatically)

- Wallhacking (showing players through walls, or making walls semi transparent)

- Miscellaneous passive assistance (like overlaying a predicted path for a ball in a game, drawing precise location for footsteps/other player sounds, etc.)

- Modification of game state (like sending your character's position at will, allowing you to fly or go through walls)

Some of these have analogues in app security:

- Botting detection is probably very similar in both MMOs and CloudFlare)

- Hidden information is not very different from what we do in web apps (only send the state that the client needs and has access to)

- Preventing game state modification is solved by having a strongly authoritative server (again pretty normal in app land)

But even in those, what makes games very unique compared to other apps is that they're hard real time: you have hard requirements for each frame time; it's expensive to calculate in-server all things that a player should be able to see every single frame; packets take time to travel over the internet so you have to give it some slack (or enemies could pop out of nowhere when crossing doors); client sometimes needs information that you'd like to remain private (you need player positions even behind walls to provide 3D sounds)...

Modern anticheats usually resort to just scanning the memory for running cheats, trying to detect a cheat reading/modifying the game memory, etc. but cheats have come to great lengths like having actual cheat hardware (DMA devices on PCIe[0]) that cannot be detected since it's running outside of the computer software.

[0] https://blog.esea.net/esea-hardware-cheats/

Re: Rust for Embedded Systems: Current state, challenges and open problems

#64
I've been trying out embassy-rs and what is really exciting that you might get RTOS abilities, without actually using an RTOS. Just native Rust, with some smart abstractions. Still prefer C, but the Rust embedded community seems to be cooking up something very interesting.

Re: Rust for Embedded Systems: Current state, challenges and open problems

#65
post #48

The paper may be Rust specific, but I found the CVE break down chart on p. 25 interesting. When looking at the percentages of the CVE causes (focused on the 59 bugs classified as those Rust prevents) I got the following: Out of Bounds Reads => 18.6%; Out of Bounds Writes => 62.7%; Null-Ptr Deref => 8.5%; Use-After-Free => 5.1%; Type Confusion, Uninitialized Pointer Access, Memory Leak => EACH 1.5%; I have to wonder a…

A bounds-checked slice type would be a relatively small addition to C, and if adopted, it would make size tracking and bounds checking easier. However, there's generally a strong pushback from C developers against features that have an unnecessary performance overhead. Having reliable bounds checking without run-time cost if a much more complicated problem. Rust uses iterators for this, but that requires generics and…

To be clear, I don't think there is any hope of implementing any protections at the language level in C, the push back would be exceptionally fierce. Although I do agree that a 'slice' type in the stdlib would not be to much to ask for.

My comment was more for consideration in the design of new languages, in particular, the development of the frequently cited as not existing, simple, C-like language with memory safety features. In that case, in a green field scenario, there are a few ways to achieve statically known memory-boundary respecting iteration and general access. Further, there are several existing methods of achieving 'generics'. The real design challenge would be in finding the simplest implementation that does not overly burden potential developers.

I am confident that it could be done, but it would take some grave dissatisfaction with Rust (which is currently at the top of the adoption curve in the memory safe, but GC free space) for the proposed language to take off.

Re: Rust for Embedded Systems: Current state, challenges and open problems

#66
post #59

Earlier quoted context omitted.

> C-to-Rust transpiler is a pretty doable project. It's been done, but what comes out is terrible Rust. Everything is unsafe types with C semantics. An intelligent C to Rust translator would be a big win. You'd need to annotate the input C with info about how long arrays are and such, to guide the translator. It might be possible to use an LLM to analyze the code and provide annotations. Usually, C code does have arr…

> It's been done, but what comes out is terrible Rust. Everything is unsafe types with C semantics. The idea behind the current c2rust tool is that you'd do a one-shot conversion to Rust and then gradually do refactoring passes over the barely-Rust code to convert it to correct C code. The focus is on preserving semantics of C over writing anything close to idiomatic (cue a + b being translated to a.wrapping_add(b) a…

> The idea behind the current c2rust tool is that you'd do a one-shot conversion to Rust and then gradually do refactoring passes over the barely-Rust code to convert it to correct C code.

I've seen what comes out of the transpiler. Nobody should touch that code by hand. It's awful Rust, and uglier than the original C. Modifying that by hand is like modifying compiler-generated machine code.

> This is actually why C23 made VLA support semi-mandatory.

C23 doesn't actually use that info. You can't get the size of buf from buf. I proposed something like that 12 years ago.[1] But I wanted to add enough features to check it.

[1] http://animats.com/papers/languages/safearraysforc43.pdf

Re: Rust for Embedded Systems: Current state, challenges and open problems

#67

Earlier quoted context omitted.

The C and C++ ecosystems are suffering from a selection effect, in that the people that have any concern about their code being correct are trying to drop them, while the people comfortable with the language are all the ones that don't know about the problems. I expect the careless unaware culture to get worse with time as more and more aware people manage to leave it.

>the people comfortable with the language are all the ones that don't know about the problems. Or the ones writing code where security doesn't matter, like HFT and video games (the former have no users, and the latter are basically impossible to make crack-resistant even if they're written entirely in Rust).

Others have corrected you about gaming; I would point out that for HFT if you write a memory error, you are reasonably likely to encounter it because of the sheer number of swings of the stick you get at hitting the bug. And if that code's concurrent at all, and it probably is, it had even moreso better get it right. You do not want to discover memory errors at run time.

I'd bet HFT has already got all the best static analysis money can buy, not that they're cowboying it more than anybody else.

Memory safety isn't just about "security". Sure, that's a huge issue, but it's also about not spending a month debugging why the login fails one out of a thousand logins because the user's password gets replaced by what seems to be a pointer, but one that doesn't point at anything, starting with the 5th character, or why your HFT code should have ordered 10,000 shares but instead ordered a pointer's worth of shares, or why the second level crashes after precisely the 1023rd frame with completely incomprehensible errors, or any number of other things.

I do not know why any sane developer that has worked through such a thing even once would be willing to entertain the notion of programming without it if it weren't utterly forced on them. I enjoy reading such tales of diagnostic heroism; I don't enjoy being in them anywhere near as much as some programmers apparently do.

Re: Rust for Embedded Systems: Current state, challenges and open problems

#68

These are all real issues with Rust, though it's worth noting that many of the integration challenges mentioned also apply to external code written in C and C++. Some of the survey responses highlight one of the biggest hurdles to rust adoption I've experienced though: Rust has an education problem. People dramatically overestimate the correctness of their [C/C++] code and underestimate the potential severity of fail…

> People dramatically overestimate the correctness of their [C/C++] code

Genuinely interested: what do people think of their tons of third-party dependencies in Rust? My experience building Rust projects is that there are orders of magnitudes more dependencies than what would make me comfortable. At least in C/C++ it's much harder to get there.

Re: Rust for Embedded Systems: Current state, challenges and open problems

#69
post #50
post #43

Earlier quoted context omitted.

Not really. The semantics as you cross the boundary are ill-defined. And you will pay dearly if the C library wants to own any of the resources (like an event loop). And "unsafe" programming in Rust is really difficult to get right--possibly harder than C. To be fair, these problems are not inherent to Rust--any language which tries to interface with C will have them.

>To be fair, these problems are not inherent to Rust--any language which tries to interface with C will have them. Yes, including C.

I guess in that case, at least it's done by a C developer...

Re: Rust for Embedded Systems: Current state, challenges and open problems

#70

Earlier quoted context omitted.

Complicated video games, especially ones with transactions or multi-player aspects, require a lot more security code than you might expect.

Is video game security an entire subfield of its own? I imagine there are categories of exploits in video games which simply don’t exist in other areas of software

The latest in FPS cheating (that I'm aware of, not like I'm super plugged into the underground) involves buying a second PC to run the cheats, a card for your main PC to grab a copy of memory over DMA, ship it off to the second PC, then joining the two video feeds together. Apparently you can also hook your mouse up to a connection where it will edit the data flowing from the mouse to give you better aim as well.

A lot of it is the same as any other sort of security stuff, but like, the tough part is that the adversary has access to the physical machine. In my understanding anyway, not a security expert.

Post reply on HN