Skip to content

psp: support rekeying psp protected tcp connections

Daniel Zahka linux-doc linux-kselftest lkml netdev 5 versions – In review

Get series with b4
b4 am [email protected] change-id 20260202-psp-3c8e2f65c5c4

Versions newest first

  1. v5 Latest6 patches 3 repliesIn review
  2. v45 patches 1 replySuperseded
  3. v35 patches 6 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v27 patches5 repliesSuperseded
v19 patches11 repliesSuperseded

Changes in v5 from the cover letter

- psp: document lock ordering with the netdev instance lock
- new patch
- psp: defer tx key deletions for SADB drivers
- take a psd reference across mutex_unlock() in psp_assoc_free() after handing the assoc to the deferred queue
- move the psp_dev_unregister() locking rule to a separate patch
- selftests: drv-net: psp: add rekey tests
- drop the fail-fast change to _recv_careful(); it is a pre-existing helper
- Link to v4: https://lore.kernel.org/r/[email protected]

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6psp: support rx rekey operationDocumentation/netlink/specs/psp.yaml Documentation/networking/psp.rst include/net/psp/functions.h +3 more+96 -131 reply
2/6psp: support tx rekey operationDocumentation/netlink/specs/psp.yaml Documentation/networking/psp.rst net/psp/psp_sock.c+58 -80 replies
3/6psp: document lock ordering with the netdev instance locknet/psp/psp_main.c+9 -00 replies
4/6psp: defer tx key deletions for SADB driversDocumentation/networking/psp.rst include/net/psp/types.h net/psp/Kconfig +5 more+334 -91 reply
5/6selftests: drv-net: psp: factor out psp connection setuptools/testing/selftests/drivers/net/psp.py tools/testing/selftests/drivers/net/psp_responder.c+59 -280 replies
6/6selftests: drv-net: psp: add rekey teststools/testing/selftests/drivers/net/psp.py tools/testing/selftests/drivers/net/psp_responder.c+349 -21 reply

Reviews trailers per patch

5 of 6 patches have a Reviewed-by or Acked-by.

PatchWillem de Bruijn
1/6R-b
2/6R-b
3/6
4/6R-b
5/6R-b
6/6R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH net-next v5 0/6] psp: support rekeying psp protected tcp connections

A note on v3 and later:
To keep this series short, I have split off some of the content that appeared in v2, and also have planned future work that will make this feature more robust, but not necessary to start. Here is the current queue of follow up series:
1. core tracked tx-key-count stat and SADB drain test case (from v2). I see this as able to stand alone as a series, and I also would like to report key deletion errors, but will have to touch mlx5 for that.
2. core to end grace period if BQL is stalled. I think this deserves its own series for human discussion.
3. Rate limiting rekey uAPIs. This has been suggusted by the bot, but whether or not it is needed depends on a bit on the deployment model.

Original cover letter:

The PSP architecture spec states the need for rekeying connections in the event of a device key rotation. After a device key rotation has occurred, a new rx derived key needs to be generated and sent out to the other end of the connection sometime before the next device key rotation occurs.

Because PSP connections involve two different keys at each endpoint, one for decrypting ingress traffic, and one for encrypting egress traffic, there are two types of rekeying events that need to be supported. From the perspective of one endpoint of the connection:

1. rx rekey: we need to allocate a new spi + decryption key pair to provide to our peer.

2. tx rekey: our peer has provided us with a new spi + encryption key pair which we should use for encrypting traffic immediately.

In the case of rx rekeying, there is a period where it makes sense to accept packets authenticated from either the previous or current spi. To deal with that, we allow a psp_assoc to remember the last spi that was valid on a socket due to a rekey. If authentication state does not match the most recent assoc, the stored state from the previous assoc will be tried.

In the case of tx rekeying, as soon as we install the new tx key, we have no use for the previous one, and it can be disposed of immediately. The only catch is in the case where hw uses a key handle in tx descriptor state, as opposed to inlining the key directly. In this case, psp core needs to be sure that any of these unaccounted for references to key state are gone by the time it tries to sync a deleted key to hw.

To deal with this race condition, we introduce a different path to key deletion for psp_assocs removed from the socket during a tx rekey. psp core will use bql byte counters filled out by the driver to determine a conservative grace period where key handles can be disposed of.

Lastly, some test cases for rekeying are included that go through key rotations and rekeying.

There are some packetdrill tests that are queued for upstreaming [1].

Future work can include a time based rate limit on the rx-assoc/tx-assoc uAPIs to prevent an untrusted user from creating lots of wasted PSP assocs and consuming SPIs, SADB space, etc. For now, users should use network namespaces, or otherwise not present PSP devices to users that could abuse this.

[1]: https://github.com/danieldzahka/packetdrill/commits/psp-rekey/

---
Changes in v5:
- psp: document lock ordering with the netdev instance lock
- new patch
- psp: defer tx key deletions for SADB drivers
- take a psd reference across mutex_unlock() in psp_assoc_free() after handing the assoc to the deferred queue
- move the psp_dev_unregister() locking rule to a separate patch
- selftests: drv-net: psp: add rekey tests
- drop the fail-fast change to _recv_careful(); it is a pre-existing helper
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- selftests: drv-net: psp: factor out psp connection setup
- drop closing the data socket on conn_setup_psp() failure; preexisting and not needed by the series
- selftests: drv-net: psp: add rekey tests
- reuse _recv_careful() and _req_echo() now in net-next instead of redefining them
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- psp: support rx rekey operation
- move the replaced assoc to psd->stale_assocs, so a rotation racing with its free doesn't count it in stale-events
- drop the requirement that the new rx spi has the opposite phase bit from the previous one
- keep prev_generation valid across a rotation when the prev SPI is from the same generation
- document rx rekey in the rx-assoc op doc in psp.yaml
- psp: support tx rekey operation
- move the replaced assoc to psd->stale_assocs, so a rotation racing with its free doesn't count the socket twice in stale-events
- document that the previous rx SPI also stops being accepted once its device key is rotated out
- drop the claim that the peer accepts both the old and new SPI after a tx rekey
- document tx rekey in the tx-assoc op doc in psp.yaml
- psp: defer tx key deletions for SADB drivers
- document that Tx descriptors must be completed or discarded before psp_dev_unregister()
- selftests: drv-net: psp: factor out psp connection setup
- take key lengths from the kernel's rx-assoc reply instead of a per-version table
- close the data socket in psp_responder if conn_setup_psp() fails
- selftests: drv-net: psp: add rekey tests
- drop test for rx rekey rejected without a device key rotation
- fail fast in _recv_careful() if the peer closes the connection
- in the basic rekey tests, run traffic across a rotation before the rekey, and rotate again after it to verify the new key is in use
- drop unneeded key rotation from rekey_rx_version_mismatch()
- carry the key length in the responder's assoc message instead of deriving it from the version
- psp: add core tracked stat for outstanding tx keys
- moved to a follow-up series
- selftests: drv-net: psp: add a tx rekey drain test for SADB drivers
- moved to a follow-up series
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- psp: support rx rekey operation
- copy old rx state by value instead of pointer to prev
- place non-datapath fields at end of struct psp_assoc
- disallow rx rekey when socket is not in full psp state, or dev/version doesn't match
- require the new rx spi to have the opposite phase bit from the previous one
- psp: support tx rekey operation
- place new assoc on pas->assocs list instead of psd->active_assocs
- disallow tx rekey when socket is not in full psp state
- document rekeying in psp.rst
- reject tx rekey on SADB devices until deferred tx key deletion lands
- psp: defer tx key deletions for SADB drivers
- replaces "psp: add driver api for deferred tx key deletion"
- use bql byte counters instead of driver callback for grace periods
- only defer tx key deletion when socket outlives psp_assoc
- document driver requirements in psp.rst
- allow tx rekey on SADB devices
- psp: add core tracked stat for outstanding tx keys
- replaces "psp: add core tracked stats for deferred key deletion"
- drop grace-periods stat
- rename tx-key-cnt to tx-key-count, only report it for SADB drivers
- warn about outstanding tx keys in psp_dev_unregister()
- selftests: drv-net: psp: factor out psp connection setup
- split psp_responder conn_setup_psp() into rx_assoc() and tx_assoc()
- drop Reviewed-by from Willem due to psp_responder changes
- selftests: drv-net: psp: add rekey tests
- add tests for rekeys rejected due to psp state and version mismatch
- add test for rx rekey rejected without a device key rotation
- add rx-assoc, tx-assoc, and key-rotate rpcs to psp_responder
- selftests: drv-net: psp: add a tx rekey drain test for SADB drivers
- new patch
- mlx5: psp: implement deferred tx key deletion
- dropped, bql based grace periods need no driver callback
- Link to v1: https://lore.kernel.org/r/[email protected]

To: Daniel Zahka <[email protected]>
To: Jakub Kicinski <[email protected]>
To: Willem de Bruijn <[email protected]>
To: David S. Miller <[email protected]>
To: Eric Dumazet <[email protected]>
To: Paolo Abeni <[email protected]>
To: Simon Horman <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Randy Dunlap <[email protected]>
To: Donald Hunter <[email protected]>
To: Andrew Lunn <[email protected]>
To: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
Daniel Zahka (6):
psp: support rx rekey operation
psp: support tx rekey operation
psp: document lock ordering with the netdev instance lock
psp: defer tx key deletions for SADB drivers
selftests: drv-net: psp: factor out psp connection setup
selftests: drv-net: psp: add rekey tests

 Documentation/netlink/specs/psp.yaml               |   8 +-
 Documentation/networking/psp.rst                   |  68 +++++-
 include/net/psp/functions.h                        |  10 +-
 include/net/psp/types.h                            |  35 ++-
 net/psp/Kconfig                                    |   1 +
 net/psp/Makefile                                   |   2 +-
 net/psp/psp.h                                      |   8 +-
 net/psp/psp_deferred_del.c                         | 231 +++++++++++++++++++
 net/psp/psp_main.c                                 |  31 ++-
 net/psp/psp_sock.c                                 | 123 ++++++++++-
 tools/testing/selftests/drivers/net/psp.py         | 246 ++++++++++++++++++++-
 .../testing/selftests/drivers/net/psp_responder.c  | 192 +++++++++++++---
 12 files changed, 900 insertions(+), 55 deletions(-)

---
base-commit: d6816d9a93b66a12bf01e10037e377f3333ad6cc
change-id: 20260202-psp-3c8e2f65c5c4

Best regards,

Signature · 1 line
Daniel Zahka <[email protected]>