10 ms·
Systemd is bad parsing
- polotics 8y agoSo it's true what some-of-you'all been saying all along about systemd! ;-D One question: any smell of intentional obfuscation for this vulnerability, or is it impossible to tell?
- blakesterz 8y ago>> One question: any smell of intentional obfuscation for this vulnerability, or is it impossible to tell? I always think that anytime there's an interesting bug in ANYTHING. I'm not an expert, but I would think it would be nearly impossible to tell the difference between "someone made a mistake" and "someone made this look like a mistake". I would think any decent programmer with malicious intent could do that anytime they wanted.
- dsr_ 8y agoHere's a thing to ponder: If this were not buried in systemd, but was part of a standalone dhcpd package, would it have been done better or caught earlier? One of the major criticisms of systemd is that it wants to take over all system management functions. In order to do that it needs to offer at least minimally functional versions of all the services it pushes out. It should not be news to anyone that trying to do everything instead of integrating with existing projects leads to sloppiness. This incident is evidence suggesting that other serious issues are lurking in systemd as a result of the actions naturally arising from their policy.
- LukeShu 8y agoThe problem was in systemd-networkd, not systemd. One of the more popular DHCP clients is 'dhcpcd', which was created and is maintained by Roy Marples, the creator of OpenRC. It's fine when someone wants to work on DHCP clients and init systems, unless that init system is systemd? (And for the record, systemd integrates wonderfully with dhcpcd.)
- AnthonyMouse 8y agodhcpcd is not solely or even primarily used with OpenRC, it just happens to be created by the same person. What systemd is doing is something else -- not recreating one thing because there is a lack of implementation diversity or the existing implementations are subpar, but reimplementing everything even when there are multiple existing reasonable implementations, just because.
- zzzcpan 8y agoRewriting everything is fine, as long as it's not in C or similar insecure by design programming language, it doesn't invent DSLs on top of INI/YAML/JSON files, uses proper architecture with clearly defined boundaries and protocols, allowing custom application-specific management instead of forcing everyone into author's narrow worldview full of incorrect assumptions. So as long as you are not doing what systemd does. Centralized management/monitoring in general sucks. People don't seem to understand the problem and keep reinventing new centralized architectures suitable for their own special cases, instead of addressing that on architecture level.
- LukeShu 8y ago> doesn't invent DSLs Systemd didn't invent a DSL. It uses the existing config language from D-Bus (whether or not you think that's a good language is another matter). > uses proper architecture with clearly defined boundaries What boundaries in systemd aren't clearly defined? > allowing custom application-specific management What do you mean by this?
- toast0 8y agoI'm sure (but don't recall) Redhat's pump and ISC's DHCPCD have had CVEs; we all know BINDs resolver and ntpd had CVEs. If one is going to rewrite all of these things, I would expect one to learn from the history and not make the same mistakes over again.
- LukeShu 8y agoNit: ISC's DHCP client is 'dhclient', not 'dhcpcd'. 'dhcpcd' is Roy Marple's DHCP client.
- deialtrous 8y agoI would only expect that if the people rewriting everything were good programmers and said they were rewriting it to be secure. Most rewrites are done for non-security reasons are don't improve security.
- mannykannot 8y agoProgrammers should give appropriate attention to security regardless of whether they are doing either original work or a rewrite, and in the latter case, regardless of the reasons for the rewrite. I would not regard those who do otherwise as good programmers. Clearly, a DHCPv6 client within Linux' system administration suite is a case where security is an issue of the first magnitude.
- deialtrous 8y agoProgrammers should do a lot of things that most of them do not do. The statement was "I would expect..." and I replied that it doesn't make sense to expect those things because the vast majority of programmers don't know or care about security at all. We still see the same trivial SQL injections being written again and again on today's web, often by 20+ year programming "veterans".
- quickben 8y agoThis approach increases the attack surface because it is included in the most popular distros by default.
- jmartinpetersen 8y agoThe article isn't really about the bug but about the (lack of) quality in the code. Spoiler alert: He doesn't like it. "This code has no redeeming features. It must be thrown away and rewritten yet again. This time by an experienced programmer who know what error codes mean, how to use asserts properly, and most of all, who has experience at network programming."
- someone454 8y agoDoesnt sound like a negative for the article. This is one of those things that we knew would happen, even as systemd was forced into distros. Edit: after reading the article, i do have to say yhat its a bit ranty.
- tinus_hn 8y agoIf the rest of the code looks anywhere near similar to the examples he shows he’s right, this is terrible code and it should never have been allowed in a serious project in this day and age.
- pbhjpbhj 8y agoPerhaps it's a choice between this and nothing?
- yxhuvud 8y agoWell, systemd has certainly not been accused of choosing nothing too often. Rather the opposite.
- NelsonMinar 8y agoIf only there were some other DHCPv6 client that we could use.
- pbhjpbhj 8y agoI meant that perhaps noone else came forward to do the IPv6 DHCP module coding for systemd-networkd (or whichever sub-module)? That's a question. Rather than asking whether isc-dhcp-server over SysV, or whatever was better.
- a3_nm 8y agoIf like me you are looking for the CVE and not for commentary about the affected code, here it is: https://nvd.nist.gov/vuln/detail/CVE-2018-15688 https://nvd.nist.gov/vuln/detail/CVE-2018-15688 FWIW, from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912008 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912008 it looks like the vulnerable code is not enabled by default on Debian.
- JdeBP 8y agoThe rather less strongly titled "Systemd-networkd memory corruption" pointing to the much more detailed Ubuntu bug has also been on Hacker News for a day. * https://news.ycombinator.com/item?id=18303613 https://news.ycombinator.com/item?id=18303613
- flohofwoe 8y agoI agree with most of the critique, but I don't quite get the part about the use of assert. The code in question quite clearly doesn't use C's standard assert macro, but a custom macro called assert_return (which I guess checks for a condition, and returns from the function instead of aborting the program). So basically: if (!condition) { return err; } How else would one check for invalid input to the function?
- viraptor 8y agoI may have a different understanding than the author, but for me the difference in the name means a lot. The fragment you wrote is clear and simple. But if I see assert_..., then I immediately have questions like: Where's the message printed and does it have enough context for debugging at that point? Is this affected by NDEBUG? Will it run in release builds? Does assert_se() kill the whole application? Assert already has a meaning and using it in this context is not great.
- mrami 8y agoYes, exactly. Coming from C++/Java, I immediately though, "wait, this is turned off in production?" cf. http://www.cplusplus.com/reference/cassert/assert/ http://www.cplusplus.com/reference/cassert/assert/
- XorNot 8y agoI can see the argument to be made about overloading the word "assert" in the language though. i.e. "assert" meaning "check something in this code is algorithmically correct" Whereas when you're checking user input, use a very different term - i.e. validate or something. So a fix would be to rename the macro to be obvious about it's usage - "validate_return" or "valid_or_return" or something. To be fair I can see the problem because I do tend to write code comments saying "assert everything makes sense" when checking user input sometimes and "assert" itself doesn't properly convey the outcome if it fails - i.e. "abort_if" or "crash_if" would be a much more descriptive term.
- Flow 8y ago
- filam 8y agoI have to admit I stopped reading after the combined section on byte swapping and casting external data to a internal structure. Perhaps the author of the code should have used ntohs() instead of be16toh(), but the effect is the same? There aren't any conditionals in ntoh... https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html https://commandcenter.blogspot.com/2012/04/byte-order-fallac... And will a compiler make use of native byte swapping instructions with the code proposed by the author?
- detaro 8y agoThe blogpost you link seems to basically recommend the same as the author, except they only talk about the conversion step and not about where it should take place too?
- filam 8y agoThat post by Rob Pike is arguing that you should not need to check the endianness of your system when swapping. Not that you should never byte swap. Systems and protocols have different endianness, which needs to be handled by programs where endianness has not been abstracted away.
- detaro 8y agowhich is the same the submission says? Extract the data using a function that produces a value "mathematically" that's always correct for the host machine. His example uses multiplication instead of shifts like Pike, but that's a minor stylistic difference.
- LukeShu 8y agoRob Pike is saying that your code should never care/check what the host byte order is; if you use the libc FOOtoh() functions, you aren't caring what the host byte order is, you're just converting something to it. Put another way, Pike is saying that libc should have implemented be16toh() like: # define be16toh(x) ( (((char*)x)[1]<<0) | (((char*)x)[0]<<8) ) instead of how GNU libc implemented it: # if __BYTE_ORDER == __LITTLE_ENDIAN # define be16toh(x) __bswap_16 (x) # else # define be16toh(x) __uint16_identity (x) # endif But that complaint doesn't affect programs that call be16toh().
- stinos 8y agoSo this is a whole rant, and it's pretty much spot on probably, but the reader is left with a huge elephant of a question in the room: what is the proper way to do it, then? It has samples all over the place of what's bad and telling thhose should be rewritten. Why not show some C/C++ code samples of the proper way to do it, then?
- asdfasgasdgasdg 8y ago> Why not show some C/C++ code samples of the proper way to do it, then? He provides constructive examples for all of the items that he criticizes. - Instead of pointer arithmetic, base_ptr, offset, len. - Instead of casting to internal structs, parsing into internal structs. - Instead of network byte order, buf[offset] + buf[offset+1] * 256 . - Instead of the wrong error codes, the right ones. - Instead of random asserts over internal data structures, validation at parse time.
- clarry 8y ago> - Instead of network byte order, buf[offset] + buf[offset+1] * 256 . And you got it wrong. Shows that there is no silver bullet.
- asdfasgasdgasdg 8y agoI mean, I don't actually know what the correct way to do this is, because it's been a long time since I thought about endianness. I just wrote down roughly what I remembered from the article. Also, of course there is no silver bullet. Everyone knows that RCEs are still achievable against Python or Java servers. But there are still better and worse ways to do things, and there are certain categories of error that you cannot make in Python and Java that you can make in C, where the opposite is rarely the case.
- jjnoakes 8y agoIt isn't wrong if that was the order the bytes were packed on the sending side.
- 8y ago
- xtrapolate 8y ago> "The other thing that you shouldn't do, even though C/C++ allows it, is pointer arithmetic. Again, it's one of those epiphany things C programmers remember from their early days. It's something they just couldn't grasp until one day they did, and then they fell in love with it. Except it's bad. The reason you struggled to grok it is because it's stupid and you shouldn't be using it. No other language has it, because it's bad." Honestly, this is a pointless rant. "Do this, but don't do that (because that's stupid)". > "No other language has it, because it's bad" The reason you "don't have pointer arithmetic in other languages" is - it's been abstracted away from you, for your convenience, so that you can just concentrate on your business logic and not have to worry about the rest. You may not deal with pointer arithmetic, but the people developing your JVM/CPython/V8/Chakra sure do. Author is simply ranting about the possibility of abusing/misusing the mechanisms offered by C/C++.
- zwkrt 8y agoProgramming as a profession is strange because we each do such different things but all tools are available to us all the time. Imagine if this were true in the physical world; you would read arcticles written by accountants like "Dynamite Considered Harmful" with rebuttals titled "Why Dynamite Matters" by construction engineers...
- sam0x17 8y agoThis is fantastically imaginative. I love it.
- zzzeek 8y agothis is the most genius thing I've ever read on hacker news.
- xtrapolate 8y agoIt's almost as if things aren't really black or white, there's usually plenty of grey in-between. Things like use-cases, scenarios, trade-offs, intricacies. I find it awkward that a security shop would publish an article using that language - I would personally be embarrassed.
- eeZah7Ux 8y ago> In the late 1990s and early 2000s, we learned that parsing input is a problem. What? It was known well in advance.
- ben0x539 8y agoI suspect in advance of the 1990s it was a problem to people who specifically cared about such things, and would read or write papers on the topic. In the 1990s it started to become a problem for a lot of people who really only cared about putting their programs on a widely-accessible network. ;)
- jeremyjh 8y agoI don't think many people were aware of the security implications of these practices before the late 90s.
- chris_wot 8y agoAs an aside, I find it a little ironic that I found it hard to parse the headline "Systemd is bad parsing". No, Systemd is not bad parsing, Systemd is parsing badly.
- philipwhiuk 8y agoI assume it should have read "Systemd is bad at parsing"
- hyperpape 8y agoThe original is “Systemd is bad parsing and should feel bad”, which sounds a little weird, but it’s a meme, so there are lower standards. I guess someone felt like it shouldn’t be a meme headline on HN, but the result is nonsense.
- exabrial 8y agoI typically disable ipv6 unless I specifically plan to offer/use it as a public service. Just more things to keep an eye on for no benefit to the actual business.
- dvfjsdhgfv 8y agoJust like me and many other sysadmins. What amazes me is that the people who designed IPv6 still don't get it and seem surprised why it hasn't took over the Internet yet.
- ben0x539 8y agoA lot of mobile phones access the internet via IPv6 by default, and IPv4-only sites that want to reach them require non-trivial compatibility infrastructure like carrier-grade NAT or more complicated shenanigans. It seems like some sites are starting to identify these shims as a huge stumbling block in their continuous work to improve latency/quality-of-service. I think Facebook in particular made a bunch of noise in that direction and celebrates how prioritizing IPv6 has let them make huge improvements in load times etc, but at this point you're as likely to find good information about that on Google as I am so I'll spare you any links. So while IPv6 might not have taken over the Internet in any particularly observable manner so far, I think it's fair to say it has huge momentum at this point and has buy-in way beyond some IETF nerds and protocol fetishists.
- dvfjsdhgfv 8y ago> It seems like some sites are starting to identify these shims as a huge stumbling block in their continuous work to improve latency/quality-of-service. I'd be curious to know how much time you can actually save because really, honestly, in the case of Facebook this particular aspect should be the last of their concerns as far as page load times are concerned.
- zlynx 8y agoHundreds of milliseconds per TCP (or UDP) session. The CGNAT boxes are handling hundreds of thousands of flows. And they're part of failover clusters so each flow has to be shipped to the other cluster members and acknowledged before starting the flow. And these things are often overloaded and adding tens of milliseconds delay to each packet passing through. Because whoever heard of an ISP spending more than "just enough" on hardware?
- ambrop7 8y agoYes the code is bad but does not need to be completely rewritten. It should interpret the data as an array uint8_t (no casting to structure/integer pointers!), use simple helper functions to read out (u)int(8/16/32) values (there was a post on HN about this recently, https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html https://commandcenter.blogspot.com/2012/04/byte-order-fallac...), and be careful to check things like sizes. The code is also wrong because of strict aliasing. This is a real problem, your program can in fact exhibit undefined behavior because of this (it happened to me). Some time ago I wrote some code to make these things simpler in C++. It allows you to define "structures" (which however are not real structs, it's an abstraction) and then directly access an arbitrary buffer through setters/getters. The code is here with documentation: https://github.com/ambrop72/aipstack/blob/master/src/aipstack/infra/Struct.h https://github.com/ambrop72/aipstack/blob/master/src/aipstac... . In fact this is part of my own TCP/IP stack and it includes DHCP code (here are my DHCP structure definitions: https://github.com/ambrop72/aipstack/blob/master/src/aipstack/proto/DhcpProto.h https://github.com/ambrop72/aipstack/blob/master/src/aipstac...).
- ben0x539 8y agoI don't think I disagree, but could you articulate how strict aliasing makes this code wrong? Maybe I'm not looking at the right code, but it's not immediately obvious from the post to me.
- ambrop7 8y agoExample explanation: https://stackoverflow.com/a/99010/1020667 https://stackoverflow.com/a/99010/1020667 (feel free to look for better ones).
- ben0x539 8y agoThat code looks somewhat wonky and seems either legal to me, or illegal for non-aliasing reasons. In principle, taking a pointer to a blob of bytes and casting it to a pointer to your struct should be sound if you can assume that the blob of bytes was originally a valid object of that struct type. I can see how you might get it wrong if that's not in fact how the blob was originally formed or if you get some alignment details wrong, but I can't immediately think of any aliasing-specific problems.
- zwkrt 8y agoOther people's gripes aside, I enjoy that the authors approach to avoiding out-of-bounds errors almost exactly mirrors Java's nio Buffer interface.
- microcolonel 8y agoSome of these complaints are more "waah, I don't like C and what people use pointers for!", which is a shame, because some are pretty reasonable concerns. systemd works, that's why people use it. If it needs improving, then improve it, or file these. Somebody will probably agree and at least look into them, rather than a gaggle of strangers pointing and laughing.
- bvinc 8y agoHe talks like the way he writes code has been established as best practice for decades, and if he can just write enough blog posts and convince enough people, maybe we can solve this problem once and for all. I think the only way to have high assurances is to program under a system that doesn't have these classes of errors. I don't care if it's a c static checker or a new language or what. Unfortunately the long term solution to these problems in system programming seems to be rust. But it's going to take decades for it to be established and I'm going to look like a language hipster member of the rust evangelism strike force every time I bring it up. But seriously, it's been decades and decades and we're still writing buffer overflows. What is the long term final nail in the coffin for buffer overflows?
- someguydave 8y agoThe long term solution is to burn down x86 and C and start over with sane hardware, which has bounds checking in hardware.
- archgoon 8y agoI'm curious; what does your memory hardware and cpu instruction set look like in this scenario? What's the interface between the cpu and memory? (rough idea, not asking for a whitepaper here :) )
- someguydave 8y agoConsider the scheme 79 chip: http://dspace.mit.edu/handle/1721.1/6334 http://dspace.mit.edu/handle/1721.1/6334
- chmod775 8y ago> bounds checking in hardware. What. That's a horrible idea. Not only would that require your hardware to understand abstractions several layers above what it actually operates on, it would also mean it'd have to check bounds of - for example - an array on every instruction accessing it. That is something compilers can do at more strategic places. Please keep that complexity out of my CPUs, they're buggy enough already. At least with software we can fix issues later, which isn't a given with hardware.
- deleted 8y ago[deleted]
- mackal 8y agoBlog makes an error in their assumption of what assert_return() is ... It's not a macro around assert() or related. Possibly a bad idea on systemd's part to reuse the name assert, but the code isn't doing what the blog assumes it does.
- rphlx 8y agoFor some further, semi-amusing support for the title's assertion, save all of your work, close important programs, and then run 'sudo systemctl --dry-run reboot'
- andrewstuart 8y agoAs always, a bug in systemd isn't a bug - it's the complete failure of systemd as a concept. Whatever.
- verytrivial 8y agoThis article started out really well, saying you shouldn't e.g. byte-swap as part of the overall task at hand, then wanders into comparisons with other languages. I had hoped it was instead going to say that you should use some verified parsing tool to unpack data. All the other languages, at some level, will byte swap! It is the choice of the level of abstraction (or lack thereof) which is the systemd bug here, not the choice of a C family language IMNSHO.
- IshKebab 8y agoThis is the first reasonable criticism of systemd I've heard. That is very bad code.
- Go0the0gophers 8y agoAlways fuzz your parser! (e.g. AFL, go fuzz)
- stmw 8y agoArticle declares that "What you should do instead is parse data the same way as if you were writing code in JavaScript," followed by "pointer arithmetic is wrong" (paraphrasing). That seems a bit extreme...
- MichaelMoser123 8y agogcc is running in -fno-permissive by default, it will give you a warning if you implicitly try to converted between pointers of different types. (turn on warning as errors -Werror so that you have to deal with these messages) Now what I don't understand is that for C you are not allowed to disable this, -fpermissive is not allowed for C, whereas for C++ you can. Anyone knows the reason why? The compiler error says "command line option "-fpermissive" is valid for C++/ObjC++ but not for C" - why is the compiler having this distinction?