News for hackers. Stuff that matters.
Re:Rust RAII is better than the Haskell bracket pattern by agumonkey on Tuesday October 09, 2018 @10:03AM (#18176044)
Does _exit wipe out memory or just mark some regions as free ? asking for security purposes.
Re:Rust RAII is better than the Haskell bracket pattern by toast0 on Tuesday October 09, 2018 @10:58AM (#18176451)
I don't know how Linux manages its memory pages. FreeBSD would put all of the anonymous pages onto essentially a free, but not zeroed queue. And there's an optional background job to zero the pages and put them in the zeroed queue. When a new page is needed, the clean queue is checked first, otherwise nonzeroed pages are zeroed on demand during allocation. (Zeroing can be theoretically skipped in cases where the kernel knows the full page will be written to before any reads)

Zeroing on exit would be more secure, but significantly slower -- you want to exit quickly, so you can potentially start a replacement program, which would be expected to, at least sometimes, take time to allocate the same amount of memory. If it does allocate the whole amount immediately, it's not necessarily any slower in total time between zeroing at exit or on mapping; but it there's enough time for the pages to get zeroed in the background, that reduces the amount of time waiting for the kernel to do things.

Re:Rust RAII is better than the Haskell bracket pattern by agumonkey on Tuesday October 09, 2018 @11:17AM (#18176608)
Maybe a randomized sparse zeroing ?
Re:Rust RAII is better than the Haskell bracket pattern by toast0 on Tuesday October 09, 2018 @11:59AM (#18177035)
I'm not sure what a randomized zeroing would get you from a security perspective. You shouldn't need to be concerned about other programs observing the memory, kernels are expected to give programs only zeroed pages. If you're concerned about kernel level memory dumping, randomized zeroing isn't good enough -- it may or may not have zeroed your secrets, so that's not very helpful. Background zeroing doesn't help much here either -- FreeBSD sets a target of zeroing half the free pages, so your secrets may not be zeroed for a long time.

It seems the jury is out on the benefits from a performance perspective (DragonflyBSD took out background zeroing, saying they were unable to observe a performance difference, so simpler code is better)

Re:Rust RAII is better than the Haskell bracket pattern by agumonkey on Tuesday October 09, 2018 @12:10PM (#18177138)
Not much indeed but it might deter some low hanging leak hacks..
Re:Rust RAII is better than the Haskell bracket pattern by Franciscouzo on Tuesday October 09, 2018 @12:19PM (#18177241)
Why? When taking into account the cpu cache, branch mispredictions, etc, I bet it would be slower than just zeroing it, besides it wouldn't be secure at all, imagine a process that stores a secret key, and then releases the memory, if another process can trigger the first to generate and release the key memory multiple times, they would be able to read it.
Re:Rust RAII is better than the Haskell bracket pattern by umanwizard on Tuesday October 09, 2018 @10:43AM (#18176343)
Marks it as free, but the OS will wipe it before giving it to another process.