freebsd-dev/sys/modules
John Baldwin b2e60773c6 Add kernel-side support for in-kernel TLS.
KTLS adds support for in-kernel framing and encryption of Transport
Layer Security (1.0-1.2) data on TCP sockets.  KTLS only supports
offload of TLS for transmitted data.  Key negotation must still be
performed in userland.  Once completed, transmit session keys for a
connection are provided to the kernel via a new TCP_TXTLS_ENABLE
socket option.  All subsequent data transmitted on the socket is
placed into TLS frames and encrypted using the supplied keys.

Any data written to a KTLS-enabled socket via write(2), aio_write(2),
or sendfile(2) is assumed to be application data and is encoded in TLS
frames with an application data type.  Individual records can be sent
with a custom type (e.g. handshake messages) via sendmsg(2) with a new
control message (TLS_SET_RECORD_TYPE) specifying the record type.

At present, rekeying is not supported though the in-kernel framework
should support rekeying.

KTLS makes use of the recently added unmapped mbufs to store TLS
frames in the socket buffer.  Each TLS frame is described by a single
ext_pgs mbuf.  The ext_pgs structure contains the header of the TLS
record (and trailer for encrypted records) as well as references to
the associated TLS session.

KTLS supports two primary methods of encrypting TLS frames: software
TLS and ifnet TLS.

Software TLS marks mbufs holding socket data as not ready via
M_NOTREADY similar to sendfile(2) when TLS framing information is
added to an unmapped mbuf in ktls_frame().  ktls_enqueue() is then
called to schedule TLS frames for encryption.  In the case of
sendfile_iodone() calls ktls_enqueue() instead of pru_ready() leaving
the mbufs marked M_NOTREADY until encryption is completed.  For other
writes (vn_sendfile when pages are available, write(2), etc.), the
PRUS_NOTREADY is set when invoking pru_send() along with invoking
ktls_enqueue().

A pool of worker threads (the "KTLS" kernel process) encrypts TLS
frames queued via ktls_enqueue().  Each TLS frame is temporarily
mapped using the direct map and passed to a software encryption
backend to perform the actual encryption.

(Note: The use of PHYS_TO_DMAP could be replaced with sf_bufs if
someone wished to make this work on architectures without a direct
map.)

KTLS supports pluggable software encryption backends.  Internally,
Netflix uses proprietary pure-software backends.  This commit includes
a simple backend in a new ktls_ocf.ko module that uses the kernel's
OpenCrypto framework to provide AES-GCM encryption of TLS frames.  As
a result, software TLS is now a bit of a misnomer as it can make use
of hardware crypto accelerators.

Once software encryption has finished, the TLS frame mbufs are marked
ready via pru_ready().  At this point, the encrypted data appears as
regular payload to the TCP stack stored in unmapped mbufs.

ifnet TLS permits a NIC to offload the TLS encryption and TCP
segmentation.  In this mode, a new send tag type (IF_SND_TAG_TYPE_TLS)
is allocated on the interface a socket is routed over and associated
with a TLS session.  TLS records for a TLS session using ifnet TLS are
not marked M_NOTREADY but are passed down the stack unencrypted.  The
ip_output_send() and ip6_output_send() helper functions that apply
send tags to outbound IP packets verify that the send tag of the TLS
record matches the outbound interface.  If so, the packet is tagged
with the TLS send tag and sent to the interface.  The NIC device
driver must recognize packets with the TLS send tag and schedule them
for TLS encryption and TCP segmentation.  If the the outbound
interface does not match the interface in the TLS send tag, the packet
is dropped.  In addition, a task is scheduled to refresh the TLS send
tag for the TLS session.  If a new TLS send tag cannot be allocated,
the connection is dropped.  If a new TLS send tag is allocated,
however, subsequent packets will be tagged with the correct TLS send
tag.  (This latter case has been tested by configuring both ports of a
Chelsio T6 in a lagg and failing over from one port to another.  As
the connections migrated to the new port, new TLS send tags were
allocated for the new port and connections resumed without being
dropped.)

ifnet TLS can be enabled and disabled on supported network interfaces
via new '[-]txtls[46]' options to ifconfig(8).  ifnet TLS is supported
across both vlan devices and lagg interfaces using failover, lacp with
flowid enabled, or lacp with flowid enabled.

Applications may request the current KTLS mode of a connection via a
new TCP_TXTLS_MODE socket option.  They can also use this socket
option to toggle between software and ifnet TLS modes.

In addition, a testing tool is available in tools/tools/switch_tls.
This is modeled on tcpdrop and uses similar syntax.  However, instead
of dropping connections, -s is used to force KTLS connections to
switch to software TLS and -i is used to switch to ifnet TLS.

Various sysctls and counters are available under the kern.ipc.tls
sysctl node.  The kern.ipc.tls.enable node must be set to true to
enable KTLS (it is off by default).  The use of unmapped mbufs must
also be enabled via kern.ipc.mb_use_ext_pgs to enable KTLS.

KTLS is enabled via the KERN_TLS kernel option.

This patch is the culmination of years of work by several folks
including Scott Long and Randall Stewart for the original design and
implementation; Drew Gallatin for several optimizations including the
use of ext_pgs mbufs, the M_NOTREADY mechanism for TLS records
awaiting software encryption, and pluggable software crypto backends;
and John Baldwin for modifications to support hardware TLS offload.

Reviewed by:	gallatin, hselasky, rrs
Obtained from:	Netflix
Sponsored by:	Netflix, Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D21277
2019-08-27 00:01:56 +00:00
..
3dfx
3dfx_linux
aac
aacraid
accf_data
accf_dns
accf_http
acl_nfs4
acl_posix1e
acpi
adlink
ae
aesni Add an AESNI-optimized version of the CCM/CBC cryptographic and authentication 2019-05-25 07:26:30 +00:00
age
agp
ahci
aic7xxx
alc
ale
allwinner The pwm interface was replaced with pwmbus, include the right header file. 2019-06-16 00:27:11 +00:00
alq
am335x_dmtpps
amd_ecc_inject
amdgpio Add amdgpio, driver for GPIO controller on AMD-based x86_64 platforms 2018-10-21 04:52:37 +00:00
amdsbwd
amdsmb
amdsmn
amdtemp
amr
an
aout
apm
ar71xx
arcmsr
arm_ti Add module makefiles for Texas Instruments ARM SoCs. 2019-06-16 01:22:44 +00:00
armv8crypto
asmc
ata
ath
ath_ahb
ath_dfs
ath_hal
ath_hal_ar5210
ath_hal_ar5211
ath_hal_ar5212
ath_hal_ar5416 Garbage collect AH_SUPPORT_AR5416 config option. 2019-01-25 13:48:40 +00:00
ath_hal_ar9300
ath_main
ath_pci
ath_rate
autofs
auxio
bce
bcm283x_clkman
bcm283x_pwm
bfe
bge
bhnd
bios Retire CLANG_NO_IAS34 2018-11-01 23:11:47 +00:00
bktr
blake2
bnxt
bridgestp
bwi
bwn
bxe
bytgpio
cam
cardbus
carp
cas
cbb
cc
ccp
cd9660
cd9660_iconv
ce
cfi
cfiscsi
chromebook_platform
chvgpio
ciss
cloudabi
cloudabi32
cloudabi64
cmx
coretemp
cp
cpsw
cpuctl
cpufreq
crypto Expose zlib's utility functions in Z_SOLO library when building kernel. 2019-08-07 01:41:17 +00:00
cryptodev
ctau
ctl
cuse
cx
cxgb
cxgbe cxgbe(4): Update T4/5/6 firmwares to 1.23.0.0. 2019-03-13 06:46:15 +00:00
dc
dcons
dcons_crom
dpms
dtb dtso: allwinner: Add an overlay for H3 thermal node 2019-08-24 13:26:34 +00:00
dtrace Disconnect fasttrap from the 32-bit powerpc build. 2019-02-21 22:49:21 +00:00
dummynet
efirt Add missing DPSRCS entry for assym.inc. 2019-06-11 23:35:49 +00:00
em Use symlinks for kernel modules rather than hardlinks 2019-04-20 12:51:05 +00:00
ena Update ENA version to v2.0.0 2019-05-30 13:52:32 +00:00
epic
epoch_test
esp
et
evdev
exca
ext2fs
fdc
fdescfs
fdt Add another required header file. 2019-03-01 04:17:43 +00:00
ffec
filemon
firewire
firmware
fusefs Remove the fuse.ko -> fusefs.ko symlink 2019-08-07 20:28:27 +00:00
fxp Remove a use of a negative array index from fxp(4). 2018-12-19 04:54:32 +00:00
gem
geom geom_uzip(4), mkuzip(8): Add Zstd image mode 2019-08-13 23:32:56 +00:00
glxiic
glxsb
gpio
hifn
hme
hpt27xx
hptiop
hptmv
hptnr
hptrr
hwpmc Don't attempt to include hwpmc support for armv6, we're missing some of the 2019-06-12 16:05:20 +00:00
hwpmc_mips24k Add dependent header files 2019-03-28 08:30:45 +00:00
hwpmc_mips74k Add dependent header files 2019-03-28 08:30:45 +00:00
hyperv
i2c Add a driver for Texas Instruments ADS101x/ADS111x i2c ADC chips. 2019-08-05 15:56:44 +00:00
iavf Use symlinks for kernel modules rather than hardlinks 2019-04-20 12:51:05 +00:00
ibcore
ichwd
ida
if_bridge
if_disc
if_edsc
if_enc
if_epair
if_gif
if_gre Add GRE-in-UDP encapsulation support as defined in RFC8086. 2019-04-24 09:05:45 +00:00
if_lagg
if_me
if_ndis
if_stf
if_tuntap tun/tap: merge and rename to tuntap 2019-05-08 02:32:11 +00:00
if_vlan
if_vxlan
iflib Fix make in sys/modules 2019-03-28 08:59:11 +00:00
iir
imgact_binmisc
imx
intelspi
io
ioat
ip6_mroute_mod
ip_mroute_mod
ipdivert
ipfilter Whitespace adjustment. 2019-06-06 03:02:25 +00:00
ipfw
ipfw_nat
ipfw_nat64 Reapply r345274 with build fixes for 32-bit architectures. 2019-03-19 10:57:03 +00:00
ipfw_nptv6
ipfw_pmod
ipmi
ipoib
ips
ipsec Revert r347402. After r347429 symlink is no longer needed. 2019-05-13 08:34:13 +00:00
ipw
ipwfw
isci
iscsi
iscsi_initiator
iser
isp
ispfw
iwi
iwifw
iwm
iwmfw Stop using .OODATE for extracting firmware. 2019-06-12 00:03:00 +00:00
iwn
iwnfw Stop using .OODATE for extracting firmware. 2019-06-12 00:03:00 +00:00
ix
ixl ixl/iavf(4): Change ixlv to iavf and update it to use iflib(9) 2018-10-12 22:40:54 +00:00
ixv
jme
kbdmux
kgssapi
kgssapi_krb5
khelp
krpc
ksyms
ktls_ocf Add kernel-side support for in-kernel TLS. 2019-08-27 00:01:56 +00:00
le
lge
libalias
libiconv
libmchain
lindebugfs LinuxKPI: Finalize move of lindebugfs from ports to base. 2019-05-19 15:44:21 +00:00
linprocfs Add warning to the Linuxulator makefiles that building it outside of a 2019-05-13 18:28:40 +00:00
linsysfs Add warning to the Linuxulator makefiles that building it outside of a 2019-05-13 18:28:40 +00:00
linux Replace -Werror with ${WERROR} in module builds 2019-08-25 22:06:17 +00:00
linux64 Replace -Werror with ${WERROR} in module builds 2019-08-25 22:06:17 +00:00
linux_common Add warning to the Linuxulator makefiles that building it outside of a 2019-05-13 18:28:40 +00:00
linuxkpi LinuxKPI: Finalize import of seq_file. 2019-05-16 21:17:18 +00:00
lio
lpt
mac_biba
mac_bsdextended
mac_ifoff
mac_lomac
mac_mls
mac_none
mac_ntpd
mac_partition
mac_portacl
mac_seeotheruids
mac_stub
mac_test
mac_veriexec
mac_veriexec_sha1
mac_veriexec_sha256
mac_veriexec_sha384
mac_veriexec_sha512
malo
md
mdio
mem
mfi
mii
mlx
mlx4
mlx4en
mlx4ib
mlx5 mlx5fpga: Initial code import. 2018-12-05 14:11:20 +00:00
mlx5en Add support for Dynamic Interrupt Moderation, DIM, in mlx5en(4). 2019-05-08 10:23:33 +00:00
mlx5fpga_tools mlx5fpga_tools initial code import. 2018-12-05 14:17:22 +00:00
mlx5ib mlx5fpga: Initial code import. 2018-12-05 14:11:20 +00:00
mlxfw Initial version of Mellanox in-kernel firmware upgrade support. 2019-05-08 10:49:05 +00:00
mly
mmc
mmcnull
mmcsd
mpr
mps
mpt
mqueue
mrsas
msdosfs
msdosfs_iconv
msk
mthca
mvs
mwl
mwlfw Stop using .OODATE for extracting firmware. 2019-06-12 00:03:00 +00:00
mxge Expose zlib's utility functions in Z_SOLO library when building kernel. 2019-08-07 01:41:17 +00:00
my
nctgpio
ndis
netfpga10g
netgraph ng_ubt(4): do not attach Intel Wireless 8260/8265 in bootloader mode. 2019-08-18 22:11:42 +00:00
netmap netmap: align codebase to the current upstream (760279cfb2730a585) 2018-12-05 11:57:16 +00:00
nfe
nfscl
nfscommon Fix build in sys/modules/nfscommon 2019-04-10 16:48:45 +00:00
nfsd Add support for INET6 addresses to the kernel code that dumps open/lock state. 2019-04-13 22:00:09 +00:00
nfslock
nfslockd
nfssvc
nge
nmdm
ntb Forgotten part of r351137. 2019-08-16 20:30:31 +00:00
nullfs
nvd
nvdimm Fix make in sys/modules 2019-03-28 08:59:11 +00:00
nvme Create a AHCI attachment for nvme. 2019-08-21 22:18:01 +00:00
nvram
oce
ocs_fc Don't delete .depend files outside of cleandepend. 2019-06-12 23:09:10 +00:00
opensolaris Export cpu_core from opensolaris.ko. 2019-04-20 11:34:53 +00:00
otus
otusfw
ow
padlock
padlock_rng
pccard
pcfclock
pf
pflog
pfsync
plip
pms
powermac_nvram
ppbus
ppc
ppi
pps
procfs
proto
pseudofs
pst
pty
puc
pwm Add ofw_pwmbus to enumerate pwmbus devices on systems configured with fdt 2019-06-17 03:32:05 +00:00
qlnx qlnxr(4), qlnxe(4): Unbreak gcc build 2019-02-01 23:04:45 +00:00
qlxgb
qlxgbe
qlxge
ral
ralfw Stop using .OODATE for extracting firmware. 2019-06-12 00:03:00 +00:00
random_fortuna
random_other
rc
rc4
rccgpio
rdma
rdrand_rng
re
rl
rndtest
rockchip Add RK805 PMIC Support 2018-11-28 13:53:43 +00:00
rp
rpi_ft5406
rtwn
rtwn_pci rtwn_pci(4): add support for RTL8188EE chipset. 2019-01-02 06:48:53 +00:00
rtwn_usb rtwn_pci(4): add support for event-based Tx reports. 2019-01-02 05:21:06 +00:00
rtwnfw Stop using .OODATE for extracting firmware. 2019-06-12 00:03:00 +00:00
s3
safe
sbni
scc
sdhci
sdhci_acpi
sdhci_pci
sdio Add opt_cam.h so we can build this outside of a kernel build. 2019-06-13 22:03:53 +00:00
sem
send
sfxge sfxge(4): add generated description of sensors 2018-11-30 05:54:30 +00:00
sge
sgx
sgx_linux
siftr
siis
sio
sis
sk
smartpqi
smbfs
snp
sound
speaker
spi
spigen
splash
sppp
ste
stge
superio add superio driver 2019-07-01 17:05:41 +00:00
sym
syscons
sysvipc
tcp This commit updates rack to what is basically being used at NF as 2019-07-10 20:40:39 +00:00
tests
ti Add module makefiles for Texas Instruments ARM SoCs. 2019-06-16 01:22:44 +00:00
tmpfs Make TMPFS_PAGES_MINRESERVED a kernel option 2019-03-25 07:46:20 +00:00
toecore
tpm Fix make in sys/modules 2019-03-28 08:59:11 +00:00
trm
tsec
twa
twe
tws
uart
ubsec
ubser
uchcom
ucycom
udf
udf_iconv
ufs
uinput
unionfs
usb Add cdceem(4) driver, for virtual ethernet devices compliant 2019-08-07 18:14:45 +00:00
veriexec
vesa
vge
viawd
videomode
virtio
vkbd
vmm
vmware Add missing dependency to vmxnet3 Makefile and clean it up a bit otherwise. 2019-01-22 04:36:19 +00:00
vnic
vpo
vr
vte
wbwd
wi
wlan
wlan_acl
wlan_amrr
wlan_ccmp
wlan_rssadapt
wlan_tkip
wlan_wep
wlan_xauth
wpi
wpifw
wtap
x86bios
xl
xz Modularize xz. 2019-02-26 19:55:03 +00:00
zfs Expose zlib's utility functions in Z_SOLO library when building kernel. 2019-08-07 01:41:17 +00:00
zlib Remove zlib 1.0.4 from kernel. 2019-08-25 17:13:00 +00:00
Makefile Add kernel-side support for in-kernel TLS. 2019-08-27 00:01:56 +00:00
Makefile.inc