Skip to contentSkip to conversation

netdevsim: psp: reset spi on key rotation and check for exhaustion on alloc

PATCH Applied Daniel Zahka 3 participants 3 messages May 15 – May 19

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Assisted-by Claude:claude-opus-4.7

---
This commit was originally part of the series:
https://lore.kernel.org/netdev/[email protected]/

But it stands alone, so I am submitting individually first.

---
 drivers/net/netdevsim/psp.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/net/netdevsim/psp.c +16 -5
index 6936ecb8173e..c6000ebc6bc8 100644
@@ -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;
 }
 

---
base-commit: 822d4a8e390a08ccfaf2abb347ae670b230b196f
change-id: 20260515-spi-handle-8be9eb842667

Best regards,

Signature · 1 line
Daniel Zahka <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Daniel Zahka

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.

This could be stated more clearly in the spec indeed. At a minimum as a suggestion ("should").

It does imply the second: "The SPI field is 31 bits long (since 1 bit is taken as the master key indicator), so the master keys must be rotated before the key’s SPI space is exhausted."

Quoted 3 lines
Assisted-by Claude:claude-opus-4.7

[PATCH net-next]

#2 lore raw
In reply to Daniel Zahka
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 15 May 2026 10:08:52 -0700 you wrote:

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.

Assisted-by Claude:claude-opus-4.7

[...]

Here is the summary with links:
- netdevsim: psp: reset spi on key rotation and check for exhaustion on alloc

    https://git.kernel.org/netdev/net-next/c/97386a9cf046

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html