psp: support rekeying psp protected tcp connections
Subsystems (6)
Daniel Zahka
maintainerv5 cover 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]>
Daniel Zahka
maintainerPATCH v5 1/6 psp: support rx rekey operation
Support updating the rx PSP state used by a socket. This is most useful to do after a device key rotation has occurred and the key being used by the peer will become stale after the next device key rotation.
Create a new psp_assoc for the socket to use that contains the same tx state, but with new rx state. Copy the previous rx state to use as a fallback while the peer is in the process of switching to the new key.
skbs matching the current rx spi and generation or the previous rx spi and generation will be accepted. It might be reasonable to stop accepting skbs on the previous state after seeing skbs with the new state and after waiting a grace period, but that is not implemented for now.
---
v3:
- 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
v2:
- 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
--- Documentation/netlink/specs/psp.yaml | 4 ++- Documentation/networking/psp.rst | 23 ++++++++++++++-- include/net/psp/functions.h | 10 ++++--- include/net/psp/types.h | 17 +++++++++++- net/psp/psp.h | 3 ++- net/psp/psp_sock.c | 52 +++++++++++++++++++++++++++++++++--- 6 files changed, 96 insertions(+), 13 deletions(-)
Documentation/netlink/specs/psp.yaml +3 -1
@@ -265,7 +265,9 @@ operations: - name: rx-assoc - doc: Allocate a new Rx key + SPI pair, associate it with a socket. + doc: | + Allocate a new Rx key + SPI pair, associate it with a socket. + If the socket already has PSP state, rekey its Rx direction. attribute-set: assoc do: request:
Documentation/networking/psp.rst +21 -2
@@ -140,14 +140,33 @@ The PSP assoc state of a socket is not reset when the connection is torn down. ``connect()`` on a socket that has PSP assoc state will return ``-EINVAL``. +Rekeying +-------- + +A connection which has completed the exchange described above and is +in the "PSP Full" state can be rekeyed in place without being torn +down, using the same netlink calls as in connection setup. + +``rx-assoc`` allocates a new Rx key and SPI, which should be passed +to the peer exactly as during the initial exchange. The SPI which was +in use before the rekey remains acceptable on the socket until the +next Rx rekey, or until the device key it was derived from has been +rotated out, so packets the peer sent before it learned the new SPI +are still received. + +A rekey is rejected with ``-EINVAL`` if it would change the PSP device +or the PSP version of the association. It is rejected with ``-EBUSY`` +if the socket has not completed its initial exchange in both +directions. + Rotation notifications ---------------------- The rotations of device key happen asynchronously and are usually performed by management daemons, not under application control. The PSP netlink family will generate a notification whenever keys -are rotated. The applications are expected to re-establish connections -before keys are rotated again. +are rotated. Applications are expected to rekey their connections, +as described above, before device keys are rotated again. Kernel implementation =====================
include/net/psp/functions.h +6 -4
@@ -77,10 +77,12 @@ psp_is_allowed_nondata(struct sk_buff *skb, struct psp_assoc *pas)static inline bool psp_pse_matches_pas (struct psp_skb_ext *pse,struct psp_assoc *pas) { -return pse && pas->rx.spi == pse->spi && - pas->generation == pse->generation && - pas->version == pse->version && - pas->dev_id == pse->dev_id; +return pse && pas->version == pse->version && + pas->dev_id == pse->dev_id && + ((pas->rx.spi == pse->spi && + pas->generation == pse->generation) || + (pas->prev_spi && pas->prev_spi == pse->spi && + pas->prev_generation == pse->generation)); } static inline enum skb_drop_reason
include/net/psp/types.h +16 -1
@@ -3,6 +3,7 @@#ifndef __NET_PSP_H#define __NET_PSP_H +#include <linux/bits.h> #include <linux/mutex.h> #include <linux/refcount.h> #include <net/net_trackers.h>
@@ -78,7 +79,8 @@ struct psp_assoc_dev {* @active_assocs: list of registered associations * @prev_assocs: associations which use old (but still usable) * device key -* @stale_assocs: associations which use a rotated out key +* @stale_assocs: associations which use a rotated out key, or were +* superseded by a rekey * * @stats: statistics maintained by the core * @stats.rotations: See stats attr key-rotations
@@ -152,6 +154,15 @@ struct psp_key_parsed {u8 key[PSP_MAX_KEY ]; }; +/** +* enum psp_assoc_flags - flags of struct psp_assoc +* @PSP_ASSOC_SKIP_TX_KEY_DEL: Do not delete Tx key from psp_dev. It was +* copied to a newer psp_assoc during an Rx rekey. +*/ +enum psp_assoc_flags { +PSP_ASSOC_SKIP_TX_KEY_DEL =BIT (0 ), +}; +struct psp_assoc {struct psp_dev *psd;
@@ -159,6 +170,10 @@ struct psp_assoc {u8 generation;u8 version;u8 peer_tx; +u8 prev_generation; +u8 flags;/* Slow path, protected by psd->lock */ + +__be32 prev_spi;u32 upgrade_seq;
net/psp/psp.h +2 -1
@@ -63,7 +63,8 @@ static inline bool psp_dev_has_sadb(struct psp_dev *psd)static inline bool psp_assoc_needs_tx_key_del (struct psp_assoc *pas) {lockdep_assert_held (&pas->psd->lock); -return psp_dev_has_sadb (pas->psd) && pas->tx.spi; +return psp_dev_has_sadb (pas->psd) && pas->tx.spi && + !(pas->flags &PSP_ASSOC_SKIP_TX_KEY_DEL ); }#endif /* __PSP_PSP_H */
net/psp/psp_sock.c +48 -4
82 lines not on this page · raw message
Signature · 1 line
2.52.1
[email protected]
AI reviewRe: [PATCH net-next v5 1/6] psp: support rx rekey operation
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The uAPI doc for the rx-assoc op in Documentation/netlink/specs/psp.yaml now reads "If the socket already…
- [Low] psp_assocs_key_rotated() (net/psp/psp_sock.c) now does a plain read-modify-write pas->prev_generation |= ~PSP_GEN_VALID_MASK on…
--
psp: support rx rekey operation
This commit lets rx-assoc run on a socket that already has full PSP state. It creates a new psp_assoc that keeps the existing Tx state and gets new Rx state. The previous Rx SPI and generation are kept as a fallback, so packets sent by the peer before it switches keys are still accepted.
Documentation/netlink/specs/psp.yaml operations: · line 270
Quoted 12 lines
Documentation/netlink/specs/psp.yaml +3
-1@@ -265,7 +265,9 @@ operations: - name: rx-assoc - doc: Allocate a new Rx key + SPI pair, associate it with a socket. + doc: | + Allocate a new Rx key + SPI pair, associate it with a socket. + If the socket already has PSP state, rekey its Rx direction.
[Severity: Low]
Does this doc match the behaviour for every socket that has PSP state? psp_sock_rx_rekey() in net/psp/psp_sock.c rejects the rekey unless both directions are set up:
if (!prev->tx.spi || !prev->peer_tx) {
NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established");
return -EBUSY;
}So a second rx-assoc on a socket that only has Rx state still fails with -EBUSY.
psp.rst describes this precondition, but the YAML spec, which ynl and the generated docs use, does not. Should the op doc say something like "If the socket already has fully established PSP state, rekey its Rx direction."?
Quoted 3 lines
Documentation/netlink/specs/psp.yaml +0
-0attribute-set: assoc do: request:
[ ... ]
Quoted 4 lines
net/psp/psp_sock.c +0
-0
[ ... ]
Quoted 8 lines
net/psp/psp_sock.c +2
-0@@ -302,8 +333,21 @@ void psp_assocs_key_rotated(struct psp_dev *psd)*/ list_for_each_entry_safe (pas, next, &psd->prev_assocs, assocs_list) { pas->generation |= ~PSP_GEN_VALID_MASK ; + pas->prev_generation |= ~PSP_GEN_VALID_MASK ; psd->stats.stales++; } +
net/psp/psp_sock.c void psp_assocs_key_rotated(struct psp_dev *psd) · line 349
Quoted 10 lines
net/psp/psp_sock.c +10
-0+/* Don't allow SPI from two generations ago to alias one from the +* current generation. Rx rekeying under the same device key generation +* is currently permitted, so skip if the previous SPI is from just one +* generation ago. +*/ +list_for_each_entry (pas, &psd->active_assocs, assocs_list) { +if ((pas->rx.spi ^ pas->prev_spi) & +cpu_to_be32 (PSP_SPI_KEY_PHASE )) + pas->prev_generation |= ~PSP_GEN_VALID_MASK ; + }
[Severity: Low]
Can these plain writes to prev_generation race with the Rx datapath?
These assocs are still published through sk->psp_assoc. The only lock held here is psd->lock, which the pre-hook of psp_nl_key_rotate_doit() takes.
The reader in psp_pse_matches_pas() runs without psd->lock and without READ_ONCE():
(pas->prev_spi && pas->prev_spi == pse->spi && pas->prev_generation == pse->generation));
It is reached from paths that hold only the socket lock or RCU:
tcp_v4_do_rcv() / tcp_v6_do_rcv()
-> psp_sk_rx_policy_check()
-> __psp_sk_rx_policy_check()
-> psp_pse_matches_pas() psp_twsk_rx_policy_check() (RCU only)
-> __psp_sk_rx_policy_check()
-> psp_pse_matches_pas()So a key-rotate running while PSP packets arrive on an rx-rekeyed socket is an unannotated data race that KCSAN would report. The field is a u8, so it can't tear, and the result is unordered against the rotation in any case.
The existing pas->generation write already works this way. This patch applies the same pattern to a new field that the datapath reads, and adds a second write site in the active_assocs loop.
Would it make sense to use WRITE_ONCE() here and READ_ONCE() in psp_pse_matches_pas()?
Quoted 3 lines
net/psp/psp_sock.c +1
-0+list_splice_init (&psd->prev_assocs, &psd->stale_assocs);list_splice_init (&psd->active_assocs, &psd->prev_assocs);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-psp-v5-0-b9ec840e0296%40gmail.com
Daniel Zahka
maintainerRe: [PATCH net-next v5 1/6] psp: support rx rekey operation
Quoted 113 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The uAPI doc for the rx-assoc op in
Documentation/netlink/specs/psp.yamlnow reads "If the socket already…
- [Low]psp_assocs_key_rotated()(net/psp/psp_sock.c) now does a plain read-modify-writepas->prev_generation |= ~PSP_GEN_VALID_MASKon…--
psp: support rx rekey operation
This commit lets rx-assoc run on a socket that already has full PSP state. It creates a new
psp_assocthat keeps the existing Tx state and gets new Rx state. The previous Rx SPI and generation are kept as a fallback, so packets sent by the peer before it switches keys are still accepted.Documentation/netlink/specs/psp.yaml operations: · line 270
Quoted 12 lines
Documentation/netlink/specs/psp.yaml +3
-1@@ -265,7 +265,9 @@ operations: - name: rx-assoc - doc: Allocate a new Rx key + SPI pair, associate it with a socket. + doc: | + Allocate a new Rx key + SPI pair, associate it with a socket. + If the socket already has PSP state, rekey its Rx direction.[Severity: Low]
Does this doc match the behaviour for every socket that has PSP state?psp_sock_rx_rekey()innet/psp/psp_sock.crejects the rekey unless both directions are set up:if (!prev->tx.spi || !prev->peer_tx) { NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established"); return -EBUSY; }So a second rx-assoc on a socket that only has Rx state still fails with
-EBUSY.
psp.rstdescribes this precondition, but the YAML spec, which ynl and the generated docs use, does not. Should the op doc say something like "If the socket already has fully established PSP state, rekey its Rx direction."?Quoted 3 lines
Documentation/netlink/specs/psp.yaml +0
-0attribute-set: assoc do: request:[ ... ]
Quoted 4 lines
net/psp/psp_sock.c +0
-0[ ... ]
Quoted 8 lines
net/psp/psp_sock.c +2
-0@@ -302,8 +333,21 @@ void psp_assocs_key_rotated(struct psp_dev *psd)*/ list_for_each_entry_safe (pas, next, &psd->prev_assocs, assocs_list) { pas->generation |= ~PSP_GEN_VALID_MASK ; + pas->prev_generation |= ~PSP_GEN_VALID_MASK ; psd->stats.stales++; } +net/psp/psp_sock.c void psp_assocs_key_rotated(struct psp_dev *psd) · line 349
Quoted 10 lines
net/psp/psp_sock.c +10
-0+/* Don't allow SPI from two generations ago to alias one from the +* current generation. Rx rekeying under the same device key generation +* is currently permitted, so skip if the previous SPI is from just one +* generation ago. +*/ +list_for_each_entry (pas, &psd->active_assocs, assocs_list) { +if ((pas->rx.spi ^ pas->prev_spi) & +cpu_to_be32 (PSP_SPI_KEY_PHASE )) + pas->prev_generation |= ~PSP_GEN_VALID_MASK ; + }[Severity: Low]
Can these plain writes toprev_generationrace with the Rx datapath?These assocs are still published through
sk->psp_assoc. The only lock held here ispsd->lock, which the pre-hook ofpsp_nl_key_rotate_doit()takes.The reader in
psp_pse_matches_pas()runs withoutpsd->lockand withoutREAD_ONCE():(pas->prev_spi && pas->prev_spi == pse->spi && pas->prev_generation == pse->generation));It is reached from paths that hold only the socket lock or RCU:
tcp_v4_do_rcv()/tcp_v6_do_rcv()-> psp_sk_rx_policy_check() -> __psp_sk_rx_policy_check() -> psp_pse_matches_pas()
psp_twsk_rx_policy_check()(RCU only)-> __psp_sk_rx_policy_check() -> psp_pse_matches_pas()So a key-rotate running while PSP packets arrive on an rx-rekeyed socket is an unannotated data race that KCSAN would report. The field is a u8, so it can't tear, and the result is unordered against the rotation in any case.
Quoted 10 lines
The existing
pas->generationwrite already works this way. This patch applies the same pattern to a new field that the datapath reads, and adds a second write site in theactive_assocsloop.Would it make sense to use
WRITE_ONCE()here andREAD_ONCE()inpsp_pse_matches_pas()?Quoted 3 lines
net/psp/psp_sock.c +1
-0+list_splice_init (&psd->prev_assocs, &psd->stale_assocs);list_splice_init (&psd->active_assocs, &psd->prev_assocs);
This review is the same as two revisions ago, so I'll just refer to:
https://lore.kernel.org/all/[email protected]/
Daniel Zahka
maintainerPATCH v5 2/6 psp: support tx rekey operation
In reply to Daniel ZahkaThe tx rekey operation creates a new psp_assoc with the same rx state, but with new tx state. The new association is spliced into the socket with RCU to be used immediately in the tx path.
Drivers that use on-device tx key storage need additional logic to delay key deletion until after any in-flight users of the key have been drained, so return -EOPNOTSUPP for now.
---
v3:
- 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
v2:
- place new assoc on pas->assocs list instead of psd->active assocs list
- reject tx rekey on SADB devices until deferred tx key deletion lands
--- Documentation/netlink/specs/psp.yaml | 4 ++- Documentation/networking/psp.rst | 5 +++- net/psp/psp_sock.c | 57 ++++++++++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 8 deletions(-)
Documentation/netlink/specs/psp.yaml +3 -1
@@ -283,7 +283,9 @@ operations: post: psp-device-unlock - name: tx-assoc - doc: Add a PSP Tx association. + doc: | + Add a PSP Tx association. + If the socket already has a Tx association, rekey its Tx direction. attribute-set: assoc do: request:
Documentation/networking/psp.rst +4 -1
@@ -145,7 +145,8 @@ Rekeying A connection which has completed the exchange described above and is in the "PSP Full" state can be rekeyed in place without being torn -down, using the same netlink calls as in connection setup. +down. The Tx and Rx directions are rekeyed separately using the same +netlink calls as in connection setup. ``rx-assoc`` allocates a new Rx key and SPI, which should be passed to the peer exactly as during the initial exchange. The SPI which was
@@ -154,6 +155,8 @@ next Rx rekey, or until the device key it was derived from has been rotated out, so packets the peer sent before it learned the new SPI are still received. +``tx-assoc`` installs a new Tx key, which takes effect immediately. + A rekey is rejected with ``-EINVAL`` if it would change the PSP device or the PSP version of the association. It is rejected with ``-EBUSY`` if the socket has not completed its initial exchange in both
net/psp/psp_sock.c +51 -6
70 lines not on this page · raw message
Signature · 1 line
2.52.1
Daniel Zahka
maintainerPATCH v5 3/6 psp: document lock ordering with the netdev instance lock
In reply to Daniel ZahkaPSP core calls driver ops with psp_dev::lock held, and drivers may take the netdev instance lock inside them. mlx5e_psp_set_config() has done so since commit 1e6e0cec0dab ("net/mlx5e: psp: Make PSP steering config dynamic"). That commit established a lock ordering that was not documented anywhere.
Document it. psp_dev_create() and psp_dev_unregister() take psp_devs_lock and psp_dev::lock, so assert that they are not called with the netdev instance lock held. The next patch adds a work item to PSP core which relies on this ordering.
---
v5:
- new patch
--- net/psp/psp_main.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/psp/psp_main.c +9 -0
@@ -19,6 +19,8 @@ struct mutex psp_devs_lock;* * psp_devs_lock protects the psp_devs xarray. * Ordering is take the psp_devs_lock and then the instance lock. +* The PSP instance lock must be taken before its main netdev's instance +* lock. * Each instance is protected by RCU, and has a refcount. * When driver unregisters the instance gets flushed, but struct sticks around. */
@@ -53,6 +55,7 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin)* @psd_caps: device capabilities * @priv_ptr: back-pointer to driver private data * +* Context: Must not be called with the netdev instance lock held. * Return: pointer to allocated PSP device, or ERR_PTR. */ struct psp_dev *
@@ -64,6 +67,8 @@ psp_dev_create(struct net_device *netdev,static u32 last_id;int err; +lockdep_assert_not_held (&netdev->lock); + if (WARN_ON(!psd_caps->versions || !psd_ops->set_config || !psd_ops->key_rotate ||
@@ -127,12 +132,16 @@ void psp_dev_free(struct psp_dev *psd)/** * psp_dev_unregister() - unregister PSP device * @psd: PSP device structure +* +* Context: Must not be called with the netdev instance lock held. */ void psp_dev_unregister (struct psp_dev *psd) {struct psp_assoc_dev *entry, *entry_tmp;struct psp_assoc *pas, *next; +lockdep_assert_not_held (&psd->main_netdev->lock); +mutex_lock (&psp_devs_lock);mutex_lock (&psd->lock);
Signature · 1 line
2.52.1
Daniel Zahka
maintainerPATCH v5 4/6 psp: defer tx key deletions for SADB drivers
In reply to Daniel ZahkaDevices that store tx keys in an SADB can hold references to key handles in tx descriptor state. PSP core needs to make sure all of these tx descriptors have been completed before calling psp_dev_tx_key_del(). Before rekeying, this was ensured by skbs holding references to skb->sk, and sk->psp_assoc being cleared only in the socket destructor.
Rekeying introduces a code path where a psp_assoc is detached from its socket and may be freed while the socket is still alive. This means skbs may exist in the driver ring that were rendered into descriptors using that old psp_assoc. We cannot delete the key from the SADB until we know these descriptors have been completed.
After a psp_assoc has all references drained (refcount and rcu), PSP core records the BQL queued count for each active TX queue and starts a descriptor grace period. It then polls the queued and completed byte counts until all data outstanding at the start of the grace period has completed. After that point, any keys queued for deletion before the start of the grace period can be deleted from the SADB.
Make CONFIG_INET_PSP depend on CONFIG_BQL.
Drivers which install Tx keys must meet the requirements in Documentation/networking/psp.rst.
The deferred deletion work takes psp_dev::lock before the netdev instance lock, following the order documented in the previous patch.
Adding a time based rate limit per socket for tx-assoc to prevent wasting SADB or deferred deletion queue space is possible for future work. For now, users should avoid presenting PSP devices to users they don't trust to abuse this.
---
v5:
- 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
v3:
- document that Tx descriptors must be completed or discarded before psp_dev_unregister()
v2:
- move grace period mechanism to use bql instead of driver callback.
- allow tx rekey on SADB devices
--- Documentation/networking/psp.rst | 42 +++++++ include/net/psp/types.h | 18 +++ net/psp/Kconfig | 1 + net/psp/Makefile | 2 +- net/psp/psp.h | 5 + net/psp/psp_deferred_del.c | 231 +++++++++++++++++++++++++++++++++++++++ net/psp/psp_main.c | 22 +++- net/psp/psp_sock.c | 22 +++- 8 files changed, 334 insertions(+), 9 deletions(-)
Documentation/networking/psp.rst +42 -0
@@ -202,6 +202,48 @@ Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload was requested for given skb. On Rx drivers should allocate and populate the ``SKB_EXT_PSP`` skb extension, and set the skb->decrypted bit to 1. +Deferred Tx key deletion +~~~~~~~~~~~~~~~~~~~~~~~~ + +Drivers which implement ``tx_key_add`` and ``tx_key_del`` may hold key +references in their Tx rings, so PSP core waits until descriptors +containing these references are completed before removing the key from +the underlying device. PSP core uses accounting based on Byte Queue Limits +(BQL) to wait for a suitable grace period before asking the driver to +remove the key. + +Drivers which implement the Tx key callbacks must meet the following +requirements: + +* The driver must be "ops locked" + (see Documentation/networking/netdevices.rst). +* A PSP skb accepted by ``ndo_start_xmit()`` must remain socket-owned until + every Tx descriptor referencing its PSP key has been completed or otherwise + made incapable of using the key. The driver must not orphan the skb before + that point. Otherwise, the socket destructor may free the Tx key while key + references remain in the Tx ring. +* Every PSP packet accepted by ``ndo_start_xmit()`` must be included in BQL + queued bytecount before the function returns. +* Completion bytecounts must exactly match enqueue bytecounts and preserve + queue order. A later packet must not be reported as completed while an earlier + packet can still reference its key. +* Before calling ``dql_reset()`` on a queue, the driver must ensure that all + outstanding descriptors containing key references have been completed or + discarded. If called under the netdev instance lock, then descriptors can + remain outstanding after the reset as long as they are completed or + discarded before the instance lock is released. +* When decreasing ``real_num_tx_queues``, the driver must ensure that every + outstanding descriptor on the queues at or above the new Tx queue count + has been completed or otherwise made incapable of using its PSP key + before the netdev instance lock is released. +* The BQL state of a queue below ``real_num_tx_queues`` must reflect all + bytes completed or be reset after the queue has been quiesced. Failure to + do so will stall the grace period algorithm. +* Before calling ``psp_dev_unregister()``, the driver must ensure that all + outstanding Tx descriptors containing key references have been completed + or discarded. PSP core deletes all remaining Tx keys during + unregistration without waiting for a grace period. + Kernel implementation notes ---------------------------
include/net/psp/types.h +18 -0
@@ -6,6 +6,7 @@#include <linux/bits.h> #include <linux/mutex.h> #include <linux/refcount.h> +#include <linux/workqueue.h> #include <net/net_trackers.h> struct netlink_ext_ack ;
@@ -81,6 +82,11 @@ struct psp_assoc_dev {* device key * @stale_assocs: associations which use a rotated out key, or were * superseded by a rekey +* @tx_del: deferred TX key deletion state +* @tx_del.active: TX keys to be deleted after the current grace period +* @tx_del.next: TX keys queued for deletion during current grace period +* @tx_del.work: delayed work item for periodic grace period checking +* @tx_del.txq_state: TX queue state for deferred deletion grace periods * * @stats: statistics maintained by the core * @stats.rotations: See stats attr key-rotations
@@ -110,6 +116,13 @@ struct psp_dev {struct list_head prev_assocs;struct list_head stale_assocs; +struct { +struct list_head active; +struct list_head next; +struct delayed_work work; +struct psp_txq_state *txq_state; + } tx_del; +struct {unsigned long rotations;unsigned long stales;
@@ -158,9 +171,14 @@ struct psp_key_parsed {* enum psp_assoc_flags - flags of struct psp_assoc * @PSP_ASSOC_SKIP_TX_KEY_DEL: Do not delete Tx key from psp_dev. It was * copied to a newer psp_assoc during an Rx rekey. +* @PSP_ASSOC_DEFER_TX_KEY_DEL: Send Tx key to psp_dev's deferred deletion +* queue. This psp_assoc was detached from its socket during a Tx rekey +* and requires device descriptor state referencing this key to be +* drained. */ enum psp_assoc_flags {PSP_ASSOC_SKIP_TX_KEY_DEL =BIT (0 ), +PSP_ASSOC_DEFER_TX_KEY_DEL =BIT (1 ), };struct psp_assoc {
net/psp/Kconfig +1 -0
@@ -5,6 +5,7 @@ config INET_PSP bool "PSP Security Protocol support" depends on INET + depends on BQL select SKB_DECRYPTED select SKB_EXTENSIONS select SOCK_VALIDATE_XMIT
net/psp/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-$(CONFIG_INET_PSP) += psp.o -psp-y := psp_main.o psp_nl.o psp_sock.o psp-nl-gen.o +psp-y := psp_main.o psp_nl.o psp_sock.o psp_deferred_del.o psp-nl-gen.o
net/psp/psp.h +5 -0
@@ -18,6 +18,11 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin);bool psp_has_assoc_dev_in_ns (struct psp_dev *psd,struct net *net);int psp_attach_netdev_notifier (void ); +int psp_deferred_del_init (struct psp_dev *psd); +void psp_deferred_del_stop (struct psp_dev *psd); +void psp_deferred_del_uninit (struct psp_dev *psd,bool unpublished); +void psp_deferred_del_queue (struct psp_dev *psd,struct psp_assoc *pas); +void psp_nl_notify_dev (struct psp_dev *psd,u32 cmd);void psp_nl_notify_disassoc (struct psp_dev *psd,struct net *net);
net/psp/psp_deferred_del.c new file +231 -0
231 lines not on this page · raw message
net/psp/psp_main.c +19 -3
@@ -3,8 +3,10 @@#include <linux/bitfield.h> #include <linux/list.h> #include <linux/netdevice.h> +#include <linux/slab.h> #include <linux/xarray.h> #include <net/net_namespace.h> +#include <net/netdev_lock.h> #include <net/psp.h> #include <net/udp.h>
@@ -75,7 +77,8 @@ psp_dev_create(struct net_device *netdev, !psd_ops->rx_spi_alloc || !psd_ops->get_stats || (!psd_ops->tx_key_add != !psd_ops->tx_key_del) || - (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add))) + (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add) || + (psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))))return ERR_PTR (-EINVAL ); psd =kzalloc_obj (*psd);
@@ -94,13 +97,16 @@ psp_dev_create(struct net_device *netdev,INIT_LIST_HEAD (&psd->stale_assocs);refcount_set (&psd->refcnt,1 ); + err =psp_deferred_del_init (psd); +if (err) + goto err_free_psd; +mutex_lock (&psp_devs_lock); err =xa_alloc_cyclic (&psp_devs, &psd->id, psd, xa_limit_16b, &last_id,GFP_KERNEL );if (err) {mutex_unlock (&psp_devs_lock); -kfree (psd); -return ERR_PTR (err); + goto err_uninit_deferred_del; }mutex_lock (&psd->lock);mutex_unlock (&psp_devs_lock);
@@ -116,6 +122,12 @@ psp_dev_create(struct net_device *netdev,mutex_unlock (&psd->lock);return psd; + +err_uninit_deferred_del: +psp_deferred_del_uninit (psd, true); +err_free_psd: +kfree (psd); +return ERR_PTR (err); }EXPORT_SYMBOL (psp_dev_create);
@@ -142,6 +154,8 @@ void psp_dev_unregister(struct psp_dev *psd)lockdep_assert_not_held (&psd->main_netdev->lock); +psp_deferred_del_stop (psd); +mutex_lock (&psp_devs_lock);mutex_lock (&psd->lock);
@@ -154,6 +168,8 @@ void psp_dev_unregister(struct psp_dev *psd)xa_store (&psp_devs, psd->id,NULL ,GFP_KERNEL );mutex_unlock (&psp_devs_lock); +psp_deferred_del_uninit (psd, false); +list_splice_init (&psd->active_assocs, &psd->prev_assocs);list_splice_init (&psd->prev_assocs, &psd->stale_assocs);list_for_each_entry_safe (pas, next, &psd->stale_assocs, assocs_list) {
net/psp/psp_sock.c +17 -5
@@ -114,8 +114,23 @@ static void psp_assoc_free(struct work_struct *work)mutex_lock (&psd->lock);if (psp_dev_is_registered (psd)) { -if (psp_assoc_needs_tx_key_del (pas)) +if (psp_assoc_needs_tx_key_del (pas)) { +if (pas->flags &PSP_ASSOC_DEFER_TX_KEY_DEL ) { +psp_deferred_del_queue (psd, pas); + +/* The deferred queue now owns pas's reference +* on psd and may drop it as soon as psd->lock +* is released. Take another reference to psd +* to ensure that psd isn't freed until +* mutex_unlock() returns. +*/ +psp_dev_get (psd); +mutex_unlock (&psd->lock); +psp_dev_put (psd); +return ; + }psp_dev_tx_key_del (psd, pas); + }list_del (&pas->assocs_list); }mutex_unlock (&psd->lock);
@@ -287,10 +302,6 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,struct psp_assoc *new;int err; -if (psp_dev_has_sadb (psd)) { -NL_SET_ERR_MSG (extack,"Tx rekey not supported on this device" ); -return -EOPNOTSUPP ; - }if (!pas->peer_tx) {NL_SET_ERR_MSG (extack,"Socket PSP state is not fully established" );return -EBUSY ;
@@ -322,6 +333,7 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,list_move (&pas->assocs_list, &psd->stale_assocs);rcu_assign_pointer (sk->psp_assoc, new); + pas->flags |=PSP_ASSOC_DEFER_TX_KEY_DEL ;psp_assoc_put (pas);return 0 ;
Signature · 1 line
2.52.1
[email protected]
AI reviewRe: [PATCH net-next v5 4/6] psp: defer tx key deletions for SADB drivers
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] With the -EOPNOTSUPP guard gone from psp_sock_tx_rekey() (net/psp/psp_sock.c), any unprivileged owner of an established PSP TCP…
- [Low] The applied commit message does not say that this patch turns on Tx rekey for SADB devices.
- [Low] The kernel-doc for psp_dev_ops::tx_key_add and ::tx_key_del in include/net/psp/types.h still says only that each callback 'Can be…
--
psp: defer tx key deletions for SADB drivers
This patch adds a deferred Tx key deletion queue for PSP devices that store Tx keys in an SADB. Before calling psp_dev_tx_key_del(), the core snapshots BQL queued byte counts per Tx queue and polls until those bytes have completed. It also removes the -EOPNOTSUPP restriction on Tx rekey for SADB devices and makes CONFIG_INET_PSP depend on CONFIG_BQL.
Quoted 4 lines
net/psp/psp_main.c +0
-0
[ ... ]
net/psp/psp_main.c psp_dev_create(struct net_device *netdev, · line 82
Quoted 8 lines
net/psp/psp_main.c +2
-1@@ -75,7 +77,8 @@ psp_dev_create(struct net_device *netdev, !psd_ops->rx_spi_alloc || !psd_ops->get_stats || (!psd_ops->tx_key_add != !psd_ops->tx_key_del) || - (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add))) + (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add) || + (psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))))return ERR_PTR (-EINVAL );
[Severity: Low]
Should the kernel-doc for tx_key_add and tx_key_del in include/net/psp/types.h be updated along with this check? It still only says:
* @tx_key_add: add a Tx key to the device
* Install an association in the device. Core will allocate space
* for the driver to use at drv_data.
* Can be left NULL if device does not store Tx keys and @tx_key_del
* is also NULL.
With this patch, a driver that implements these callbacks needs an ops locked netdev. Without one, psp_dev_create() hits the WARN_ON and returns -EINVAL.
The driver also needs exact, in-order BQL accounting and has to follow the dql_reset() and real_num_tx_queues rules that psp_deferred_del_work() relies on.
These rules are only written down in Documentation/networking/psp.rst, and the ops kernel-doc doesn't point there. A driver written from the struct documentation alone could hit the registration WARN, stall the grace period, or end it too early.
Could the kernel-doc reference the new "Deferred Tx key deletion" section? No later patch in the series appears to update it.
Quoted 4 lines
net/psp/psp_sock.c +0
-0
[ ... ]
net/psp/psp_sock.c psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas, · line 307
Quoted 11 lines
net/psp/psp_sock.c +0
-4@@ -287,10 +302,6 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,struct psp_assoc *new;int err; -if (psp_dev_has_sadb (psd)) { -NL_SET_ERR_MSG (extack,"Tx rekey not supported on this device" ); -return -EOPNOTSUPP ; - }if (!pas->peer_tx) {NL_SET_ERR_MSG (extack,"Socket PSP state is not fully established" );return -EBUSY ;
[Severity: Low]
This isn't a bug, but could the commit message say outright that Tx rekey is now allowed on SADB devices?
The earlier commit "psp: support tx rekey operation" said SADB drivers would "return -EOPNOTSUPP for now". With this guard removed, PSP_CMD_TX_ASSOC on a socket that already has a Tx key now succeeds on mlx5, where it used to fail.
The only explicit mention is "allow tx rekey on SADB devices" in the v2 changelog below the --- line, and that part is dropped when the patch is applied.
The same goes for the new registration requirement in psp_dev_create():
(psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))
The body only says drivers "must meet the requirements in Documentation/networking/psp.rst".
net/psp/psp_sock.c psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas, · line 339
Quoted 8 lines
net/psp/psp_sock.c +1
-0@@ -322,6 +333,7 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,list_move (&pas->assocs_list, &psd->stale_assocs);rcu_assign_pointer (sk->psp_assoc, new); + pas->flags |=PSP_ASSOC_DEFER_TX_KEY_DEL ;psp_assoc_put (pas);return 0 ;
[Severity: Medium]
Can an unprivileged user use up the device's hardware Tx key pool through this path?
PSP_CMD_TX_ASSOC has no GENL_ADMIN_PERM. psp_sock_assoc_set_tx() enters psp_sock_tx_rekey() whenever pas->tx.spi is already set, and each call allocates a new hardware key:
psp_sock_tx_rekey()
psp_assoc_set_tx()
psp_dev_tx_key_add()
mlx5e_psp_assoc_add()
mlx5_create_encryption_key()The old key then goes onto the deferred deletion queue, which has no upper bound:
net/psp/psp_deferred_del.c:psp_deferred_del_queue() {
list_move_tail(&pas->assocs_list, &psd->tx_del.next);
schedule_delayed_work(&psd->tx_del.work, 0);
}psp_deferred_del_work() handles one grace period at a time and polls every PSP_TX_GRACE_POLL_MS (1000 ms). Keys queued during a grace period wait for the next one. A single socket can therefore pin as many DEKs as it can rekey in that window, where before each socket held at most one.
Suppose a queue below real_num_tx_queues never completes the bytes snapshotted in psp_tx_grace_start(). Would every later rekey then pin a DEK, a psp_assoc and a psd reference until psp_dev_unregister()?
When a grace period does end, psp_deferred_del_work() calls psp_dev_tx_key_del() for the whole batch while holding psd->lock. On mlx5 each call is a firmware command:
list_for_each_entry(pas, &to_free, assocs_list) psp_dev_tx_key_del(psd, pas);
Would that block other PSP netlink operations, and psp_assoc_free() for every socket on the device, until the batch is done?
The psp_assoc allocation uses GFP_KERNEL_ACCOUNT, but the hardware DEK pool is shared by the whole device and is not charged to any cgroup. One local user could make tx_key_add fail for other users' sockets. That includes sockets in other netns that were delegated the same device.
The commit message acknowledges this ("users should avoid presenting PSP devices to users they don't trust to abuse this"). In the main netns, though, every local user can reach the device. Nothing later in the series appears to change these paths.
Is a cap on the deferred queue length, or a per-socket rate limit, needed before SADB rekey is allowed?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-psp-v5-0-b9ec840e0296%40gmail.com
Daniel Zahka
maintainerRe: [PATCH net-next v5 4/6] psp: defer tx key deletions for SADB drivers
Quoted 165 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] With the
-EOPNOTSUPPguard gone frompsp_sock_tx_rekey()(net/psp/psp_sock.c), any unprivileged owner of an established PSP TCP…
- [Low] The applied commit message does not say that this patch turns on Tx rekey for SADB devices.
- [Low] The kernel-doc forpsp_dev_ops::tx_key_addand ::tx_key_del ininclude/net/psp/types.hstill says only that each callback 'Can be…--
psp: defer tx key deletions for SADB drivers
This patch adds a deferred Tx key deletion queue for PSP devices that store Tx keys in an SADB. Before calling
psp_dev_tx_key_del(), the core snapshots BQL queued byte counts per Tx queue and polls until those bytes have completed. It also removes the-EOPNOTSUPPrestriction on Tx rekey for SADB devices and makesCONFIG_INET_PSPdepend onCONFIG_BQL.Quoted 4 lines
net/psp/psp_main.c +0
-0[ ... ]
net/psp/psp_main.c psp_dev_create(struct net_device *netdev, · line 82
Quoted 8 lines
net/psp/psp_main.c +2
-1@@ -75,7 +77,8 @@ psp_dev_create(struct net_device *netdev, !psd_ops->rx_spi_alloc || !psd_ops->get_stats || (!psd_ops->tx_key_add != !psd_ops->tx_key_del) || - (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add))) + (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add) || + (psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))))return ERR_PTR (-EINVAL );[Severity: Low]
Should the kernel-doc fortx_key_addandtx_key_delininclude/net/psp/types.hbe updated along with this check? It still only says:* @tx_key_add: add a Tx key to the device
* Install an association in the device. Core will allocate space
* for the driver to use atdrv_data.
* Can be left NULL if device does not store Tx keys and @tx_key_del
* is also NULL.With this patch, a driver that implements these callbacks needs an ops locked netdev. Without one,
psp_dev_create()hits theWARN_ONand returns-EINVAL.The driver also needs exact, in-order BQL accounting and has to follow the
dql_reset()andreal_num_tx_queuesrules thatpsp_deferred_del_work()relies on.These rules are only written down in
Documentation/networking/psp.rst, and the ops kernel-doc doesn't point there. A driver written from the struct documentation alone could hit the registration WARN, stall the grace period, or end it too early.Could the kernel-doc reference the new "Deferred Tx key deletion" section? No later patch in the series appears to update it.
Quoted 4 lines
net/psp/psp_sock.c +0
-0[ ... ]
net/psp/psp_sock.c psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas, · line 307
Quoted 11 lines
net/psp/psp_sock.c +0
-4@@ -287,10 +302,6 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,struct psp_assoc *new;int err; -if (psp_dev_has_sadb (psd)) { -NL_SET_ERR_MSG (extack,"Tx rekey not supported on this device" ); -return -EOPNOTSUPP ; - }if (!pas->peer_tx) {NL_SET_ERR_MSG (extack,"Socket PSP state is not fully established" );return -EBUSY ;[Severity: Low]
This isn't a bug, but could the commit message say outright that Tx rekey is now allowed on SADB devices?The earlier commit "psp: support tx rekey operation" said SADB drivers would "return
-EOPNOTSUPPfor now". With this guard removed,PSP_CMD_TX_ASSOCon a socket that already has a Tx key now succeeds on mlx5, where it used to fail.The only explicit mention is "allow tx rekey on SADB devices" in the v2 changelog below the --- line, and that part is dropped when the patch is applied.
The same goes for the new registration requirement in
psp_dev_create():(psd_ops->tx_key_add && !netdev_need_ops_lock(netdev))The body only says drivers "must meet the requirements in
Documentation/networking/psp.rst".net/psp/psp_sock.c psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas, · line 339
Quoted 8 lines
net/psp/psp_sock.c +1
-0@@ -322,6 +333,7 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,list_move (&pas->assocs_list, &psd->stale_assocs);rcu_assign_pointer (sk->psp_assoc, new); + pas->flags |=PSP_ASSOC_DEFER_TX_KEY_DEL ;psp_assoc_put (pas);return 0 ;[Severity: Medium]
Can an unprivileged user use up the device's hardware Tx key pool through this path?
PSP_CMD_TX_ASSOChas noGENL_ADMIN_PERM.psp_sock_assoc_set_tx()enterspsp_sock_tx_rekey()wheneverpas->tx.spiis already set, and each call allocates a new hardware key:
psp_sock_tx_rekey()
psp_assoc_set_tx()psp_dev_tx_key_add() mlx5e_psp_assoc_add() mlx5_create_encryption_key()The old key then goes onto the deferred deletion queue, which has no upper bound:
net/psp/psp_deferred_del.c:psp_deferred_del_queue() { list_move_tail(&pas->assocs_list, &psd->tx_del.next); schedule_delayed_work(&psd->tx_del.work, 0); }
psp_deferred_del_work()handles one grace period at a time and polls everyPSP_TX_GRACE_POLL_MS(1000 ms). Keys queued during a grace period wait for the next one. A single socket can therefore pin as many DEKs as it can rekey in that window, where before each socket held at most one.Suppose a queue below
real_num_tx_queuesnever completes the bytes snapshotted inpsp_tx_grace_start(). Would every later rekey then pin a DEK, apsp_assocand a psd reference untilpsp_dev_unregister()?When a grace period does end,
psp_deferred_del_work()callspsp_dev_tx_key_del()for the whole batch while holdingpsd->lock. On mlx5 each call is a firmware command:list_for_each_entry(pas, &to_free, assocs_list) psp_dev_tx_key_del(psd, pas);Would that block other PSP netlink operations, and
psp_assoc_free()for every socket on the device, until the batch is done?The
psp_assocallocation usesGFP_KERNEL_ACCOUNT, but the hardware DEK pool is shared by the whole device and is not charged to any cgroup. One local user could maketx_key_addfail for other users' sockets. That includes sockets in other netns that were delegated the same device.
Quoted 7 lines
The commit message acknowledges this ("users should avoid presenting PSP devices to users they don't trust to abuse this"). In the main netns, though, every local user can reach the device. Nothing later in the series appears to change these paths.
Is a cap on the deferred queue length, or a per-socket rate limit, needed before SADB rekey is allowed?
As discussed on every prior posting of this series, in the commit message, and cover letter, the rate limiting is left for future work. The psp dev should be hidden from a user that can't be trusted to do this.
Daniel Zahka
maintainerPATCH v5 5/6 selftests: drv-net: psp: factor out psp connection setup
In reply to Daniel ZahkaLift out connection setup and PSP assoc uapi code in psp.py and responder, so that the key exchange sequence can be used in other test cases that start with a key exchange, but might choose to perform additional tx/rx assoc calls afterwards.
---
v4:
- drop closing the data socket on conn_setup_psp() failure; preexisting and not needed by the series
v3:
- 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
--- tools/testing/selftests/drivers/net/psp.py | 14 ++++- .../testing/selftests/drivers/net/psp_responder.c | 73 ++++++++++++++-------- 2 files changed, 59 insertions(+), 28 deletions(-)
tools/testing/selftests/drivers/net/psp.py +11 -3
@@ -467,10 +467,11 @@ def assoc_twice(cfg): ksft_eq(len(tx), 0) -def _data_basic_send(cfg, version, ipver): - """ Test basic data send """ - _init_psp_dev(cfg) +def _establish_psp_conn(cfg, version, ipver=None): + """Establish a PSP connection and return after key exchange + Requires _init_psp_dev() to have been called first. + """ # Version 0 is required by spec, don't let it skip if version: name = cfg.pspnl.consts["version"].entries_by_val[version].name
@@ -495,7 +496,14 @@ def _data_basic_send(cfg, version, ipver): "version": version, "tx-key": tx, "sock-fd": s.fileno()}) + return s + + +def _data_basic_send(cfg, version, ipver): + """ Test basic data send """ + _init_psp_dev(cfg) + s = _establish_psp_conn(cfg, version, ipver) data_len = _send_careful(cfg, s, 100) _check_data_rx(cfg, data_len) _req_echo(cfg, s)
tools/testing/selftests/drivers/net/psp_responder.c +48 -25
103 lines not on this page · raw message
Signature · 1 line
2.52.1
Daniel Zahka
maintainerPATCH v5 6/6 selftests: drv-net: psp: add rekey tests
In reply to Daniel ZahkaAdd testcases for rekeying psp connections.
Tests include coverage for different cases where rx-assoc and tx-assoc should fail based on mismatched psp version and psp state.
Add rpc endpoints for tx-assoc, rx-assoc, and key-rotate netlink calls to the psp_responder.
---
v5:
- drop the fail-fast change to _recv_careful(); it is a pre-existing helper
v4:
- reuse _recv_careful() and _req_echo() now in net-next instead of redefining them
v3:
- 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
v2:
- 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
--- tools/testing/selftests/drivers/net/psp.py | 232 ++++++++++++++++++++- .../testing/selftests/drivers/net/psp_responder.c | 119 +++++++++++ 2 files changed, 349 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/psp.py +230 -2
@@ -28,6 +28,10 @@ from lib.py import ip TCP_ULP = 31 +_PSP_MAX_KEY_LEN = 32 +_PSP_ASSOC_MSG = f'!IBB2x{_PSP_MAX_KEY_LEN}s' + + def _get_outq(s): one = b'\0' * 4 outq = fcntl.ioctl(s.fileno(), termios.TIOCOUTQ, one)
@@ -80,6 +84,33 @@ def _close_psp_conn(cfg, s): _close_conn(cfg, s) +def _recv_all(s, target): + data = b'' + while len(data) < target: + chunk = s.recv(target - len(data)) + if not chunk: + raise KsftFailEx(f"peer closed after {len(data)} of {target} bytes") + data += chunk + return data + + +def _remote_rx_assoc(cfg): + _send_with_ack(cfg, b'rx assoc\0') + msg = _recv_all(cfg.comm_sock, struct.calcsize(_PSP_ASSOC_MSG)) + spi, version, key_len, key = struct.unpack(_PSP_ASSOC_MSG, msg) + return version, {'spi': spi, 'key': key[:key_len]} + + +def _remote_tx_assoc(cfg, version, rx): + msg = struct.pack(_PSP_ASSOC_MSG, rx['spi'], version, len(rx['key']), + rx['key']) + _send_with_ack(cfg, b'tx assoc\0' + msg) + + +def _remote_key_rotate(cfg): + _send_with_ack(cfg, b'key rotate\0') + + def _spi_xchg(s, rx): s.send(struct.pack('I', rx['spi']) + rx['key']) tx = s.recv(4 + len(rx['key']))
@@ -150,6 +181,21 @@ def _check_data_outq(s, exp_len, force_wait=False): ksft_eq(outq, exp_len) +def _psp_txrx(cfg, s, rounds, sent=0): + """Send data both ways, and return the total bytes sent to the peer""" + sent += _send_careful(cfg, s, rounds) + _check_data_rx(cfg, sent) + _req_echo(cfg, s) + return sent + + +def _require_version(cfg, version): + """Skip the test unless the device supports the given PSP version""" + name = cfg.pspnl.consts["version"].entries_by_val[version].name + if name not in cfg.psp_info['psp-versions-cap']: + raise KsftSkipEx("PSP version not supported", name) + + def _get_stat(cfg, key): return cfg.pspnl.get_stats({'dev-id': cfg.psp_dev_id})[key]
@@ -510,6 +556,186 @@ def _data_basic_send(cfg, version, ipver): _close_psp_conn(cfg, s) +def _rekey_rx(cfg, s, version, sent): + """Rekey the Rx direction, running traffic after each step""" + rx_assoc = cfg.pspnl.rx_assoc({"version": version, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + sent = _psp_txrx(cfg, s, 1, sent) + + _remote_tx_assoc(cfg, version, rx_assoc['rx-key']) + return _psp_txrx(cfg, s, 1, sent) + + +def _rekey_tx(cfg, s, sent): + """Rekey the Tx direction, running traffic after each step""" + version, tx = _remote_rx_assoc(cfg) + sent = _psp_txrx(cfg, s, 1, sent) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": version, + "tx-key": tx, + "sock-fd": s.fileno()}) + return _psp_txrx(cfg, s, 1, sent) + + +def rekey_rx_incomplete(cfg): + """Test rejecting Rx rekey until the PSP connection is established""" + psp_ver = 0 + _init_psp_dev(cfg) + + with _make_lo_conn() as s: + assoc = cfg.pspnl.rx_assoc({"version": psp_ver, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + + # Reject rekey before Tx state is configured. + with ksft_raises(NlError) as cm: + cfg.pspnl.rx_assoc({"version": psp_ver, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": psp_ver, + "tx-key": assoc['rx-key'], + "sock-fd": s.fileno()}) + + # Reject rekey until authenticated PSP traffic has been received. + with ksft_raises(NlError) as cm: + cfg.pspnl.rx_assoc({"version": psp_ver, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY) + + +def rekey_tx_incomplete(cfg): + """Test rejecting Tx rekey until the PSP connection is established""" + psp_ver = 0 + _init_psp_dev(cfg) + + with _make_lo_conn() as s: + assoc = cfg.pspnl.rx_assoc({"version": psp_ver, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": psp_ver, + "tx-key": assoc['rx-key'], + "sock-fd": s.fileno()}) + + # Reject rekey until authenticated PSP traffic has been received. + with ksft_raises(NlError) as cm: + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": psp_ver, + "tx-key": assoc['rx-key'], + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.EBUSY) + + +def rekey_rx_version_mismatch(cfg): + """Test rejecting an Rx rekey whose version does not match socket state""" + _init_psp_dev(cfg) + _require_version(cfg, 1) + + s = _establish_psp_conn(cfg, 0) + try: + _psp_txrx(cfg, s, 1) + + with ksft_raises(NlError) as cm: + cfg.pspnl.rx_assoc({"dev-id": cfg.psp_dev_id, + "version": 1, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL) + finally: + _close_psp_conn(cfg, s) + + +def rekey_tx_version_mismatch(cfg): + """Test rejecting a Tx rekey whose version does not match socket state""" + _init_psp_dev(cfg) + _require_version(cfg, 1) + + s = _establish_psp_conn(cfg, 0) + try: + _psp_txrx(cfg, s, 1) + + with ksft_raises(NlError) as cm: + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": 1, + "tx-key": {'spi': 0x12345678, + 'key': b'\xa5' * 32}, + "sock-fd": s.fileno()}) + ksft_eq(cm.exception.nl_msg.error, -errno.EINVAL) + finally: + _close_psp_conn(cfg, s) + + +def _get_psp_ver_variants(): + for ver in range(4): + yield KsftNamedVariant(f"v{ver}", ver) + + +@ksft_variants(_get_psp_ver_variants()) +def rekey_rx_basic(cfg, version): + """Test rekeying the Rx key of an established connection""" + _init_psp_dev(cfg) + + s = _establish_psp_conn(cfg, version) + try: + data_len = _psp_txrx(cfg, s, 1) + cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + data_len = _psp_txrx(cfg, s, 1, data_len) + data_len = _rekey_rx(cfg, s, version, data_len) + cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + _psp_txrx(cfg, s, 1, data_len) + finally: + _close_psp_conn(cfg, s) + + +@ksft_variants(_get_psp_ver_variants()) +def rekey_tx_basic(cfg, version): + """Test rekeying the Tx key of an established connection""" + _init_psp_dev(cfg) + + s = _establish_psp_conn(cfg, version) + try: + data_len = _psp_txrx(cfg, s, 1) + _remote_key_rotate(cfg) + data_len = _psp_txrx(cfg, s, 1, data_len) + data_len = _rekey_tx(cfg, s, data_len) + _remote_key_rotate(cfg) + _psp_txrx(cfg, s, 1, data_len) + finally: + _close_psp_conn(cfg, s) + + +@ksft_variants(_get_psp_ver_variants()) +def rekey_both_sides(cfg, version): + """Test rekeying both directions""" + _init_psp_dev(cfg) + + s = _establish_psp_conn(cfg, version) + try: + data_len = _psp_txrx(cfg, s, 10) + + cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + _remote_key_rotate(cfg) + + # first, rx then tx + data_len = _rekey_rx(cfg, s, version, data_len) + data_len = _rekey_tx(cfg, s, data_len) + + cfg.pspnl.key_rotate({"id": cfg.psp_dev_id}) + _remote_key_rotate(cfg) + + # now, tx then rx + data_len = _rekey_tx(cfg, s, data_len) + _rekey_rx(cfg, s, version, data_len) + finally: + _close_psp_conn(cfg, s) + + def __bad_xfer_do(cfg, s, tx, version='hdr0-aes-gcm-128'): # Make sure we accept the ACK for the SPI before we seal with the bad assoc _check_data_outq(s, 0)
@@ -1209,7 +1435,8 @@ def main() -> None: cfg.comm_port), timeout=1) - cases = [data_basic_send, data_mss_adjust] + cases = [data_basic_send, data_mss_adjust, + rekey_rx_basic, rekey_tx_basic, rekey_both_sides] if has_cont: cases += [
@@ -1225,7 +1452,8 @@ def main() -> None: ] ksft_run(cases=cases, globs=globals(), - case_pfx={"dev_", "data_", "assoc_", "removal_"}, + case_pfx={"dev_", "data_", "assoc_", "rekey_", + "removal_"}, args=(cfg, )) cfg.comm_sock.send(b"exit\0")
tools/testing/selftests/drivers/net/psp_responder.c +119 -0
161 lines not on this page · raw message
Signature · 1 line
2.52.1
[email protected]
AI reviewRe: [PATCH net-next v5 6/6] selftests: drv-net: psp: add rekey tests
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] selftests: drv-net: psp: stale length n in run_session() after tx assoc
--
Quoted 10 lines
tools/testing/selftests/drivers/net/psp_responder.c +3
-0@@ -247,6 +354,16 @@ run_session(struct ynl_sock *ys, struct opts *opts,fprintf (stderr,"WARN: echo but no data sock\n" );send_ack (comm_sock); } +if (cmd ("rx assoc" )) +handle_rx_assoc (ys, data_sock, + comm_sock);
tools/testing/selftests/drivers/net/psp_responder.c run_session(struct ynl_sock *ys, struct opts *opts, · line 369
Quoted 10 lines
tools/testing/selftests/drivers/net/psp_responder.c +7
-0+ if (cmd_w_msg("tx assoc", struct assoc_msg)) { +handle_tx_assoc (ys, buf, data_sock, + comm_sock); +__consume (sizeof (struct assoc_msg )); + } +if (cmd ("key rotate" )) +handle_key_rotate (ys, opts, comm_sock);if (cmd ("data close" )) {if (data_sock >=0 ) {close (data_sock);
[Severity: Medium]
In run_session(), n is set from off once, before the do/while loop, and is never updated. cmd() still tests n >= sz and __consume() tests n == sz. For a single tx assoc message n is 49.
cmd("tx assoc") consumes the 9 byte string and moves the struct assoc_msg to buf[0]. __consume(sizeof(struct assoc_msg)) then takes the else branch. That leaves off == 0, but the 40 byte assoc_msg is still in buf[0..39].
The checks that follow in the same iteration (key rotate, data close, conn psp, conn clr, exit) still see n == 49. They memcmp() buf against the SPI, version and key bytes of a message that was already handled. Suppose those bytes match a command string. For example, an SPI of 0x65786974 with version 0 reads as "exit\0". The matching __consume() then does off -= sz starting from zero, and memmove() gets a negative length converted to a huge size_t, which crashes the responder.
The conn psp handler already has the same stale-n pattern, but it only leaves the two version bytes behind. tx assoc is the first command that leaves an arbitrary binary payload at the front of buf.
Would it make sense to have cmd() and __consume() check off rather than n, perhaps as a small fix ahead of this patch? Then a command could only match bytes that have not been consumed yet.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-psp-v5-0-b9ec840e0296%40gmail.com
Daniel Zahka
maintainerRe: [PATCH net-next v5 6/6] selftests: drv-net: psp: add rekey tests
Quoted 55 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] selftests: drv-net: psp: stale length n in
run_session()after tx assoc--
Quoted 10 lines
tools/testing/selftests/drivers/net/psp_responder.c +3
-0@@ -247,6 +354,16 @@ run_session(struct ynl_sock *ys, struct opts *opts,fprintf (stderr,"WARN: echo but no data sock\n" );send_ack (comm_sock); } +if (cmd ("rx assoc" )) +handle_rx_assoc (ys, data_sock, + comm_sock);tools/testing/selftests/drivers/net/psp_responder.c run_session(struct ynl_sock *ys, struct opts *opts, · line 369
Quoted 10 lines
tools/testing/selftests/drivers/net/psp_responder.c +7
-0+ if (cmd_w_msg("tx assoc", struct assoc_msg)) { +handle_tx_assoc (ys, buf, data_sock, + comm_sock); +__consume (sizeof (struct assoc_msg )); + } +if (cmd ("key rotate" )) +handle_key_rotate (ys, opts, comm_sock);if (cmd ("data close" )) {if (data_sock >=0 ) {close (data_sock);[Severity: Medium]
Inrun_session(), n is set from off once, before the do/while loop, and is never updated.cmd()still tests n >= sz and__consume()tests n == sz. For a single tx assoc message n is 49.
cmd("tx assoc")consumes the 9 byte string and moves the structassoc_msgto buf[0].__consume(sizeof(struct assoc_msg))then takes the else branch. That leaves off == 0, but the 40 byteassoc_msgis still in buf[0..39].The checks that follow in the same iteration (key rotate, data close, conn psp, conn clr, exit) still see n == 49. They
memcmp()buf against the SPI, version and key bytes of a message that was already handled. Suppose those bytes match a command string. For example, an SPI of0x65786974with version 0 reads as "exit\0". The matching__consume()then does off -= sz starting from zero, andmemmove()gets a negative length converted to a hugesize_t, which crashes the responder.
Quoted 7 lines
The conn psp handler already has the same stale-n pattern, but it only leaves the two version bytes behind. tx assoc is the first command that leaves an arbitrary binary payload at the front of buf.
Would it make sense to have
cmd()and__consume()check off rather than n, perhaps as a small fix ahead of this patch? Then a command could only match bytes that have not been consumed yet.
that probably would make sense, but this is mostly a preexisting hazard with the demux loop, so it would cost another setup patch, and the issue is still not actually reachable during test execution. The 4B SPI would need to alias the string "exit". That won't ever happen.
This would be the only reason to go to a v6 for the series here, so let me know if you think this is worth it.