Re: cryptoapi and swap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rob McGee wrote:
> I haven't read where anyone has done this yet, but it is quite simple to
> use CryptoAPI for swap devices. Looking back at the list archives I see
> that this is very similar to Jari's scheme for swap encryption with
> Loop-AES. Here's how I did it:

I do not recommend using cryptoapi for encrypted swap. It has nasties like
sleeping in make_request_fn() and potential memory allocation deadlock, both
of which should not affect non-swap use.
 
> Jari mentioned a potential problem of /dev/urandom lacking in entropy at
> boot time. I thought of a partial solution to that: make a script to
> swapoff and do it over again, and run it daily, from root's crontab
> (preferably at a non-busy time, of course.) Then you would only be
> vulnerable for the first day after booting.

Here is my latest version, have fun:
---------------- cut here ----------------
#!/bin/sh
# Run this script somewhere in your startup scripts _after_ random
# number generator has been initialized and /usr has been mounted.
# (md5sum, uuencode, tail and head programs usually reside in /usr/bin/)

# encrypted swap partition
SWAPDEVICE=/dev/hda666

# loop device name
LOOPDEV=/dev/loop6

MD=`dd if=${SWAPDEVICE} bs=4096 count=10 2>/dev/null | md5sum`
for X in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; do
    dd if=/dev/zero of=${SWAPDEVICE} bs=4096 count=10 conv=notrunc 2>/dev/null
    sync
done
UR=`dd if=/dev/urandom bs=18 count=1 2>/dev/null \
    | uuencode -m - | tail -2 | head -1`
DT=`date '+%s'`
echo ${MD}${UR}${DT} | losetup -p 0 -e AES128 ${LOOPDEV} ${SWAPDEVICE}
MD=
UR=
DT=
dd if=/dev/zero of=${LOOPDEV} bs=4096 count=10 conv=notrunc 2>/dev/null
sync
mkswap ${LOOPDEV}
sync
swapon ${LOOPDEV}
---------------- cut here ----------------

> Jari mentioned having some reliability problems with his. I haven't had
> a chance to test mine out yet. Under a light load it's doing fine with
> loop7 (the /SWAP file) and loop6 (a disk partition) as encrypted swap
> devices, while I also have another disk partition of unencrypted swap.

Reliability problems were (and are) kernel 2.4 instability problems under
insane workloads. All 2.4 kernels that I have tested under insane workloads,
fail without any crypto or loop loaded or installed. That happens with
Andrea's new VM too. No reliability problems with loop-AES itself.

Regards,
Jari Ruusu <jari.ruusu@xxxxxxxxxx>


Linux-crypto:  cryptography in and on the Linux system
Archive:       http://mail.nl.linux.org/linux-crypto/


[Index of Archives]     [Kernel]     [Linux Crypto]     [Gnu Crypto]     [Gnu Classpath]     [Netfilter]     [Bugtraq]
  Powered by Linux