r/programming • u/speckz • Nov 11 '22
NSA urges orgs to use memory-safe programming languages - C/C++ on the bench, as NSA puts its trust in Rust, C#, Go, Java, Ruby and Swift
https://www.theregister.com/2022/11/11/nsa_urges_orgs_to_use/308
u/lacronicus Nov 11 '22 edited Feb 03 '25
racial alive work crush crawl ask versed dependent marry absorbed
This post was mass deleted and anonymized with Redact
28
26
u/Souseisekigun Nov 12 '22
Yes. People's suspicion and antipathy towards the NSA has been built up over decades of illegal spying operations and attempts at infiltrating companies (including American companies) and undermining their security for the NSA's own benefit. Any statement of theirs, even one that seems on the face of it reasonable, is therefore instantly suspect and deserving of scrutiny.
The root issue is that there is a fundamental difference of desires and interests between the NSA and the average programmer. The average programmer wants their systems to be as secure as they can possibly be. The NSA does not want systems to be as secure as they can possibly be. They want systems to be "secure enough that China or Russia cannot get into them, but insecure enough the the NSA can". This means that the NSA is not your friend or ally, and they do not help you or advise you in good faith.
If this all sounds paranoid remember when they pushed Dual_EC_DRBG so that we could all have the next generation of secure encryption? Seems perfectly reasonable right? I would suspect that if this were one of those threads you would be posting a similar comment. NSA: "Guys for the love of god please move onto next generation crypto!" and you would be laughing at all the people going "that's how they gethca". Except of course it turns out that Dual_EC_DRBG indeed was effectively backdoored by the NSA, any everyone that adopted it on their recommendation absolutely got got. Every time the NSA steps in and generously offers some advice to help you be more secure remember this.
Though they're probably already into your Google Drive anyway.
→ More replies (13)28
u/Substantial-Owl1167 Nov 11 '22
Google docs is unreasonably good. It made me quit my plain text obsession.
→ More replies (5)29
96
Nov 11 '22
How are we expected to escape the simulation now?
14
380
u/Akeshi Nov 11 '22
In the Venn diagram of language use-cases, 'C' and 'Ruby' are a pair of goggles.
18
u/dacandyman0 Nov 12 '22
lmao never heard this phrase before, or if it's not a phrase, it's going to be now for me 😄
24
u/thisisjustascreename Nov 12 '22
They did say "when possible." Nobody expects you to write code for your embedded hardware controller in Haskell.
47
u/coldblade2000 Nov 11 '22
I think they meant languages in general. Go and Rust (which were both mentioned) do compete with C in many areas (not every area, though, of course)
70
u/IcyDefiance Nov 11 '22 edited Nov 12 '22
Go's tracing garbage collection is a deal breaker for almost everything that C is used for. It's more of a competitor to C# and Java.
Rust is almost always a better choice than C, though, since it doesn't have that overhead and it can expose a C ABI. The main exceptions are just for platforms that Rust (and probably LLVM) doesn't support.
→ More replies (2)25
→ More replies (1)7
u/FargusDingus Nov 11 '22 edited Nov 11 '22
Edit: I miss read the headline ☹️
12
u/Akeshi Nov 11 '22
Your response implies C is a memory-safe alternative they're suggesting, but it's the opposite: they're saying to stop using the (memory-unsafe) C, and instead use Rust, Ruby etc.
7
32
u/SaneMadHatter Nov 11 '22
What about Ada?
13
3
u/Serious_Feedback Feb 18 '23
Ada is fine. The article mis-quotes the NSA, who gave languages as examples rather than an exhaustive list.
148
u/minisculebarber Nov 11 '22
Well, I just started working on a Python Extension, sooo...
159
u/reamde_txt Nov 11 '22
It's not "Leaky Coding", it's a "Dynamic Agile Memory Model"
→ More replies (3)80
17
0
Nov 11 '22
[deleted]
→ More replies (3)70
Nov 11 '22
Yes, except, you solve the hard problem once in a lower level language and then you can use it in an easier language and don't run the risk of adding a bunch of defects and vulnerabilities. A small number of people need to solve the hard problems in C, and everyone else should leverage the wheel that has already been invented.
→ More replies (26)23
u/TheHumanParacite Nov 11 '22
Well hold on now, if that were true why aren't computation heavy things like neutral nets wrapped in python... Oh wait...
→ More replies (11)
101
195
u/Salamok Nov 11 '22
Meanwhile the millions of outdated and unpatched Java instances continue to march along convinced of their superiority.
59
u/istarian Nov 11 '22 edited Nov 11 '22
That's a much harder to fix problem though.
I doubt there's much your code can do about vulnerabilities in the VM except reduce its own attack surface.
Besides, Java itself (as a language implementation)is considered memory-safe because it has runtime error detection. You can't do out-of-bounds array accesses or anything like pointer dereferencing without errors being thrown.
16
u/Salamok Nov 11 '22 edited Nov 11 '22
It is a platform that is notoriously hard to patch, often the enterprise application vendors adopt a set it and forget it deployment and no one on the consumer side knows this is bad so it goes unmaintained.
Saying hey PHP which still powers close to 80% of the web is not on the approved list so lets migrate everything off of that is a big mountain to be moving.
→ More replies (20)
14
u/djnz Nov 11 '22
What about Sinclair BASIC
2
2
u/Maristic Nov 12 '22
What about Sinclair BASIC burned into a ROM. No danger of anything breaking with an OS update!
27
u/TimeTravelPenguin Nov 11 '22
Forget the Python bros, where are my Haskell homies at?
→ More replies (5)
495
u/ShelteredTortoise Nov 11 '22
Agency responsible for hoarding zero day vulnerabilities and achieving access to private systems urges you to rewrite your code to make it safer guys, I promise.
335
u/pfmiller0 Nov 11 '22
Protecting our national secrets is a big part of the NSAs job, so it's no surprise that they have an interest in more secure software. SELinux was created by them for the same reason.
168
u/ShelteredTortoise Nov 11 '22
Don’t get me wrong. I do know that the NSA does make recommendations on security that are legitimate. When they talk, you should definitely hear them out. But they juggle that with hoarding vulnerabilities (Eternal Blue) and infiltrating systems both foreign and domestic. Just take what they say with a grain of salt. I’m also not American so I’m not entirely convinced that the NSA really cares about my countries digital security competence
80
u/airodonack Nov 11 '22
Yeah well it’s all connected. You can make software that Americans use within their borders. I think the NSA sees cybersecurity as a leaky boat with way too many holes. Infiltration is not the problem for them, instead they’re trying not to drown.
41
u/chipperclocker Nov 11 '22
Look at it this way: they have a vested interest in ensuring your average business or government entity is legitimately secure enough that nothing short of an advanced nation-state level attack of the type they’re known for carrying out can compromise you
→ More replies (2)11
6
→ More replies (2)4
Nov 11 '22
Making a secure thing then putting NSA-private backdoor it would be on script for them.
→ More replies (2)40
u/mamcx Nov 11 '22
Totally reasonable.
Doctor: Eat vegetables, and fruit, and do exercise.
Rest of humanity (bar 2 or 3): Nah!
Ah, but you are talking about EVIL doctors:
Evil Doctor: Eat vegetables, and fruit, and do exercise. (thinking for himself: I eat humans in my spare time and wish they taste nice.)
Rest of humanity (bar 2 or 3): Still Nah!
8
u/PixelCartographer Nov 11 '22
2) When having any private conversation, whether via phone or with those in your home, turn down the TV and radio to cut back on noise pollution. Also, please try to keep your conversations lively – maybe some local gossip or polarizing sports opinions. Too much boring talk about plans for your garden or where to buy good laserdiscs can make the Secret Police tired and less effective at their jobs.
7
u/ironykarl Nov 11 '22
Were you gonna suggest a way in which this advice might actually lead to more vulnerabilities in the wild... or are we just to assume that nefarious motives magically overturn logic?
→ More replies (5)65
u/matthieum Nov 11 '22
No contradiction there.
C and C++ applications are so rife with security vulnerabilities that any script kiddy can find an exploit in them.
Using safer languages raises the bar, weeding out competitors.
→ More replies (3)
20
60
u/tiberiumx Nov 11 '22
I've been a diehard C++ programmer (at least when I can't get away with python), but with Linux adding support for Rust, I'm probably going to pick that up and start migrating that way for future projects.
32
u/StickyPolitical Nov 11 '22
Not sure about OSs and other stuff but i dont think rust is going to grow in embedded development for awhile.
There was a small push in my company and it was nixed because nobody really knows it. Industry standard is c/cpp.
Vulnerabilities are likely mitigated through network security and protocols.
Think of like a 787, its probably running c/cpp on everything but planes dont get hacked in a malicious sense. Same with cars.
Changing to rust has little benefit in these applications. Dynamic memory is already off the table in real time embedded systems after initialization.
→ More replies (8)18
u/tiberiumx Nov 11 '22
I've only ever done embedded stuff as a hobby, so that's not my concern, but the issue addressed here is stuff like buffer overflow vulnerabilities, and that's a problem regardless of whether your memory is allocated on the stack, heap, .bss, etc.
It doesn't matter how good you are, eventually you're going to fuck something up with memory management in C/C++. Ever had an off by one error? Ever used an iterator after it was invalid? Ever called a method on an already freed object reference? Maybe you'll get lucky and realize your fuckup right away with a SIGSEGV, but usually not. Static code analysis tools can help, but only so much.
You definitely can't rely on network security to guard your application.
I don't know anything about Boeing avionics, but I'd hope they're using something better for safety critical applications like Ada.
→ More replies (5)8
u/assassinator42 Nov 11 '22 edited Nov 11 '22
787 uses a mix of C and Ada.
Ada doesn't prevent you from shooting yourself in the foot via assigning an arbitrary address to a record or having a definition mismatch interoping with C.
→ More replies (1)8
u/quick_escalator Nov 11 '22 edited Nov 11 '22
Have a look at cppfront, the experimental overhaul of C++ by Herb Sutter. It's really neat.
Here's the talk from this year's cppcon:https://www.youtube.com/watch?v=ELeZAKCN4tY (For some idiotic reason they removed the video and made it to premier tomorrow again, I've watched it last week...)
28
u/gnuban Nov 11 '22
Rust is about 100x more polished and works today, though ..
16
u/quick_escalator Nov 11 '22 edited Nov 11 '22
Sure, but the Rust compiler isn't compatible with every single piece of code written in C++ or C, whereas this is: Every .cpp file in your git repo still compiles, and you need a total of zero command line arguments for that. That's such a strong selling point, the arguably two most important ecosystems are built around it: C++ and Java.
It's a different value proposition than "just rewrite your app from scratch in rust".
Personally I really like D (and from what I know about Rust they are very similar), but sadly it doesn't have widespread adoption.
→ More replies (7)→ More replies (1)2
u/Superblazer Nov 12 '22
Do you create gui applications with c++? If so what framework do you use?
→ More replies (1)3
7
u/harshyadavjiii Nov 12 '22
C/C++ aren't going anywhere atleast for college graduates we prepare our DSA's mainly in C/C++. Our professor introduced us to Data Structures entirely in C Idk but for performance Rust stands on the same page where C++ does
13
u/MinMaxDev Nov 11 '22
maybe this is a dumb question, but what is swift used for outside of iOS dev ?
8
u/rjcarr Nov 12 '22
It's a general purpose language with a compiler. It can be used for anything, it just isn't very often.
8
u/guigui_mo Nov 11 '22
It can be used on the server side with frameworks such as Vapor.
4
0
Nov 12 '22
[deleted]
7
u/gdwsk Nov 12 '22
A few real life applications of server-side Swift…
Mercedes-Benz: in-car infotainment backend and dealership console
FINN (ING Bank subsidiary): banking APIs
allegro (Polish Amazon equivalent): image processing micro services
Amazon: multiple Prime Video applications
Spotify: build integrations and metrics
BBC: mobile app test harnesses
Apple: iCloud services
58
Nov 11 '22 edited Nov 11 '22
I’m a flight software engineer and I’d rather develop avionics and satellite bus software in C++. I don’t even want to think about linking matlab/c model generation into Rust nor patching in-orbit rust software with new matlab/c models. Im getting anxiety just thinking about that.
Edit:
Going to leave the original. Im just venting cause it’s been a rough morning. Got to thinking this might get some attention so clarifying a few things. I’ve always wanted to write flight grade software for avionics and satellite buses in Rust. I think that would be an awesome endeavor with a ton a knowledge gained from it. I even know of some companies that have and are doing it but they also had the capability to start from square one and define their architecture.
However, humbly speaking and IMO, many orgs in the aerospace industry are not starting from square one and adopting new footprints would require longer more expensive schedules. So you cannot drop Rust in as a C/C++ replacement always in complex embedded/firmware development environments for space flight oriented systems.
Now maybe in the future we can get there. I’m probably a little biased but we are all experienced/skilled in our own area and I don’t always feel embedded/firmware dev environments get thought of much when people write these articles. Here at work we lwrite models in Matlab, convert to c (no I don’t like it either), link it into C++ software, then do time stretching in VHDL at the FPGA level.
Dropping Rust in I guess I would start by figuring out how to link the Matlab/C models in. Rewriting the C++ to Rust then I would need to performance monitor each thread and probably a few subroutines. Multithreaded apps are weird so I would need a good understanding of where my bottlenecks are. Then we could redo our time stretching at the VHDL level and maybe check timing constraints again so I’m not f’d by clock skew with any of the underlying interface logic. I guess I would start there. That’s a big schedule hit though. PM probably be driving me insane the whole way through.
This comment got out of control so I’ll stop now. I like Rust and I hope industry tries to adopt it more and more. Though I like C++ too. I believe us engineer(s) should define what to use in my above case versus the cooperations. I’m not a fan of management if you can tell. Cheers all and happy debugging.
→ More replies (6)15
6
u/antillian Nov 12 '22
Ruby dev here. Does this mean I’m qualified for a job at NSA? 🤔
1
u/Dark-Philosopher Feb 19 '23
If you need to ask then no. If you feel good enough that you don't need to ask then no If you can hack them then probably yes, if you don't go to jail first.
5
9
u/GayMakeAndModel Nov 12 '22
There are a lot of salty bitches on here. Managed languages don’t have buffer overflows, they don’t have use after free errors, they don’t have memory leaks THAT ARE NOT FORGOTTEN REFERENCES TO OBJECTS - that shit is not technically a memory leak. A memory leak is when memory is allocated, but there’s no longer a reference to it.
Anyway, not using C/C++ eliminates a HUGE swath of vulnerabilities. Now that we have viable high level systems programming languages, the NSA is absolutely correct in making this recommendation.
→ More replies (2)
95
Nov 11 '22
Surprised I didn't see Python in that list. And really pretty stupid. It isn't just the language that matters but underlying security issues that pop up because of poorly coded libraries!!!
134
u/SmallCapsLock Nov 11 '22
It is not an exhaustive list. Here is the full quote:
Using a memory safe language can help prevent programmers from introducing certain types of memory-related issues. Memory is managed automatically as part of the computer language; it does not rely on the programmer adding code to implement memory protections. The language institutes automatic protections using a combination of compile time and runtime checks. These inherent language features protect the programmer from introducing memory management mistakes unintentionally. Examples of memory safe language include C#, Go, Java®, RubyTM, Rust®, and Swift®.
19
Nov 11 '22
I understand that but it's a glass half full. Bugs come not only from the language but from the underlying libraries. I've written C and C++ programs that were safe. On the other hand I've seen Java libraries riddled with security issues...
85
u/psych0pat- Nov 11 '22
they never imply that you won't get bugs or security issues by using memory safe language, just that restricting direct access to the memory adds a layer of protection and make the language safer to use.
56
u/LuckyHedgehog Nov 11 '22
They would probably argue that seatbelts aren't necessary because you can still get hurt in any accident, and good drivers can avoid accidents altogether
Wearing a seatbelt is still a good idea
→ More replies (3)→ More replies (11)25
u/Full-Spectral Nov 11 '22 edited Nov 11 '22
But the point is you can have memory related errors and every test of that code that you could think to write could quite likely produce the correct results, but it'll still have a potential security hole.
If you have logical errors, you at least have a very good chance of catching them if the code is thoroughly auto-tested.
→ More replies (7)15
u/onequbit Nov 11 '22
no, Python can be memory unsafe all by itself... https://github.com/DavidBuchanan314/unsafe-python
4
24
u/small_kimono Nov 11 '22
Probably because lots of the more performance oriented Python libraries are coded in C?
→ More replies (17)40
u/vicegrip Nov 11 '22 edited Nov 11 '22
My quib with Python is the slew of run-time errors it brings to the table as a function of not being a statically typed language.
Thus, while it's true that Python eliminates the aforementioned memory problems, it comes with sufficient baggage itself -- on top of being demonstrably slower than statically typed languages like Java in many ways.
The NSA should have specified statically typed languages in its statement because static typing eliminates hosts of runtime errors. You could also make a strong argument to desire immutability by default.
10
u/CandidPiglet9061 Nov 11 '22
I guess it depends a lot on what the app is doing. A lot of those runtime issues can be mitigated with MyPy, but generally I’ve found that Python’s real limitation is that it doesn’t scale well in terms of LOC. Large Python codebases can be quite labyrinthine without a lot of discipline from everyone involved, and generally if the only thing between you and a big mess is a gentleman’s agreement among devs to keep things clean, you’re in for a world of hurt
16
u/Cobaltjedi117 Nov 11 '22 edited Nov 11 '22
As much as I love python for quick or one time problems and its ease of programming, there are certain things you don't want to use python for, and its really loose nature can come back to bite you. C# is my weapon of choice since it can be rigid. I am expecting this variable to be an int, if its not then that's a problem.
→ More replies (9)5
Nov 11 '22
It is true that you can get runtime errors but that is true of every language. It is true you can get fewer because of the strong typing, but languages that support polymorphism can have the same thing. You just need to deal with them.
And in Python 3.6 there is typing that may or may not be used. You will get people on both sides arguing about strongly typed vs. dynamic. Personally I like programming by contract because it gets rid of a lot of those things too.
→ More replies (3)9
u/TheChance Nov 11 '22
Typehints are wonderful, but they aren’t enforced by the interpreter.
→ More replies (10)4
u/engineerFWSWHW Nov 11 '22
I use python,c,c++, and c# on a daily basis (on safety critical systems). For tools, testing and utilities, python is ok. For safety critical systems being deployed on the field, I wouldn't use python due to the absence of compiler checks and will prefer strongly typed, compiled language. We even go as far as checking the compiler generated assembly and enabling lots of error checks on compilers.
→ More replies (22)3
u/uncooked-cookie Nov 11 '22 edited Nov 12 '22
The list of recommended languages or languages to avoid?
In python, pickling is a big problem as it enables arbitrary code execution.
4
10
Nov 11 '22
As someone that is constantly defending myself over using c# instead of "real" languages that "real" programmers use...haha, suck it.
17
Nov 12 '22 edited Nov 12 '22
Serious question, how old are you? I can only imagine people claiming C# isn’t a real language who are too young to have any real-world exposure. C# is one of the most widely-used languages in the world by actual businesses.
→ More replies (6)→ More replies (5)7
u/_crater Nov 12 '22
As someone who was in the same boat as you a while ago before diving into C and Rust for embedded development and such...
You're still 100% right.
I will say I've come to understand how to use certain practices/features in C# a lot better because of the lower level programming, but if the project can be done in C# I'm definitely doing it there. Especially with .NET 5+/C#9.0+ things are just so... Clean. All the bullshit is handled for you, leaving you to focus your efforts on actual programming instead of fucking around with makefiles, memory management, worrying about safety, toolchain quirks, assembly, etc.
→ More replies (1)
3
u/Chroko Nov 12 '22
I’m surprised they don’t favor some of the functional languages like Haskell, but I guess that’s because it’s not popular enough and is maybe also not typically used for the types of apps they’re interested in.
→ More replies (1)
3
u/biffbobfred Nov 12 '22
People go “no memory leaks” when “no more double free attacks on the heap” is much more important.
3
u/daravenrk Nov 12 '22
This is like saying, we have added training wheels to all bikes and it’s now a law.
So now you can’t make sharp turns at all.
2
u/-Redstoneboi- Nov 13 '22
unsafe.Although these ways of including memory unsafe mechanisms subvert the inherent memory safety, they help to localize where memory problems could exist, allowing for extra scrutiny on those sections of code.
→ More replies (2)2
u/daravenrk Nov 13 '22
I don’t mind actively managed memory. I think it’s rude to say that we are not good enough to use c and c++ without causing segmentation faults.
→ More replies (20)
3
5
u/Xoipos Nov 12 '22
*sighs*
There is a myth around C++ that gets propagated ever since Rust made it about memory safety. The problem with C++ isn't that it's impossible to get safe, it's that all the help you can get from the compiler is turned off by default. Case in point, from the article:
"Mitigations like address space layout randomization (ASLR) and stack
guard are kind of a band-aid, not a full solution; moving to a
memory-safe language is a much better one,"
This glosses over the very fact that even Rust uses these mitigations, because any sane person uses them.
This goes for C++ as well, there exist a host of off-by-default flags/features that make it a lot easier to make safe code in C++. Jason Turner's cpp best practices is a must read, using the sanitizers is another must, using facilities like g++'s _GLIBCXX_DEBUG and _GLIBCXX_DEBUG_PEDANTIC or MSVC's /GS /RTCs is a must.
I get it. Rust is an amazing step forwards in memory-safe programming without compromising performance. I absolutely love that it competes against C++ and in turn forces C++ to improve. Heck, there's work underway to introduce a Rust-esque lifetime analysis in C++! And we should absolutely do that! But to call for completely avoiding C++ is unjustified and based on fallacies. I expect better from NSA.
3
u/-Redstoneboi- Nov 13 '22 edited Nov 13 '22
See Page 4, "Application Security Testing", of The actual report
5
u/CommunismDoesntWork Nov 12 '22
That's great, but C++ doesn't have a first party package manager or build system so it's a hard no from me dawg.
2
u/1337GameDev Nov 11 '22
Considering python, rust, java, c# etc are pretty fast with newer runtimes -- even compared to c++ / c.
→ More replies (7)
2
u/SteeleDynamics Nov 12 '22
; garbage collect this!
(define (loop acc)
(loop (cons 'foo acc)))
(length (loop '()))2
2
u/cfehunter Nov 12 '22
Garbage collection doesn't mean memory safety. Java and C# are still susceptible to plenty of unsafe behaviour.
4
u/istarian Nov 12 '22 edited Nov 12 '22
https://en.wikipedia.org/wiki/Memory_safety
Make sure you're using the right terminology.
Java throws runtime exceptions over out of bound array accesses (OutOfBoundsException) and trying to use a reference that's null (NullPointerException).
It is also a a Pass-By-Value language.
https://www.digitalocean.com/community/tutorials/java-is-pass-by-value-and-not-pass-by-reference
2
u/livewirerd Nov 12 '22 edited Nov 12 '22
Absolutely no mention of JavaScript as a thread safe language using v8
Edit: I grow more appalled thinking these are the folks reading all my emails knowing this is how they value JavaScript
2
u/should_i_do Nov 12 '22 edited Nov 12 '22
This will do nothing to prevent colossal screw ups like the Mars Climate Orbiter
EDIT I read NSA as NASA, but whatever my point still stands that screw ups are possible. Yes NSA, is trying to avoid buffer overflow exploits. Also, it looks like I haven't recovered fully from my concussion.
2
Nov 12 '22
That's a bit of a weird recommendation. You can make mistakes in every language.
→ More replies (1)
3
u/Ateist Nov 12 '22 edited Nov 12 '22
"Mitigations like address space layout randomization (ASLR) and stack guard are kind of a band-aid, not a full solution; moving to a memory-safe language is a much better one," added Reed, before echoing Russinovich's sentiments.
Wouldn't it be better to use hardware/OS protection?
If every process was hardware encrypted with its own key, you could buffer overflow all you want - without getting anything meaningful out of any other program from it.
It would also solve all the sideline attacks.
→ More replies (8)2
u/Dean_Roddey Nov 12 '22
Clearly hardware should be more involved. But it's such a hard practical issue to solve. It would probably require some fairly fundamental changes in the OS, but it would still have to run on hardware that doesn't have those features and which will be around for decades.
Even something as 'simple' as hardware supported, handle based memory instead of pointer based that's light weight enough to use in a heap allocation sort of way. So every string or vector or whatever can allocate a buffer that is accessed through a handle, not a pointer, so that all accesses can be hardware checked for overflow and access rights can be set on it. So I, thread A, can allocate a buffer that only I can write to and other threads can only read, or only I can access at all so any other thread accessing it purposefully or by overflow from somewhere else would be caught at the hardware level.
That kind of thing would be a VAST improvement, but it would also require an overhaul of both the hardware and software ecosystems that is all but impossible at this point. we could have maybe done it in 1995, but now it would be almost inconceivable.
6
u/linuxdwag Nov 11 '22 edited Nov 11 '22
I think every post about languages is missing the point.... Every language has it's purpose and pros/cons. You use the right tool for the right job. Some can shoot yourself in the foot more than others but doesn't mean you shouldn't use them. Some applications require tight timing requirements such as realtime systems, trading applications, medical devices, automotive applications, etc.
It comes down to the developers using the tools available such as address sanitizers, compiler safety checks, static analysis, linters, etc. What these other languages have is structure and tooling built around that structure. What c/c++ have are many tools all designed to add or subtract based on your use case.
I personally would like better tooling for c/c++ and is annoying setting them up. Right now you have to know a lot to get started. Then you have to customize and make things work together which is a pain.
Also better practices such as CI/CD, automating things you can automate, TDD, BDD, Integration testing, pair programming, mob programming, etc help solve these problems. Just because a language is "memory safe" doesn't mean you can't create vulnerabilities. It is harder to do but if you don't understand the language or how to design and program is where they slip in. We need mentors teaching juniors not language regulations
18
Nov 11 '22
I think you're missing the point with some of these safer languages, particularly Rust. Having the default be safe and the thing they have to go out of their way to be unsafe with is inherently safer design. No one is saying that C++/C is impossible to make safe, but devs are humans and make mistakes and therefore using a system designed to minimize those mistakes is a better choice.
→ More replies (9)→ More replies (1)5
u/IAmRoot Nov 11 '22 edited Nov 11 '22
Yeah, and there are some places where memory safe languages are not the right tool. For instance, in high performance computing, we have pointers to memory in different address spaces. It isn't possible to reason about or track the lifetime of objects in a different memory space without prohibitively expensive communication. There are special cases like global arrays where lifetime can be reasoned about but the general case is impossible. C++ having smart pointers for process-local memory and unmanaged pointers for global memory is the sweet spot here.
Maybe it would be better to have an
unsafe_ptr<T>and prohibit raw pointers as a way of flagging such pointers, but that doesn't make it safe.
4
4
u/Polyclad Nov 11 '22
No thanks.
34
u/Local-Program404 Nov 11 '22
Research has shown the majority of security flaws could be solved by memory safety.
→ More replies (4)
3
u/XeonProductions Nov 11 '22
Can't modern C++ be memory safe though?
18
u/vlakreeh Nov 11 '22
You can write memory safe code but you can also write memory unsafe code. Here's some examples that even modern idiomatic C++ can't statically check. While C++ has undeniably made great progress on improving how many memory safety issues it can catch at compile time there's always going to be holes in it unless they are willing to break things and you still need to have memory safety on your mind when you are implementing things in C++. But I'd also like to say that "memory safe" really isn't binary, more of a scale. Even languages like Rust have holes in them that can cause issues like segfaults, they're just a lot less frequent and much smaller in surface area.
→ More replies (1)→ More replies (1)10
u/rabid_briefcase Nov 11 '22
Obviously yes.
From TFA: malicious cyber actors may exploit vulnerabilities in poorly managed memory, which occurs more frequently in the languages that give more options and flexibility to the programmer.
Despite the headline and alarmist language by The Register, if you click through to the actual NSA press release, you get the title "NSA Releases Guidance on How to Protect Against Software Memory Safety Issues" and their actual recommendation "NSA recommends that organizations use memory safe languages when possible and bolster protection through code-hardening defenses such as compiler options, tool options, and operating system configurations."
As others posted, you can write crappy code in any language. You can also write quality code.
-2
1
u/krum Nov 11 '22 edited Nov 11 '22
Calling Rust memory safe is a bit disingenuous.
6
Nov 11 '22
Can you explain? I donot like rust for its complexity but seeing it endorsed it everywhere has made me studying it.
7
u/krum Nov 11 '22 edited Nov 11 '22
You can get into the memory weeds in Rust pretty easily. You have to trust that your dependencies are 100% memory safe, which of course at some point they aren't. I spent half a day debugging a memory safety issue in a dependent rust library because it called out to a C API the other day. Bugs like this can creep into prod and cause some headaches.
I think one of Rust's real strengths in terms of safety is in the barrow checker, which to a large extent is related to memory safety, but it's not the whole picture.
It's definitely safer than C or C++ by a long shot.
→ More replies (3)
2
1
1
1
1
u/zenyl Nov 12 '22
With both garbage collection and extensive compile-time checks for potential null references, C# is pretty secure against unintended crashes.
1
u/franzwong Nov 12 '22
I hope software can provide a wrapper first. Recently I tried to write rust to call C (MacOS API). But the time to create the interface requires some effort. I didn't use unknown 3rd party library because I was working to access keychain.
1
1
u/bnolsen Nov 12 '22
It's easier for the nsa to back door these other languages?
2
u/thiseye Nov 12 '22
That's what people said about DES encryption when NSA suggested tweaks to it that ended up making it stronger.
1
u/daravenrk Nov 12 '22
I want government officials held accountable for their terrible choices.
The NSA listens to our calls.
Watches our traffic and thinks they are going to cut c and c++.
I want these people shut down now!
1
Nov 13 '22
This problem was solved 30 years ago with Ada, but only now is it starting to look attractive after the DoD has largely abandoned it.
1
1
1
u/CeFurkan Nov 29 '22
Of course the programming language is important. however, more important factor is the education of the programmers
I try to teach all of the possible leaks in my lecture videos in C# : https://www.youtube.com/@SECourses
1
u/SnooMemesjellies7345 Dec 13 '22
Hi everyone. Do anyone wants to create your first programming language?
1
u/StandingIntercession Jan 07 '23
Let's hope the memory-safe programming languages help keep us safe!
1
0
-3
u/Zeh_Matt Nov 11 '22
An experienced developer is perfectly capable of writing a safe program in C or C++, the propaganda against C/C++ is getting slightly annoying lately.
11
u/smalleconomist Nov 11 '22
You, circa 1970: “An experienced developer is perfectly capable of writing a safe program in assembly, the propaganda against assembly is getting slightly annoying lately.”
→ More replies (14)→ More replies (1)5
u/miyakohouou Nov 11 '22
In theory it's possible to write a safe program in C, but in practice there are too many opportunities for things to go wrong. We've seen plenty of evidence that skilled programmers, in practice, still miss things and security errors caused by a lack of memory safety still make it into programs. We have tools that can help us with this, so it seems like a good practice to use them. That's not to say there is no place for C at all, but we should probably treat it more like hand written assembly: something to be carefully used when appropriate to augment other languages, rather than something we write entire projects in.
C++ is a little less clear cut, since the language has been evolving pretty quickly lately, and it wouldn't surprise me to see better memory safety options cropping up. RAII already helps, and C++ has better type safety in general to help writing more memory safe programs.
It does seem like Rust is probably the future for most systems programming though. It's clearly gained a lot of momentum, addressed a lot of concrete memory safety issues, and clearly brings in language features that a lot of people want.
→ More replies (3)
1
u/ContentFlamingo Nov 12 '22
Wait dont the NSA want us to have security vunerabilities in there they can exploit?
2
u/Qweesdy Nov 12 '22
NSA want security vulnerabilities they can exploit but other people can't exploit. It's why their covert agents contribute to lots of security related open source projects (OpenSSL, Linux kernel, ...).
1
u/tiajuanat Nov 12 '22
I'm really surprised Go is on the list, because my coworkers frequently have problems from it.
-4
u/RobinsonDickinson Nov 11 '22
The NSA can suck it. Bunch of pieces of shits who are only there to impede on our freedom and normalizing a surveillance state.
0
4.1k
u/3CN Nov 11 '22
This is a nice idea, but I’ll have you know my colleagues and I are more than capable of implementing leaky and insecure software with any language.