opnsense-src/sys
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
..
amd64 Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
arm Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
arm64 Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
boot dd is currently a bootstrap tool. It really doesn't have any business 2016-12-02 14:44:38 +00:00
bsm
cam Add SCSI REPORT TIMESTAMP and SET TIMESTAMP support. 2016-12-01 22:20:27 +00:00
cddl Don't create FBT probes for lock owner methods. 2016-12-10 03:13:11 +00:00
compat Add more LinuxKPI PCI definitions. 2016-12-09 15:05:09 +00:00
conf Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
contrib Add a FREEBSD-Xlist file for CK. 2016-11-28 21:16:03 +00:00
crypto Add accelerated AES with using the ARMv8 crypto instructions. This is based 2016-11-21 11:18:00 +00:00
ddb Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
dev Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
fs Fix the NFSv4.1 server for Open reclaim after a reboot. 2016-12-05 22:36:25 +00:00
gdb
geom Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
gnu Add Ingenic X1000 DTS files (unofficial). 2016-11-19 15:03:49 +00:00
i386 Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
isa
kern Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
kgssapi
libkern Update r309143 to prevent false sharing. 2016-11-25 17:20:23 +00:00
mips Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
modules cxgbe(4): Update firmwares from version 1.16.12.0 to 1.16.22.0. 2016-12-06 12:43:07 +00:00
net Fix the typos and style(9) in comment. 2016-12-08 18:18:48 +00:00
net80211 [net80211] add a field for storing a 64 bit TSC. 2016-12-08 07:57:16 +00:00
netgraph Changes to allow the patching of packets with an offset (and other changes.. see man page) 2016-12-02 10:47:10 +00:00
netinet Fix build for 32-bit machines. 2016-12-09 20:50:35 +00:00
netinet6 Whitespace changes. 2016-12-06 10:21:25 +00:00
netipsec Add a missing header 2016-11-26 23:15:11 +00:00
netnatm
netpfil Improve upon r309394 2016-12-10 03:31:38 +00:00
netsmb
nfs Hide the boottime and bootimebin globals, provide the getboottime(9) 2016-07-27 11:08:59 +00:00
nfsclient
nfsserver
nlm
ofed Move the ConnectX-3 and ConnectX-2 driver from sys/ofed into sys/dev/mlx4 2016-09-30 08:23:06 +00:00
opencrypto Add support for the fpu_kern(9) KPI on arm64. It hooks into the existing 2016-10-20 09:22:10 +00:00
pc98 Add a COMPAT_FREEBSD11 kernel option. 2016-12-09 18:54:12 +00:00
powerpc Add a COMPAT_FREEBSD11 kernel option. 2016-12-09 18:54:12 +00:00
riscv Disable superpages reservations as we don't have implemented them yet. 2016-11-21 12:00:31 +00:00
rpc Hide the boottime and bootimebin globals, provide the getboottime(9) 2016-07-27 11:08:59 +00:00
security Audit 'fd' and 'cmd' arguments to fcntl(2), and when generating BSM, 2016-11-22 00:41:24 +00:00
sparc64 Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
sys Add support for encrypted kernel crash dumps. 2016-12-10 16:20:39 +00:00
teken
tests
tools Consider CROSS_BINUTILS_PREFIX environment variable so we use correct 2016-08-10 13:49:17 +00:00
ufs Release laundered vnode pages to the head of the inactive queue. 2016-11-23 17:53:07 +00:00
vm Allow bogus_page to be passed to pager(s). 2016-12-09 21:21:24 +00:00
x86 Require the STACK option for code that captures stacks of running threads. 2016-12-06 22:48:28 +00:00
xdr
xen xen: add a grant-table user-space device 2016-10-31 13:12:58 +00:00
Makefile