1*a9266275SJakub Kicinski.. SPDX-License-Identifier: GPL-2.0-only 2*a9266275SJakub Kicinski 3*a9266275SJakub Kicinski===================== 4*a9266275SJakub KicinskiPSP Security Protocol 5*a9266275SJakub Kicinski===================== 6*a9266275SJakub Kicinski 7*a9266275SJakub KicinskiProtocol 8*a9266275SJakub Kicinski======== 9*a9266275SJakub Kicinski 10*a9266275SJakub KicinskiPSP Security Protocol (PSP) was defined at Google and published in: 11*a9266275SJakub Kicinski 12*a9266275SJakub Kicinskihttps://raw.githubusercontent.com/google/psp/main/doc/PSP_Arch_Spec.pdf 13*a9266275SJakub Kicinski 14*a9266275SJakub KicinskiThis section briefly covers protocol aspects crucial for understanding 15*a9266275SJakub Kicinskithe kernel API. Refer to the protocol specification for further details. 16*a9266275SJakub Kicinski 17*a9266275SJakub KicinskiNote that the kernel implementation and documentation uses the term 18*a9266275SJakub Kicinski"device key" in place of "master key", it is both less confusing 19*a9266275SJakub Kicinskito an average developer and is less likely to run afoul any naming 20*a9266275SJakub Kicinskiguidelines. 21*a9266275SJakub Kicinski 22*a9266275SJakub KicinskiDerived Rx keys 23*a9266275SJakub Kicinski--------------- 24*a9266275SJakub Kicinski 25*a9266275SJakub KicinskiPSP borrows some terms and mechanisms from IPsec. PSP was designed 26*a9266275SJakub Kicinskiwith HW offloads in mind. The key feature of PSP is that Rx keys for every 27*a9266275SJakub Kicinskiconnection do not have to be stored by the receiver but can be derived 28*a9266275SJakub Kicinskifrom device key and information present in packet headers. 29*a9266275SJakub KicinskiThis makes it possible to implement receivers which require a constant 30*a9266275SJakub Kicinskiamount of memory regardless of the number of connections (``O(1)`` scaling). 31*a9266275SJakub Kicinski 32*a9266275SJakub KicinskiTx keys have to be stored like with any other protocol, but Tx is much 33*a9266275SJakub Kicinskiless latency sensitive than Rx, and delays in fetching keys from slow 34*a9266275SJakub Kicinskimemory is less likely to cause packet drops. Preferably, the Tx keys 35*a9266275SJakub Kicinskishould be provided with the packet (e.g. as part of the descriptors). 36*a9266275SJakub Kicinski 37*a9266275SJakub KicinskiKey rotation 38*a9266275SJakub Kicinski------------ 39*a9266275SJakub Kicinski 40*a9266275SJakub KicinskiThe device key known only to the receiver is fundamental to the design. 41*a9266275SJakub KicinskiPer specification this state cannot be directly accessible (it must be 42*a9266275SJakub Kicinskiimpossible to read it out of the hardware of the receiver NIC). 43*a9266275SJakub KicinskiMoreover, it has to be "rotated" periodically (usually daily). Rotation 44*a9266275SJakub Kicinskimeans that new device key gets generated (by a random number generator 45*a9266275SJakub Kicinskiof the device), and used for all new connections. To avoid disrupting 46*a9266275SJakub Kicinskiold connections the old device key remains in the NIC. A phase bit 47*a9266275SJakub Kicinskicarried in the packet headers indicates which generation of device key 48*a9266275SJakub Kicinskithe packet has been encrypted with. 49*a9266275SJakub Kicinski 50*a9266275SJakub KicinskiUser facing API 51*a9266275SJakub Kicinski=============== 52*a9266275SJakub Kicinski 53*a9266275SJakub KicinskiPSP is designed primarily for hardware offloads. There is currently 54*a9266275SJakub Kicinskino software fallback for systems which do not have PSP capable NICs. 55*a9266275SJakub KicinskiThere is also no standard (or otherwise defined) way of establishing 56*a9266275SJakub Kicinskia PSP-secured connection or exchanging the symmetric keys. 57*a9266275SJakub Kicinski 58*a9266275SJakub KicinskiThe expectation is that higher layer protocols will take care of 59*a9266275SJakub Kicinskiprotocol and key negotiation. For example one may use TLS key exchange, 60*a9266275SJakub Kicinskiannounce the PSP capability, and switch to PSP if both endpoints 61*a9266275SJakub Kicinskiare PSP-capable. 62*a9266275SJakub Kicinski 63*a9266275SJakub KicinskiAll configuration of PSP is performed via the PSP netlink family. 64*a9266275SJakub Kicinski 65*a9266275SJakub KicinskiDevice discovery 66*a9266275SJakub Kicinski---------------- 67*a9266275SJakub Kicinski 68*a9266275SJakub KicinskiThe PSP netlink family defines operations to retrieve information 69*a9266275SJakub Kicinskiabout the PSP devices available on the system, configure them and 70*a9266275SJakub Kicinskiaccess PSP related statistics. 71*a9266275SJakub Kicinski 72*a9266275SJakub KicinskiSecuring a connection 73*a9266275SJakub Kicinski--------------------- 74*a9266275SJakub Kicinski 75*a9266275SJakub KicinskiPSP encryption is currently only supported for TCP connections. 76*a9266275SJakub KicinskiRx and Tx keys are allocated separately. First the ``rx-assoc`` 77*a9266275SJakub KicinskiNetlink command needs to be issued, specifying a target TCP socket. 78*a9266275SJakub KicinskiKernel will allocate a new PSP Rx key from the NIC and associate it 79*a9266275SJakub Kicinskiwith given socket. At this stage socket will accept both PSP-secured 80*a9266275SJakub Kicinskiand plain text TCP packets. 81*a9266275SJakub Kicinski 82*a9266275SJakub KicinskiTx keys are installed using the ``tx-assoc`` Netlink command. 83*a9266275SJakub KicinskiOnce the Tx keys are installed, all data read from the socket will 84*a9266275SJakub Kicinskibe PSP-secured. In other words act of installing Tx keys has a secondary 85*a9266275SJakub Kicinskieffect on the Rx direction. 86*a9266275SJakub Kicinski 87*a9266275SJakub KicinskiThere is an intermediate period after ``tx-assoc`` successfully 88*a9266275SJakub Kicinskireturns and before the TCP socket encounters it's first PSP 89*a9266275SJakub Kicinskiauthenticated packet, where the TCP stack will allow certain nondata 90*a9266275SJakub Kicinskipackets, i.e. ACKs, FINs, and RSTs, to enter TCP receive processing 91*a9266275SJakub Kicinskieven if not PSP authenticated. During the ``tx-assoc`` call, the TCP 92*a9266275SJakub Kicinskisocket's ``rcv_nxt`` field is recorded. At this point, ACKs and RSTs 93*a9266275SJakub Kicinskiwill be accepted with any sequence number, while FINs will only be 94*a9266275SJakub Kicinskiaccepted at the latched value of ``rcv_nxt``. Once the TCP stack 95*a9266275SJakub Kicinskiencounters the first TCP packet containing PSP authenticated data, the 96*a9266275SJakub Kicinskiother end of the connection must have executed the ``tx-assoc`` 97*a9266275SJakub Kicinskicommand, so any TCP packet, including those without data, will be 98*a9266275SJakub Kicinskidropped before receive processing if it is not successfully 99*a9266275SJakub Kicinskiauthenticated. This is summarized in the table below. The 100*a9266275SJakub Kicinskiaforementioned state of rejecting all non-PSP packets is labeled "PSP 101*a9266275SJakub KicinskiFull". 102*a9266275SJakub Kicinski 103*a9266275SJakub Kicinski+----------------+------------+------------+-------------+-------------+ 104*a9266275SJakub Kicinski| Event | Normal TCP | Rx PSP | Tx PSP | PSP Full | 105*a9266275SJakub Kicinski+================+============+============+=============+=============+ 106*a9266275SJakub Kicinski| Rx plain | accept | accept | drop | drop | 107*a9266275SJakub Kicinski| (data) | | | | | 108*a9266275SJakub Kicinski+----------------+------------+------------+-------------+-------------+ 109*a9266275SJakub Kicinski| Rx plain | accept | accept | accept | drop | 110*a9266275SJakub Kicinski| (ACK|FIN|RST) | | | | | 111*a9266275SJakub Kicinski+----------------+------------+------------+-------------+-------------+ 112*a9266275SJakub Kicinski| Rx PSP (good) | drop | accept | accept | accept | 113*a9266275SJakub Kicinski+----------------+------------+------------+-------------+-------------+ 114*a9266275SJakub Kicinski| Rx PSP (bad | drop | drop | drop | drop | 115*a9266275SJakub Kicinski| crypt, !=SPI) | | | | | 116*a9266275SJakub Kicinski+----------------+------------+------------+-------------+-------------+ 117*a9266275SJakub Kicinski| Tx | plain text | plain text | encrypted | encrypted | 118*a9266275SJakub Kicinski| | | | (excl. rtx) | (excl. rtx) | 119*a9266275SJakub Kicinski+----------------+------------+------------+-------------+-------------+ 120*a9266275SJakub Kicinski 121*a9266275SJakub KicinskiTo ensure that any data read from the socket after the ``tx-assoc`` 122*a9266275SJakub Kicinskicall returns success has been authenticated, the kernel will scan the 123*a9266275SJakub Kicinskireceive and ofo queues of the socket at ``tx-assoc`` time. If any 124*a9266275SJakub Kicinskienqueued packet was received in clear text, the Tx association will 125*a9266275SJakub Kicinskifail, and the application should retry installing the Tx key after 126*a9266275SJakub Kicinskidraining the socket (this should not be necessary if both endpoints 127*a9266275SJakub Kicinskiare well behaved). 128*a9266275SJakub Kicinski 129*a9266275SJakub KicinskiBecause TCP sequence numbers are not integrity protected prior to 130*a9266275SJakub Kicinskiupgrading to PSP, it is possible that a MITM could offset sequence 131*a9266275SJakub Kicinskinumbers in a way that deletes a prefix of the PSP protected part of 132*a9266275SJakub Kicinskithe TCP stream. If userspace cares to mitigate this type of attack, a 133*a9266275SJakub Kicinskispecial "start of PSP" message should be exchanged after ``tx-assoc``. 134*a9266275SJakub Kicinski 135*a9266275SJakub KicinskiRotation notifications 136*a9266275SJakub Kicinski---------------------- 137*a9266275SJakub Kicinski 138*a9266275SJakub KicinskiThe rotations of device key happen asynchronously and are usually 139*a9266275SJakub Kicinskiperformed by management daemons, not under application control. 140*a9266275SJakub KicinskiThe PSP netlink family will generate a notification whenever keys 141*a9266275SJakub Kicinskiare rotated. The applications are expected to re-establish connections 142*a9266275SJakub Kicinskibefore keys are rotated again. 143*a9266275SJakub Kicinski 144*a9266275SJakub KicinskiKernel implementation 145*a9266275SJakub Kicinski===================== 146*a9266275SJakub Kicinski 147*a9266275SJakub KicinskiDriver notes 148*a9266275SJakub Kicinski------------ 149*a9266275SJakub Kicinski 150*a9266275SJakub KicinskiDrivers are expected to start with no PSP enabled (``psp-versions-ena`` 151*a9266275SJakub Kicinskiin ``dev-get`` set to ``0``) whenever possible. The user space should 152*a9266275SJakub Kicinskinot depend on this behavior, as future extension may necessitate creation 153*a9266275SJakub Kicinskiof devices with PSP already enabled, nonetheless drivers should not enable 154*a9266275SJakub KicinskiPSP by default. Enabling PSP should be the responsibility of the system 155*a9266275SJakub Kicinskicomponent which also takes care of key rotation. 156*a9266275SJakub Kicinski 157*a9266275SJakub KicinskiNote that ``psp-versions-ena`` is expected to be used only for enabling 158*a9266275SJakub Kicinskireceive processing. The device is not expected to reject transmit requests 159*a9266275SJakub Kicinskiafter ``psp-versions-ena`` has been disabled. User may also disable 160*a9266275SJakub Kicinski``psp-versions-ena`` while there are active associations, which will 161*a9266275SJakub Kicinskibreak all PSP Rx processing. 162*a9266275SJakub Kicinski 163*a9266275SJakub KicinskiDrivers are expected to ensure that a device key is usable and secure 164*a9266275SJakub Kicinskiupon init, without explicit key rotation by the user space. It must be 165*a9266275SJakub Kicinskipossible to allocate working keys, and that no duplicate keys must be 166*a9266275SJakub Kicinskigenerated. If the device allows the host to request the key for an 167*a9266275SJakub Kicinskiarbitrary SPI - driver should discard both device keys (rotate the 168*a9266275SJakub Kicinskidevice key twice), to avoid potentially using a SPI+key which previous 169*a9266275SJakub KicinskiOS instance already had access to. 170*a9266275SJakub Kicinski 171*a9266275SJakub KicinskiDrivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload 172*a9266275SJakub Kicinskiwas requested for given skb. On Rx drivers should allocate and populate 173*a9266275SJakub Kicinskithe ``SKB_EXT_PSP`` skb extension, and set the skb->decrypted bit to 1. 174*a9266275SJakub Kicinski 175*a9266275SJakub KicinskiKernel implementation notes 176*a9266275SJakub Kicinski--------------------------- 177*a9266275SJakub Kicinski 178*a9266275SJakub KicinskiPSP implementation follows the TLS offload more closely than the IPsec 179*a9266275SJakub Kicinskioffload, with per-socket state, and the use of skb->decrypted to prevent 180*a9266275SJakub Kicinskiclear text leaks. 181*a9266275SJakub Kicinski 182*a9266275SJakub KicinskiPSP device is separate from netdev, to make it possible to "delegate" 183*a9266275SJakub KicinskiPSP offload capabilities to software devices (e.g. ``veth``). 184