3 ms·
Can you expand how this is the case here? Where does the Rust standard library leave a “subtle Posix bug” unpatched?
by littlestymaar 5y ago
Can you expand how this is the case here? Where does the Rust standard library leave a “subtle Posix bug” unpatched?
- pjmlp 5y agoThere are so many, if Rust wants to do it right across the board, then for every POSIX API where the behavior isn't fully specified, they need to provide a correct way. https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap01.html https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd... And if you want a specific example, thread cancelation cannot be wrapped in safe Rust, because many details depend on the actual UNIX is being used. https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_09_21 https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh...
- littlestymaar 5y ago> cannot be wrapped in safe Rust There are a lot of things that cannot be exposed in safe Rust (and that's OK, that's what `unsafe` is made for). There's a big difference between “using this is unsafe, and you must use the `unsafe` keyword and be sure to manually check your invariants” and “oops you used a safe function from the standard library and it was in fact unsafe too bad”.
- pjmlp 5y agoThe safety problem that gets lost, is that the only guarantees safe Rust can offer are related to memory corruption.
- tialaramex 5y agoWe're literally in a thread about a guarantee that Rust kept (but C++ didn't) for filesystem APIs. So "related to memory corruption" is either a deliberately vague statement such that you can count "deleted files you didn't intend" as "memory corruption" or you're missing the true extent of what's offered here. Type safety could also be argued to just be about "memory corruption" but because of the newtype idiom Rust's type safety ensures all sorts of critical things that you wouldn't associate with "memory corruption" as it is ordinarily understood, starting with obvious built-ins like str really being UTF-8 and Saturating<i16> really having saturating arithmetic operations despite only being an ordinary 16-bit integer - but building up to Mutex<Thing> genuinely not letting you access the Thing without taking the Mutex, and GPIO types that reflect the reality that this GPIO is either a PCM device, or it is a serial port, but it by definition is only one thing at a time and must be explicitly switched between them if that's what you want to do.
- pjmlp 5y agoA fake guarantee, because it is impossible to actually enforce it for every filesystem in use. If Rust safety goals is to be dependent typed safety language instead of memory, then quite a few knobs are missing.
- tialaramex 5y ago> A fake guarantee, because it is impossible to actually enforce it for every filesystem in use. For some time now the situation is that a POC exists which works just fine against C++ programs, but no longer works against Rust programs with current Rust. That seems much more like a real guarantee to me than a fake one. > If Rust safety goals is to be dependent typed safety language Rust does not offer full-blown dependent types today, and so far as I know has no plans to do so, although it would be convenient if it was easy (it isn't easy). But (safe) Rust does have working type safety and this already meaningfully makes us safer as I explained already.
- ncmncm 5y agoUntil, of course, a very slightly different POC is coded that works against Rust programs built with current Rust. Erecting a fencepost and expecting attackers to run headlong into the fencepost and knock themselves out is not security. Actual attackers just go around. Again, it is unwise to explain things you do not understand to people who do understand them.
- tialaramex 5y agoOf course, just "a very slightly different POC". And let me guess, because you are "people who do understand them" you could certainly conjure up such a thing, but alas, you just don't have the time right? So, Rust is vulnerable to an imaginary attack that Nathan Myers claims to be able to write, while C++ is vulnerable to an actual attack that we know works. As to the fencepost analogy I will note that Rust fixed the problem a little over a month ago and ever since C++ proponents have been running into that particular fencepost quite certain that the resulting brain damage is proof of just how smart they are for not fixing bugs.
- littlestymaar 5y agoAlmost this, but it's slightly broader: Rust guarantees means you won't hit an undefined behavior in safe Rust (as long as the underlying unsafe Rust is correct, this is an important caveat). This isn't equal to memory corruption, especially because optimizing compilers exist and UB can lead your code to be completely miscompiled (which is both dangerous and really annoying to debug). Also, while this isn't a guarantee, Rust's type system and control flow regarding error handling can help avoid mistakes you sometime see in C (the infamous “goto fail” for instance). Obviously, since C++ is already much more expressive than C, Rust is less of an improvement from C++ in that regard.
- pcwalton 5y agoBut pthread_cancel isn't exposed in the Rust standard library! It's marked unsafe in libc, as it should be.
- pjmlp 5y agoThat is not the reason why it is marked unsafe, rather how the C FFI works on Rust. So now is safety memory safety, or POSIX cross platform semantics safety? Better make your mind what safe actually means in Rust.
- expnkx 5y ago[flagged]
- expnkx 5y ago
- expnkx 5y ago
- expnkx 5y ago
- littlestymaar 5y agothe libc crate exposes functions in Rust, some are safe, others aren't, you don't call the libc crate function through FFI. (The libc crate indeed calls the underlying libc through FFI but this isn't the same thing!)
- expnkx 5y ago
- expnkx 5y ago