Re: Security of data in memory

From: Glynn Clements (glynn.clements@virgin.net)
Date: 12/26/01


From: Glynn Clements <glynn.clements@virgin.net>
Date: Wed, 26 Dec 2001 22:28:58 +0000
To: Nicholas Brawn <ncb@pobox.com>


Nicholas Brawn wrote:

> I have a unix program that reads in an encrypted file, decrypts it and
> works on it whilst in memory. What security considerations should I be
> aware of? I'm thinking of things like clearing the decrypted buffer
> prior to exiting, not storing any of the data in a temporary file, etc.

Actually, you may be better off storing the plaintext in an mmap()d
file.

Storing it "in memory" risks having it written out to swap, and there
isn't any reliable way of wiping it from swap. Unfortunately, you
can't, in general, rely upon mlock(). On some systems (e.g. Linux),
mlock() requires root privilege. On others, it depends upon resource
limit settings (RLIMIT_MEMLOCK).

If you use an mmap()d file (with MAP_SHARED), it shouldn't be written
to swap, and you can wipe the file once you are finished. The main
issue here is whether the underlying filesystem allows you to reliably
overwrite data.

BTW, be sure to create the file without any excess permissions, e.g.
open(..., 0600).

-- 
Glynn Clements <glynn.clements@virgin.net>



Relevant Pages

  • Re: Heaps and Foreigners
    ... >> can ask for the memory and get a pointer to it. ... cause unfathomable deaths when swap space gets low or is exhausted. ... It's probably because there is some reserve memory to print out errors ... of RAM and disk space) and virtual swap (which is just a number managed ...
    (comp.lang.lisp)
  • Re: Is Greenspun enough?
    ... Most OSes memory map executables directly from the file system so code doesn't pollute the file cache or swap space. ...
    (comp.lang.lisp)
  • Re: [PATCH] io-controller: Add io group reference handling for request
    ... Find the io group bio belongs to. ... anonymous pages (swap) you still need the page tracking functionality ... so fair to charge the current task for the whole activity. ... is some other memory hungry application which is forcing these swap outs. ...
    (Linux-Kernel)
  • Re: [kde-linux] VM and Swap problems
    ... swap is half full the system starts removing swap until it is exactly ... Maybe one of your applications leak memory (I have a webpage ... to two times RAM. ... Unused memory will be used as disk buffers. ...
    (KDE)
  • Re: [RFC][PATCH 2/9] deadlock prevention core
    ... don't try to swap over the network. ... We could track dirty anonymous memory and throttle. ... to be stuck in wait queues. ... What is a "socket wait queue" and how/why can it consume so much memory? ...
    (Linux-Kernel)

Loading