xref: /freebsd/share/man/man4/ktls.4 (revision d1e0552937e18bef661fb9ace710bcaa1b5d5a80)
1*d1e05529SJohn Baldwin.\" Copyright (c) 2020, Chelsio Inc
2*d1e05529SJohn Baldwin.\" All rights reserved.
3*d1e05529SJohn Baldwin.\"
4*d1e05529SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
5*d1e05529SJohn Baldwin.\" modification, are permitted provided that the following conditions are met:
6*d1e05529SJohn Baldwin.\"
7*d1e05529SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright notice,
8*d1e05529SJohn Baldwin.\"    this list of conditions and the following disclaimer.
9*d1e05529SJohn Baldwin.\"
10*d1e05529SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
11*d1e05529SJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
12*d1e05529SJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
13*d1e05529SJohn Baldwin.\"
14*d1e05529SJohn Baldwin.\" 3. Neither the name of the Chelsio Inc nor the names of its
15*d1e05529SJohn Baldwin.\"    contributors may be used to endorse or promote products derived from
16*d1e05529SJohn Baldwin.\"    this software without specific prior written permission.
17*d1e05529SJohn Baldwin.\"
18*d1e05529SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*d1e05529SJohn Baldwin.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*d1e05529SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*d1e05529SJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22*d1e05529SJohn Baldwin.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*d1e05529SJohn Baldwin.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*d1e05529SJohn Baldwin.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*d1e05529SJohn Baldwin.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*d1e05529SJohn Baldwin.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*d1e05529SJohn Baldwin.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*d1e05529SJohn Baldwin.\" POSSIBILITY OF SUCH DAMAGE.
29*d1e05529SJohn Baldwin.\"
30*d1e05529SJohn Baldwin.\" * Other names and brands may be claimed as the property of others.
31*d1e05529SJohn Baldwin.\"
32*d1e05529SJohn Baldwin.\" $FreeBSD$
33*d1e05529SJohn Baldwin.\"
34*d1e05529SJohn Baldwin.Dd November 25, 2020
35*d1e05529SJohn Baldwin.Dt KTLS 4
36*d1e05529SJohn Baldwin.Os
37*d1e05529SJohn Baldwin.Sh NAME
38*d1e05529SJohn Baldwin.Nm ktls
39*d1e05529SJohn Baldwin.Nd kernel Transport Layer Security
40*d1e05529SJohn Baldwin.Sh SYNOPSIS
41*d1e05529SJohn Baldwin.Cd options KERN_TLS
42*d1e05529SJohn Baldwin.Sh DESCRIPTION
43*d1e05529SJohn BaldwinThe
44*d1e05529SJohn Baldwin.Nm
45*d1e05529SJohn Baldwinfacility allows the kernel to perform Transport Layer Security (TLS)
46*d1e05529SJohn Baldwinframing on TCP sockets.
47*d1e05529SJohn BaldwinWith
48*d1e05529SJohn Baldwin.Nm ,
49*d1e05529SJohn Baldwinthe initial handshake for a socket using TLS is performed in userland.
50*d1e05529SJohn BaldwinOnce the session keys are negotiated,
51*d1e05529SJohn Baldwinthey are provided to the kernel via the
52*d1e05529SJohn Baldwin.Dv TCP_TXTLS_ENABLE
53*d1e05529SJohn Baldwinand
54*d1e05529SJohn Baldwin.Dv TCP_RXTLS_ENABLE
55*d1e05529SJohn Baldwinsocket options.
56*d1e05529SJohn BaldwinBoth socket options accept a
57*d1e05529SJohn Baldwin.Vt struct tls_so_enable
58*d1e05529SJohn Baldwinstructure as their argument.
59*d1e05529SJohn BaldwinThe members of this structure describe the cipher suite used for the
60*d1e05529SJohn BaldwinTLS session and provide the session keys used for the respective
61*d1e05529SJohn Baldwindirection.
62*d1e05529SJohn Baldwin.Pp
63*d1e05529SJohn Baldwin.Nm
64*d1e05529SJohn Baldwinonly permits the session keys to be set once in each direction.
65*d1e05529SJohn BaldwinAs a result,
66*d1e05529SJohn Baldwinapplications must disable rekeying when using
67*d1e05529SJohn Baldwin.Nm .
68*d1e05529SJohn Baldwin.Ss Modes
69*d1e05529SJohn Baldwin.Nm
70*d1e05529SJohn Baldwincan operate in different modes.
71*d1e05529SJohn BaldwinA given socket may use different modes for transmit and receive,
72*d1e05529SJohn Baldwinor a socket may only offload a single direction.
73*d1e05529SJohn BaldwinThe available modes are:
74*d1e05529SJohn Baldwin.Bl -tag -width "Dv TCP_TLS_MODE_IFNET"
75*d1e05529SJohn Baldwin.It Dv TCP_TLS_MODE_NONE
76*d1e05529SJohn Baldwin.Nm
77*d1e05529SJohn Baldwinis not enabled.
78*d1e05529SJohn Baldwin.It Dv TCP_TLS_MODE_SW
79*d1e05529SJohn BaldwinTLS records are encrypted or decrypted in the kernel in the socket
80*d1e05529SJohn Baldwinlayer.
81*d1e05529SJohn BaldwinTypically the encryption or decryption is performred in software,
82*d1e05529SJohn Baldwinbut it may also be performed by co-processors via
83*d1e05529SJohn Baldwin.Xr crypto 9 .
84*d1e05529SJohn Baldwin.It Dv TCP_TLS_MODE_IFNET
85*d1e05529SJohn BaldwinTLS records are encrypted or decrypted by the network interface card (NIC).
86*d1e05529SJohn BaldwinIn this mode, the network stack does not work with encrypted data.
87*d1e05529SJohn BaldwinInstead, the NIC is encrypts TLS records as they are being transmitted,
88*d1e05529SJohn Baldwinor decrypts received TLS records before providing them to the host.
89*d1e05529SJohn Baldwin.Pp
90*d1e05529SJohn BaldwinNetwork interfaces which support this feature will advertise the
91*d1e05529SJohn Baldwin.Dv TXTLS4
92*d1e05529SJohn Baldwin(for IPv4)
93*d1e05529SJohn Baldwinand/or
94*d1e05529SJohn Baldwin.Dv TXTLS6
95*d1e05529SJohn Baldwin(for IPv6)
96*d1e05529SJohn Baldwincapabilities as reported by
97*d1e05529SJohn Baldwin.Xr ifconfig 8 .
98*d1e05529SJohn BaldwinThese capabilities can also be controlled by
99*d1e05529SJohn Baldwin.Xr ifconfig 8 .
100*d1e05529SJohn Baldwin.Pp
101*d1e05529SJohn BaldwinIf a network interface supports rate limiting
102*d1e05529SJohn Baldwin(also known as packet pacing) for TLS offload,
103*d1e05529SJohn Baldwinthe interface will advertise the
104*d1e05529SJohn Baldwin.Dv TXTLS_RTLMT
105*d1e05529SJohn Baldwincapability.
106*d1e05529SJohn Baldwin.It Dv TCP_TLS_MODE_TOE
107*d1e05529SJohn BaldwinTLS records are encrypted by the NIC using a TCP offload engine (TOE).
108*d1e05529SJohn BaldwinThis is similar to
109*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_IFNET
110*d1e05529SJohn Baldwinin that the network stack does not work with encrypted data.
111*d1e05529SJohn BaldwinHowever, this mode works in tandem with a TOE to handle interactions
112*d1e05529SJohn Baldwinbetween TCP and TLS.
113*d1e05529SJohn Baldwin.El
114*d1e05529SJohn Baldwin.Ss Transmit
115*d1e05529SJohn BaldwinOnce TLS transmit is enabled by a successful set of the
116*d1e05529SJohn Baldwin.Dv TCP_TXTLS_ENABLE
117*d1e05529SJohn Baldwinsocket option,
118*d1e05529SJohn Baldwinall data written on the socket is stored in TLS records and encrypted.
119*d1e05529SJohn BaldwinMost data is transmitted in application layer TLS records,
120*d1e05529SJohn Baldwinand the kernel chooses how to partition data among TLS records.
121*d1e05529SJohn BaldwinIndividual TLS records with a fixed length and record type can be sent
122*d1e05529SJohn Baldwinby
123*d1e05529SJohn Baldwin.Xr sendmsg 2
124*d1e05529SJohn Baldwinwith the TLS record type set in a
125*d1e05529SJohn Baldwin.Dv TLS_SET_RECORD_TYPE
126*d1e05529SJohn Baldwincontrol message.
127*d1e05529SJohn BaldwinThe payload of this control message is a single byte holding the desired
128*d1e05529SJohn BaldwinTLS record type.
129*d1e05529SJohn BaldwinThis can be used to send TLS records with a type other than
130*d1e05529SJohn Baldwinapplication data (for example, handshake messages) or to send
131*d1e05529SJohn Baldwinapplication data records with specific contents (for example, empty
132*d1e05529SJohn Baldwinfragments).
133*d1e05529SJohn Baldwin.Pp
134*d1e05529SJohn BaldwinTLS transmit requires the use of unmapped mbufs.
135*d1e05529SJohn BaldwinUnmapped mbufs are not enabled by default, but can be enabled by
136*d1e05529SJohn Baldwinsetting the
137*d1e05529SJohn Baldwin.Va kern.ipc.mb_use_ext_pgs
138*d1e05529SJohn Baldwinsysctl node to 1.
139*d1e05529SJohn Baldwin.Pp
140*d1e05529SJohn BaldwinThe current TLS transmit mode of a socket can be queried via the
141*d1e05529SJohn Baldwin.Dv TCP_TXTLS_MODE
142*d1e05529SJohn Baldwinsocket option.
143*d1e05529SJohn BaldwinA socket using TLS transmit offload can also set the
144*d1e05529SJohn Baldwin.Dv TCP_TXTLS_MODE
145*d1e05529SJohn Baldwinsocket option to toggle between
146*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_SW
147*d1e05529SJohn Baldwinand
148*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_IFNET .
149*d1e05529SJohn Baldwin.Ss Receive
150*d1e05529SJohn BaldwinOnce TLS receive is enabled by a successful set of the
151*d1e05529SJohn Baldwin.Dv TCP_RXTLS_ENABLE
152*d1e05529SJohn Baldwinsocket option,
153*d1e05529SJohn Baldwinall data read from the socket is returned as decrypted TLS records.
154*d1e05529SJohn BaldwinEach received TLS record must be read from the socket using
155*d1e05529SJohn Baldwin.Xr recvmsg 2 .
156*d1e05529SJohn BaldwinEach received TLS record will contain a
157*d1e05529SJohn Baldwin.Dv TLS_GET_RECORD
158*d1e05529SJohn Baldwincontrol message along with the decrypted payload.
159*d1e05529SJohn BaldwinThe control message contains a
160*d1e05529SJohn Baldwin.Vt struct tls_get_record
161*d1e05529SJohn Baldwinwhich includes fields from the TLS record header.
162*d1e05529SJohn BaldwinIf an invalid or corrupted TLS record is received,
163*d1e05529SJohn Baldwinrecvmsg 2
164*d1e05529SJohn Baldwinwill fail with one of the following errors:
165*d1e05529SJohn Baldwin.Bl -tag -width Er
166*d1e05529SJohn Baldwin.It Bq Er EINVAL
167*d1e05529SJohn BaldwinThe version fields in a TLS record's header did not match the version required
168*d1e05529SJohn Baldwinby the
169*d1e05529SJohn Baldwin.Vt struct tls_so_enable
170*d1e05529SJohn Baldwinstructure used to enable in-kernel TLS.
171*d1e05529SJohn Baldwin.It Bq Er EMSGSIZE
172*d1e05529SJohn BaldwinA TLS record's length was either too small or too large.
173*d1e05529SJohn Baldwin.It Bq Er EMSGSIZE
174*d1e05529SJohn BaldwinThe connection was closed after sending a truncated TLS record.
175*d1e05529SJohn Baldwin.It Bq Er EBADMSG
176*d1e05529SJohn BaldwinThe TLS record failed to match the included authentication tag.
177*d1e05529SJohn Baldwin.El
178*d1e05529SJohn Baldwin.Pp
179*d1e05529SJohn BaldwinThe current TLS receive mode of a socket can be queried via the
180*d1e05529SJohn Baldwin.Dv TCP_RXTLS_MODE
181*d1e05529SJohn Baldwinsocket option.
182*d1e05529SJohn BaldwinAt present,
183*d1e05529SJohn Baldwinthe mode cannot be changed.
184*d1e05529SJohn Baldwin.Ss Sysctl Nodes
185*d1e05529SJohn Baldwin.Nm
186*d1e05529SJohn Baldwinuses several sysctl nodes under the
187*d1e05529SJohn Baldwin.Va kern.ipc.tls
188*d1e05529SJohn Baldwinnode.
189*d1e05529SJohn BaldwinA few of them are described below:
190*d1e05529SJohn Baldwin.Bl -tag -width ".Va kern.ipc.tls.cbc_enable"
191*d1e05529SJohn Baldwin.It Va kern.ipc.tls.enable
192*d1e05529SJohn BaldwinDetermines if new kernel TLS sessions can be created.
193*d1e05529SJohn Baldwin.It Va kern.ipc.tls.cbc_enable
194*d1e05529SJohn BaldwinDetermines if new kernel TLS sessions with a cipher suite using AES-CBC
195*d1e05529SJohn Baldwincan be created.
196*d1e05529SJohn Baldwin.It Va kern.ipc.tls.sw
197*d1e05529SJohn BaldwinA tree of nodes containing statistics for TLS sessions using
198*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_SW .
199*d1e05529SJohn Baldwin.It Va kern.ipc.tls.ifnet
200*d1e05529SJohn BaldwinA tree of nodes containing statistics for TLS sessions using
201*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_IFNET .
202*d1e05529SJohn Baldwin.It Va kern.ipc.tls.toe
203*d1e05529SJohn BaldwinA tree of nodes containing statistics for TLS sessions using
204*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_TOE .
205*d1e05529SJohn Baldwin.It Va kern.ipc.tls.stats
206*d1e05529SJohn BaldwinA tree of nodes containing various kernel TLS statistics.
207*d1e05529SJohn Baldwin.El
208*d1e05529SJohn Baldwin.Ss Backends
209*d1e05529SJohn BaldwinThe base system includes a software backend for the
210*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_SW
211*d1e05529SJohn Baldwinmode which uses
212*d1e05529SJohn Baldwin.Xr crypto 9
213*d1e05529SJohn Baldwinto encrypt and decrypt TLS records.
214*d1e05529SJohn BaldwinThis backend can be enabled by loading the
215*d1e05529SJohn Baldwin.Pa ktls_ocf.ko
216*d1e05529SJohn Baldwinkernel module.
217*d1e05529SJohn Baldwin.Pp
218*d1e05529SJohn BaldwinThe
219*d1e05529SJohn Baldwin.Xr cxgbe 4
220*d1e05529SJohn Baldwinand
221*d1e05529SJohn Baldwin.Xr mlx5en 4
222*d1e05529SJohn Baldwindrivers include support for the
223*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_IFNET
224*d1e05529SJohn Baldwinmode.
225*d1e05529SJohn Baldwin.Pp
226*d1e05529SJohn BaldwinThe
227*d1e05529SJohn Baldwin.Xr cxgbe 4
228*d1e05529SJohn Baldwindriver includes support for the
229*d1e05529SJohn Baldwin.Dv TCP_TLS_MODE_TOE
230*d1e05529SJohn Baldwinmode.
231*d1e05529SJohn Baldwin.Ss Supported Libraries
232*d1e05529SJohn BaldwinOpenSSL 3.0 and later include support for
233*d1e05529SJohn Baldwin.Nm .
234*d1e05529SJohn BaldwinThe
235*d1e05529SJohn Baldwin.Fa devel/openssl
236*d1e05529SJohn Baldwinport may also be built with support for
237*d1e05529SJohn Baldwin.Nm
238*d1e05529SJohn Baldwinby enabling the
239*d1e05529SJohn Baldwin.Dv KTLS
240*d1e05529SJohn Baldwinoption .
241*d1e05529SJohn Baldwin.Pp
242*d1e05529SJohn BaldwinApplications using a supported library should generally work with
243*d1e05529SJohn Baldwin.Nm
244*d1e05529SJohn Baldwinwithout any changes provided they use standard interfaces such as
245*d1e05529SJohn Baldwin.Xr SSL_read 3
246*d1e05529SJohn Baldwinand
247*d1e05529SJohn Baldwin.Xr SSL_write 3 .
248*d1e05529SJohn BaldwinAdditional performance may be gained by the use of
249*d1e05529SJohn Baldwin.Xr SSL_sendfile 3 .
250*d1e05529SJohn Baldwin.Sh IMPLEMENTATION NOTES
251*d1e05529SJohn Baldwin.Nm
252*d1e05529SJohn Baldwinassumes the presence of a direct map of physical memory when performing
253*d1e05529SJohn Baldwinsoftware encryption and decryption.
254*d1e05529SJohn BaldwinAs a result, it is only supported on architectures with a direct map.
255*d1e05529SJohn Baldwin.Sh SEE ALSO
256*d1e05529SJohn Baldwin.Xr cxgbe 4 ,
257*d1e05529SJohn Baldwin.Xr mlx5en 4 ,
258*d1e05529SJohn Baldwin.Xr tcp 4 ,
259*d1e05529SJohn Baldwin.Xr ifconfig 8 ,
260*d1e05529SJohn Baldwin.Xr sysctl 8 ,
261*d1e05529SJohn Baldwin.Xr crypto 9
262*d1e05529SJohn Baldwin.Sh HISTORY
263*d1e05529SJohn BaldwinKernel TLS first appeared in
264*d1e05529SJohn Baldwin.Fx 13.0 .
265