3 ms·
> Usually security nuts like to override the clear-text string with zeros or random characters before calling free() on it. If you are worried, you can store t
by cogman10 4y ago
> Usually security nuts like to override the clear-text string with zeros or random characters before calling free() on it.
If you are worried, you can store the password in a byte array and zero that out.
But further, a buffer overflow is practically impossible with a GCed language (especially a popular one). A programmer using a GCed language cannot write code which has a buffer overflow. That must come from a bug in the runtime itself. Not likely.
As far as I'm aware, every gced language has bounds checks on arrays. Certainly all the popular ones.
> the last thread dying will release the memory for this variable.
Really not how GCed languages work. Memory lifetime is not bound by thread lifetime except in the rare case when memory is bound to a thread (static/global variables).
The majority of GCs on the market are tracing collectors. Memory is periodically collected when it is not longer referenced (mark and sweep). What triggers that collection is a whole host of potentials interactions. How frequently and deep it runs also depends on a lot of application characteristics.
- acatton 4y ago> But further, a buffer overflow is practically impossible with a GCed language (especially a popular one) Because the JVM had no buffer overflow? [1] Also I purposefully wrote "buffer overflow & co" because buffer overflow are not the only possibility. Shellcodes could ptrace() and inspect the memory of the program. > > the last thread dying will release the memory for this variable. > Really not how GCed languages work. Memory lifetime is not bound by thread lifetime except in the rare case when memory is bound to a thread (static/global variables). That was bad phrasing from by part. You should have read "the last thread releasing the variable reference". [1] https://www.cvedetails.com/vulnerability-list.php?vendor_id=93&product_id=19117&version_id=&page=1&hasexp=0&opdos=0&opec=0&opov=0&opcsrf=0&opgpriv=0&opsqli=0&opxss=0&opdirt=0&opmemc=0&ophttprs=0&opbyp=0&opfileinc=0&opginf=0&cvssscoremin=0&cvssscoremax=0&year=0&month=0&cweid=0&order=3&trc=707&sha=e7bd4bdaede94939bbb984bced9c264b834fc20c https://www.cvedetails.com/vulnerability-list.php?vendor_id=...
- cogman10 4y ago> Because the JVM had no buffer overflow? Happens extremely rarely and is frequently not in JVM core code but rather something like the 2d renderer or applets. Code not likely to be executed on a server. Take a deeper look into those CVEs and count how many are for Java 8+ and server code (it's a pretty short list). You might as well argue the linux kernel is insecure because there's been buffer overflows in the various drivers. > Shellcodes could ptrace() and inspect the memory of the program. Certainly, and they can redirect socket traffic and inject a MITM for any process to directly intercept a password. Even if you are zeroing memory, there will be a period of time when a password is present in memory which means the ptrace attack also works with C. The bad part of a managed language is that passwords stay in memory for longer, but that risk is somewhat moot considering exploiting requires a compromised system. In which case, there's little reason to pull out passwords by sniffing memory.
- blibble 4y ago> If you are worried, you can store the password in a byte array and zero that out. if it's a copying collector this is no guarantee of anything but the same is true of general memory allocated with the OS (swap/THP/...), unless you use something like mlock()
- cogman10 4y agoFair point, but really one of those situations where if an attacker is in the position to look at a password stored in a tombstone, you've got bigger problems (for example, would be trivial in that scenario to simply intercept the password rather than looking for it in VM memory).
- paulryanrogers 4y agoCould it still add some defense in depth for other scenarios?
- deleted 4y ago[deleted]
- WirelessGigabit 4y agoBy checking if things are referenced or not as the basis for collection is a bad idea. Take 2 classes that reference each other, but nothing references either. In your example they won't get cleaned up. You'll want a tree-based collector. If an object is no longer referenced from the tree it can be cleaned up.