File:  [NetBSD Developer Wiki] / wikisrc / security / cgdroot.mdwn
Revision 1.8: download - view: text, annotated - select for diffs
Fri Feb 10 10:42:44 2017 UTC (5 years, 3 months ago) by khorben
Branches: MAIN
CVS tags: HEAD
Try to clarify a bit more

    1: Root filesystem encryption
    2: ==========================
    3: 
    4: It is possible to run NetBSD with [complete root filesystem encryption][1], thanks to the `cgdroot.kmod` kernel module. It really is a memory disk (also knows as RAM disk) that is expected to be loaded in the kernel while booting. It is named after CGD, the "cryptographic device driver", which implements encryption for storage in the NetBSD kernel.
    5: 
    6: Full disk encryption makes it more difficult for an attacker to modify the unencrypted part of the disk to plant a backdoor. With only partial encryption, the original [[!template id=man name="cgdconfig" section="8"]] binary may be modified to send the passphrase away, allowing an attacker with a disk dump to recover the data.
    7: 
    8: The mechanism described here still requires one unencrypted partition to boot from (typically `wd0a`).
    9: 
   10: The boot process
   11: ----------------
   12: 
   13: Instead of booting normally the GENERIC kernel and using the root filesystem, a kernel module is loaded at boot-time containing a memory disk. This minimal filesystem image is then considered the actual root filesystem.
   14: 
   15: The boot partition on disk only needs to contain:
   16: 
   17: * [[!template id=man name="boot" section="8"]], the second-stage bootloader
   18: * [[!template id=man name="boot.cfg" section="5"]], the configuration file for the bootloader (optional)
   19: * a GENERIC kernel
   20: * the `cgdroot.kmod` kernel module
   21: * the configuration file for CGD, `cgd.conf`
   22: * the encryption key for the volume to start from, named after its partition (like `wd0f`)
   23: 
   24: Once loaded the memory disk mounts the `wd0a` partition onto `/etc/cgd`, and asks for the encryption passphrase as usual (with [[!template id=man name="cgdconfig" section="8"]]). If successful, the `cgd0a` volume configured is mounted on `/altroot`, and [[!template id=man name="init" section="8"]] is told via [[!template id=man name="sysctl" section="7"]] to chroot into this volume before actually booting. The system then starts normally.
   25: 
   26: In practice the memory disk remains the real root, and the regular system is
   27: really ran from a chroot in `/altroot`.
   28: 
   29: Obtaining the kernel module
   30: ---------------------------
   31: 
   32: The `cgdroot.kmod` kernel module is part of the regular NetBSD releases since NetBSD 7.0. It can be found in the `<arch>/installation/miniroot` folder from the release. For instance, for the amd64 architecture on the German mirror for the 7.0.1 release, download it at (ftp://ftp.de.netbsd.org/pub/NetBSD/NetBSD-7.0.1/amd64/installation/miniroot/cgdroot.kmod).
   33: 
   34: Configuring the kernel module
   35: -----------------------------
   36: 
   37: The kernel module needs to be available in the boot partition, alongside the desired kernel. The bootloader configuration in `/boot.cfg` should be modified to load the module, as in this example:
   38: 
   39: [[!template id=filecontent name="/boot.cfg" text="""
   40: menu=Boot normally:rndseed /etc/entropy-file;load /cgdroot.kmod;boot /netbsd.gz -z
   41: """]]
   42: 
   43: Building the kernel module
   44: --------------------------
   45: 
   46: The kernel module can be compiled in two steps from within the source tree for the NetBSD base system, once the distribution has been built. Change to the `distrib/<arch>/ramdisks/ramdisk-cgdroot` and use `nbmake-<arch>` to build:
   47: 
   48: [[!template id=programlisting text="""
   49: src/distrib/amd64/ramdisks/ramdisk-cgdroot$ /path/to/tooldir/bin/nbmake-amd64
   50: [...]
   51:      create  ramdisk-cgdroot/ramdisk-cgdroot.fs
   52: Calculated size of `ramdisk-cgdroot.fs.tmp': 5120000 bytes, 85 inodes
   53: Extent size set to 4096
   54: ramdisk-cgdroot.fs.tmp: 4.9MB (10000 sectors) block size 4096, fragment size 512
   55:         using 1 cylinder groups of 4.88MB, 1250 blks, 96 inodes.
   56: super-block backups (for fsck -b #) at:
   57:  32,
   58: Populating `ramdisk-cgdroot.fs.tmp'
   59: Image `ramdisk-cgdroot.fs.tmp' complete
   60: """]]
   61: 
   62: Then the kernel module can be built:
   63: 
   64: [[!template id=programlisting text="""
   65: src/distrib/amd64/kmod-cgdroot$ /path/to/tooldir/bin/nbmake-amd64
   66: """]]
   67: 
   68: Caveats
   69: -------
   70: 
   71: The biggest (known) issue with this setup occurs when firmware needs to be loaded early in the boot process (such as graphics drivers for the console). At the moment they need to be provided as part of the memory disk. Some network interfaces, of which some wireless devices in particular, also require loading firmware to work properly.
   72: 
   73: This setup is not entirely safe against physical attacks. An attacker can modify the boot process to store the passphrase for later retrieval, or insert a backdoor while booting. To defend against such attacks, the bootloader, kernel and ramdisk all need to be signed and their integrity checked before booting (eg with [[!template id=man name="tpm" section="4"]]). Alternatively, it is possible to boot from a removable medium (eg USB stick), which can be protected against tampering attacks (eg secure storage, read-only volume...).
   74: 
   75: It is also possible to boot a Xen DOM0 system with root filesystem encryption. However, Xen-enabled NetBSD kernels currently do not support loading modules at boot-time. The memory disk has to be placed directly inside the kernel instead (with [[!template id=man name="mdconfig" section="8"]] or a new kernel configuration).
   76: 
   77: References
   78: ----------
   79: 
   80: * [Full Disk Encryption with cgd (well, almost)][1]
   81: 
   82: [1]: https://mail-index.netbsd.org/current-users/2013/03/21/msg022311.html "Full Disk Encryption with cgd (well, almost)"

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb