freebsd-dev/sys/geom
Konrad Witaszczyk 480f31c214 Add support for encrypted kernel crash dumps.
Changes include modifications in kernel crash dump routines, dumpon(8) and
savecore(8). A new tool called decryptcore(8) was added.

A new DIOCSKERNELDUMP I/O control was added to send a kernel crash dump
configuration in the diocskerneldump_arg structure to the kernel.
The old DIOCSKERNELDUMP I/O control was renamed to DIOCSKERNELDUMP_FREEBSD11 for
backward ABI compatibility.

dumpon(8) generates an one-time random symmetric key and encrypts it using
an RSA public key in capability mode. Currently only AES-256-CBC is supported
but EKCD was designed to implement support for other algorithms in the future.
The public key is chosen using the -k flag. The dumpon rc(8) script can do this
automatically during startup using the dumppubkey rc.conf(5) variable.  Once the
keys are calculated dumpon sends them to the kernel via DIOCSKERNELDUMP I/O
control.

When the kernel receives the DIOCSKERNELDUMP I/O control it generates a random
IV and sets up the key schedule for the specified algorithm. Each time the
kernel tries to write a crash dump to the dump device, the IV is replaced by
a SHA-256 hash of the previous value. This is intended to make a possible
differential cryptanalysis harder since it is possible to write multiple crash
dumps without reboot by repeating the following commands:
# sysctl debug.kdb.enter=1
db> call doadump(0)
db> continue
# savecore

A kernel dump key consists of an algorithm identifier, an IV and an encrypted
symmetric key. The kernel dump key size is included in a kernel dump header.
The size is an unsigned 32-bit integer and it is aligned to a block size.
The header structure has 512 bytes to match the block size so it was required to
make a panic string 4 bytes shorter to add a new field to the header structure.
If the kernel dump key size in the header is nonzero it is assumed that the
kernel dump key is placed after the first header on the dump device and the core
dump is encrypted.

Separate functions were implemented to write the kernel dump header and the
kernel dump key as they need to be unencrypted. The dump_write function encrypts
data if the kernel was compiled with the EKCD option. Encrypted kernel textdumps
are not supported due to the way they are constructed which makes it impossible
to use the CBC mode for encryption. It should be also noted that textdumps don't
contain sensitive data by design as a user decides what information should be
dumped.

savecore(8) writes the kernel dump key to a key.# file if its size in the header
is nonzero. # is the number of the current core dump.

decryptcore(8) decrypts the core dump using a private RSA key and the kernel
dump key. This is performed by a child process in capability mode.
If the decryption was not successful the parent process removes a partially
decrypted core dump.

Description on how to encrypt crash dumps was added to the decryptcore(8),
dumpon(8), rc.conf(5) and savecore(8) manual pages.

EKCD was tested on amd64 using bhyve and i386, mipsel and sparc64 using QEMU.
The feature still has to be tested on arm and arm64 as it wasn't possible to run
FreeBSD due to the problems with QEMU emulation and lack of hardware.

Designed by:	def, pjd
Reviewed by:	cem, oshogbo, pjd
Partial review:	delphij, emaste, jhb, kib
Approved by:	pjd (mentor)
Differential Revision:	https://reviews.freebsd.org/D4712
2016-12-10 16:20:39 +00:00
..
bde Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
cache
concat Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
eli Fix alignment issues on MIPS: align the pointers properly. 2016-10-31 16:55:14 +00:00
gate Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
journal Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
label Relax checking if the privider size matches size recorded in the 2016-07-18 05:00:01 +00:00
linux_lvm Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
mirror Add gmirror create subcommand, alike to gstripe, gconcat, etc. 2016-11-30 09:27:08 +00:00
mountver Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
multipath Do not report error on close even if we have no paths left. 2016-11-12 18:57:38 +00:00
nop
part Add BUF_TRACKING and FULL_BUF_TRACKING buffer debugging 2016-10-31 23:09:52 +00:00
raid Fix improper use of "its". 2016-11-08 23:59:41 +00:00
raid3 Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
sched Cleanup unnecessary semicolons from the kernel. 2016-04-10 23:07:00 +00:00
shsec Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
stripe Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
uzip 1.Improve handling around last compressed block of the file, which is 2016-06-29 18:19:05 +00:00
vinum Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
virstor Use g_wither_provider() where applicable. 2016-09-23 21:29:40 +00:00
zero
geom_aes.c
geom_bsd_enc.c sys/geom: spelling fixes in comments. 2016-04-29 20:56:58 +00:00
geom_bsd.c
geom_ccd.c sys/geom: spelling fixes in comments. 2016-04-29 20:56:58 +00:00
geom_ctl.c geom: unsign some types to match their definitions and avoid overflows. 2016-04-27 15:10:40 +00:00
geom_ctl.h
geom_dev.c Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
geom_disk.c Add BUF_TRACKING and FULL_BUF_TRACKING buffer debugging 2016-10-31 23:09:52 +00:00
geom_disk.h Switch geom_disk over to using a pool mutex. 2016-06-23 20:05:59 +00:00
geom_dump.c
geom_event.c Remove asserts that Giant is not held on entrance into geom KPI, which 2016-05-20 08:22:20 +00:00
geom_flashmap.c
geom_fox.c
geom_int.h
geom_io.c Add BUF_TRACKING and FULL_BUF_TRACKING buffer debugging 2016-10-31 23:09:52 +00:00
geom_kern.c Remove unneeded Giant locking around kthreads creation. 2016-05-20 08:28:11 +00:00
geom_map.c
geom_mbr_enc.c sys/geom: spelling fixes in comments. 2016-04-29 20:56:58 +00:00
geom_mbr.c Removal of Giant droping wrappers for GEOM classes. 2016-05-20 08:25:37 +00:00
geom_pc98_enc.c
geom_pc98.c Removal of Giant droping wrappers for GEOM classes. 2016-05-20 08:25:37 +00:00
geom_redboot.c [geom_redboot] Extend geom_redboot to handle non-zero fis offset. 2016-10-04 16:35:38 +00:00
geom_slice.c
geom_slice.h
geom_subr.c Add BUF_TRACKING and FULL_BUF_TRACKING buffer debugging 2016-10-31 23:09:52 +00:00
geom_sunlabel_enc.c sys/geom: spelling fixes in comments. 2016-04-29 20:56:58 +00:00
geom_sunlabel.c
geom_vfs.c Add BUF_TRACKING and FULL_BUF_TRACKING buffer debugging 2016-10-31 23:09:52 +00:00
geom_vfs.h
geom_vol_ffs.c
geom.h Remove asserts that Giant is not held on entrance into geom KPI, which 2016-05-20 08:22:20 +00:00
notes