diff options
| author | Daniel Zahka <daniel.zahka@gmail.com> | 2026-05-15 10:08:52 -0700 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2026-05-18 16:27:18 -0700 |
| commit | 97386a9cf046002b3c89208ab0603f1e631026e3 (patch) | |
| tree | 49b6042b5f457cd36c734777985a463f8aac9c50 /drivers/net/netdevsim | |
| parent | 5a3a819389ad9ac2baa56402dc272c2e210d215f (diff) | |
| download | linux-next-97386a9cf046002b3c89208ab0603f1e631026e3.tar.gz linux-next-97386a9cf046002b3c89208ab0603f1e631026e3.zip | |
netdevsim: psp: reset spi on key rotation and check for exhaustion on alloc
The PSP spec states that the lower 31b of the SPI need to be
non-zero. Though not in the spec, I think it is reasonable to reset
the lower 31b of the spi space after a key rotation, and to also
decline to generate session keys when the lower 31b saturate.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260515-spi-handle-v1-1-debf8cb467cb@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/net/netdevsim')
| -rw-r--r-- | drivers/net/netdevsim/psp.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c index 6936ecb8173e..c6000ebc6bc8 100644 --- a/drivers/net/netdevsim/psp.c +++ b/drivers/net/netdevsim/psp.c @@ -132,14 +132,15 @@ nsim_rx_spi_alloc(struct psp_dev *psd, u32 version, struct netlink_ext_ack *extack) { struct netdevsim *ns = psd->drv_priv; - unsigned int new; int i; - new = ++ns->psp.spi & PSP_SPI_KEY_ID; - if (psd->generation & 1) - new |= PSP_SPI_KEY_PHASE; + /* Check if incrementing the spi would change the phase bit */ + if ((ns->psp.spi & PSP_SPI_KEY_ID) == PSP_SPI_KEY_ID) { + NL_SET_ERR_MSG(extack, "SPI space exhausted"); + return -ENOSPC; + } - assoc->spi = cpu_to_be32(new); + assoc->spi = cpu_to_be32(++ns->psp.spi); assoc->key[0] = psd->generation; for (i = 1; i < PSP_MAX_KEY; i++) assoc->key[i] = ns->psp.spi + i; @@ -162,6 +163,16 @@ static int nsim_assoc_add(struct psp_dev *psd, struct psp_assoc *pas, static int nsim_key_rotate(struct psp_dev *psd, struct netlink_ext_ack *extack) { + struct netdevsim *ns = psd->drv_priv; + + /* Flip key phase and reset SPI to 0 within that space + * (will be pre-incremented, as 0 is an invalid SPI). + */ + if (ns->psp.spi & PSP_SPI_KEY_PHASE) + ns->psp.spi = 0; + else + ns->psp.spi = PSP_SPI_KEY_PHASE; + return 0; } |
