psp.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. .. SPDX-License-Identifier: GPL-2.0-only
  2. =====================
  3. PSP Security Protocol
  4. =====================
  5. Protocol
  6. ========
  7. PSP Security Protocol (PSP) was defined at Google and published in:
  8. https://raw.githubusercontent.com/google/psp/main/doc/PSP_Arch_Spec.pdf
  9. This section briefly covers protocol aspects crucial for understanding
  10. the kernel API. Refer to the protocol specification for further details.
  11. Note that the kernel implementation and documentation uses the term
  12. "device key" in place of "master key", it is both less confusing
  13. to an average developer and is less likely to run afoul any naming
  14. guidelines.
  15. Derived Rx keys
  16. ---------------
  17. PSP borrows some terms and mechanisms from IPsec. PSP was designed
  18. with HW offloads in mind. The key feature of PSP is that Rx keys for every
  19. connection do not have to be stored by the receiver but can be derived
  20. from device key and information present in packet headers.
  21. This makes it possible to implement receivers which require a constant
  22. amount of memory regardless of the number of connections (``O(1)`` scaling).
  23. Tx keys have to be stored like with any other protocol, but Tx is much
  24. less latency sensitive than Rx, and delays in fetching keys from slow
  25. memory is less likely to cause packet drops. Preferably, the Tx keys
  26. should be provided with the packet (e.g. as part of the descriptors).
  27. Key rotation
  28. ------------
  29. The device key known only to the receiver is fundamental to the design.
  30. Per specification this state cannot be directly accessible (it must be
  31. impossible to read it out of the hardware of the receiver NIC).
  32. Moreover, it has to be "rotated" periodically (usually daily). Rotation
  33. means that new device key gets generated (by a random number generator
  34. of the device), and used for all new connections. To avoid disrupting
  35. old connections the old device key remains in the NIC. A phase bit
  36. carried in the packet headers indicates which generation of device key
  37. the packet has been encrypted with.
  38. User facing API
  39. ===============
  40. PSP is designed primarily for hardware offloads. There is currently
  41. no software fallback for systems which do not have PSP capable NICs.
  42. There is also no standard (or otherwise defined) way of establishing
  43. a PSP-secured connection or exchanging the symmetric keys.
  44. The expectation is that higher layer protocols will take care of
  45. protocol and key negotiation. For example one may use TLS key exchange,
  46. announce the PSP capability, and switch to PSP if both endpoints
  47. are PSP-capable.
  48. All configuration of PSP is performed via the PSP netlink family.
  49. Device discovery
  50. ----------------
  51. The PSP netlink family defines operations to retrieve information
  52. about the PSP devices available on the system, configure them and
  53. access PSP related statistics.
  54. Securing a connection
  55. ---------------------
  56. PSP encryption is currently only supported for TCP connections.
  57. Rx and Tx keys are allocated separately. First the ``rx-assoc``
  58. Netlink command needs to be issued, specifying a target TCP socket.
  59. Kernel will allocate a new PSP Rx key from the NIC and associate it
  60. with given socket. At this stage socket will accept both PSP-secured
  61. and plain text TCP packets.
  62. Tx keys are installed using the ``tx-assoc`` Netlink command.
  63. Once the Tx keys are installed, all data read from the socket will
  64. be PSP-secured. In other words act of installing Tx keys has a secondary
  65. effect on the Rx direction.
  66. There is an intermediate period after ``tx-assoc`` successfully
  67. returns and before the TCP socket encounters it's first PSP
  68. authenticated packet, where the TCP stack will allow certain nondata
  69. packets, i.e. ACKs, FINs, and RSTs, to enter TCP receive processing
  70. even if not PSP authenticated. During the ``tx-assoc`` call, the TCP
  71. socket's ``rcv_nxt`` field is recorded. At this point, ACKs and RSTs
  72. will be accepted with any sequence number, while FINs will only be
  73. accepted at the latched value of ``rcv_nxt``. Once the TCP stack
  74. encounters the first TCP packet containing PSP authenticated data, the
  75. other end of the connection must have executed the ``tx-assoc``
  76. command, so any TCP packet, including those without data, will be
  77. dropped before receive processing if it is not successfully
  78. authenticated. This is summarized in the table below. The
  79. aforementioned state of rejecting all non-PSP packets is labeled "PSP
  80. Full".
  81. +----------------+------------+------------+-------------+-------------+
  82. | Event | Normal TCP | Rx PSP | Tx PSP | PSP Full |
  83. +================+============+============+=============+=============+
  84. | Rx plain | accept | accept | drop | drop |
  85. | (data) | | | | |
  86. +----------------+------------+------------+-------------+-------------+
  87. | Rx plain | accept | accept | accept | drop |
  88. | (ACK|FIN|RST) | | | | |
  89. +----------------+------------+------------+-------------+-------------+
  90. | Rx PSP (good) | drop | accept | accept | accept |
  91. +----------------+------------+------------+-------------+-------------+
  92. | Rx PSP (bad | drop | drop | drop | drop |
  93. | crypt, !=SPI) | | | | |
  94. +----------------+------------+------------+-------------+-------------+
  95. | Tx | plain text | plain text | encrypted | encrypted |
  96. | | | | (excl. rtx) | (excl. rtx) |
  97. +----------------+------------+------------+-------------+-------------+
  98. To ensure that any data read from the socket after the ``tx-assoc``
  99. call returns success has been authenticated, the kernel will scan the
  100. receive and ofo queues of the socket at ``tx-assoc`` time. If any
  101. enqueued packet was received in clear text, the Tx association will
  102. fail, and the application should retry installing the Tx key after
  103. draining the socket (this should not be necessary if both endpoints
  104. are well behaved).
  105. Because TCP sequence numbers are not integrity protected prior to
  106. upgrading to PSP, it is possible that a MITM could offset sequence
  107. numbers in a way that deletes a prefix of the PSP protected part of
  108. the TCP stream. If userspace cares to mitigate this type of attack, a
  109. special "start of PSP" message should be exchanged after ``tx-assoc``.
  110. Rotation notifications
  111. ----------------------
  112. The rotations of device key happen asynchronously and are usually
  113. performed by management daemons, not under application control.
  114. The PSP netlink family will generate a notification whenever keys
  115. are rotated. The applications are expected to re-establish connections
  116. before keys are rotated again.
  117. Kernel implementation
  118. =====================
  119. Driver notes
  120. ------------
  121. Drivers are expected to start with no PSP enabled (``psp-versions-ena``
  122. in ``dev-get`` set to ``0``) whenever possible. The user space should
  123. not depend on this behavior, as future extension may necessitate creation
  124. of devices with PSP already enabled, nonetheless drivers should not enable
  125. PSP by default. Enabling PSP should be the responsibility of the system
  126. component which also takes care of key rotation.
  127. Note that ``psp-versions-ena`` is expected to be used only for enabling
  128. receive processing. The device is not expected to reject transmit requests
  129. after ``psp-versions-ena`` has been disabled. User may also disable
  130. ``psp-versions-ena`` while there are active associations, which will
  131. break all PSP Rx processing.
  132. Drivers are expected to ensure that a device key is usable and secure
  133. upon init, without explicit key rotation by the user space. It must be
  134. possible to allocate working keys, and that no duplicate keys must be
  135. generated. If the device allows the host to request the key for an
  136. arbitrary SPI - driver should discard both device keys (rotate the
  137. device key twice), to avoid potentially using a SPI+key which previous
  138. OS instance already had access to.
  139. Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload
  140. was requested for given skb. On Rx drivers should allocate and populate
  141. the ``SKB_EXT_PSP`` skb extension, and set the skb->decrypted bit to 1.
  142. Kernel implementation notes
  143. ---------------------------
  144. PSP implementation follows the TLS offload more closely than the IPsec
  145. offload, with per-socket state, and the use of skb->decrypted to prevent
  146. clear text leaks.
  147. PSP device is separate from netdev, to make it possible to "delegate"
  148. PSP offload capabilities to software devices (e.g. ``veth``).