]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
ktls: Ensure FIFO encryption order for TLS 1.0.
authorJohn Baldwin <jhb@FreeBSD.org>
Wed, 13 Oct 2021 19:30:15 +0000 (12:30 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Wed, 13 Oct 2021 19:30:15 +0000 (12:30 -0700)
commit9f03d2c00167c8047416e0048e3b7f89d73baf8e
treee571e21a794a4ccc9cffb24a46052454b9eedba4
parenta63752cce6462d08bbec08cad931d70dec2f5b4c
ktls: Ensure FIFO encryption order for TLS 1.0.

TLS 1.0 records are encrypted as one continuous CBC chain where the
last block of the previous record is used as the IV for the next
record.  As a result, TLS 1.0 records cannot be encrypted out of order
but must be encrypted as a FIFO.

If the later pages of a sendfile(2) request complete before the first
pages, then TLS records can be encrypted out of order.  For TLS 1.1
and later this is fine, but this can break for TLS 1.0.

To cope, add a queue in each TLS session to hold TLS records that
contain valid unencrypted data but are waiting for an earlier TLS
record to be encrypted first.

- In ktls_enqueue(), check if a TLS record being queued is the next
  record expected for a TLS 1.0 session.  If not, it is placed in
  sorted order in the pending_records queue in the TLS session.

  If it is the next expected record, queue it for SW encryption like
  normal.  In addition, check if this new record (really a potential
  batch of records) was holding up any previously queued records in
  the pending_records queue.  Any of those records that are now in
  order are also placed on the queue for SW encryption.

- In ktls_destroy(), free any TLS records on the pending_records
  queue.  These mbufs are marked M_NOTREADY so were not freed when the
  socket buffer was purged in sbdestroy().  Instead, they must be
  freed explicitly.

Reviewed by: gallatin, markj
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D32381
sys/kern/uipc_ktls.c
sys/sys/ktls.h